Skip to content

Commit 5eda048

Browse files
committed
merge the sync and async write implementations into a shared implementation that can transition from sync to async if needed
1 parent 3bc6449 commit 5eda048

10 files changed

Lines changed: 538 additions & 321 deletions

Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<PackageVersion Include="Newtonsoft.Json" Version="13.0.4" />
2828
<PackageVersion Include="NSubstitute" Version="5.3.0" />
2929
<PackageVersion Include="StackExchange.Redis" Version="2.13.17" />
30+
<PackageVersion Include="StackExchange.Redis.StrongName" Version="1.2.6" />
3031
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.556" />
3132
<PackageVersion Include="System.Collections.Immutable" Version="10.0.5" />
3233
<PackageVersion Include="System.Reflection.Metadata" Version="10.0.5" />

src/RESPite.Benchmark/OldCoreBenchmarkBase.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,13 @@ bool Tick()
187187

188188
private async ValueTask<int> GetAndMeasureString(IDatabaseAsync client)
189189
{
190+
#if LEGACY_API
191+
byte[]? data = (byte[]?)(await client.StringGetAsync(GetSetKey).ConfigureAwait(false));
192+
return data?.Length ?? -1;
193+
#else
190194
using var lease = await client.StringGetLeaseAsync(GetSetKey).ConfigureAwait(false);
191195
return lease?.Length ?? -1;
196+
#endif
192197
}
193198

194199
[DisplayName("SET")]
@@ -228,7 +233,14 @@ private ValueTask<bool> ZAdd(IDatabaseAsync client) =>
228233
client.SortedSetAddAsync(SortedSetKey, "element:__rand_int__", 0).AsValueTask();
229234

230235
[DisplayName("ZPOPMIN")]
231-
private ValueTask<int> ZPopMin(IDatabaseAsync client) => HasSortedSetElement(client.SortedSetPopAsync(SortedSetKey));
236+
private ValueTask<int> ZPopMin(IDatabaseAsync client)
237+
{
238+
#if LEGACY_API
239+
throw new NotSupportedException();
240+
#else
241+
return HasSortedSetElement(client.SortedSetPopAsync(SortedSetKey));
242+
#endif
243+
}
232244

233245
private async ValueTask<int> HasSortedSetElement(Task<SortedSetEntry?> pending)
234246
{
@@ -240,8 +252,14 @@ private async ValueTask<int> HasSortedSetElement(Task<SortedSetEntry?> pending)
240252
private ValueTask<bool> MSet(IDatabaseAsync client) => client.StringSetAsync(_pairs).AsValueTask();
241253

242254
[DisplayName("XADD")]
243-
private ValueTask<RedisValue> XAdd(IDatabaseAsync client) =>
244-
client.StreamAddAsync(StreamKey, "myfield", Payload).AsValueTask();
255+
private ValueTask<RedisValue> XAdd(IDatabaseAsync client)
256+
{
257+
#if LEGACY_API
258+
throw new NotSupportedException();
259+
#else
260+
return client.StreamAddAsync(StreamKey, "myfield", Payload).AsValueTask();
261+
#endif
262+
}
245263

246264
[DisplayName("LRANGE_100")]
247265
private ValueTask<int> LRange100(IDatabaseAsync client) => CountAsync(client.ListRangeAsync(ListKey, 0, 99));

src/RESPite.Benchmark/RESPite.Benchmark.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@
2222
<PackageReference Remove="Microsoft.CodeAnalysis.PublicApiAnalyzers"/>
2323
</ItemGroup>
2424

25+
<!-- v1 builds (for comparison) -->
26+
<ItemGroup Condition="'$(TargetVer)'=='1'">
27+
<PackageReference Include="StackExchange.Redis.StrongName" />
28+
</ItemGroup>
29+
<PropertyGroup Condition="'$(TargetVer)'=='1'">
30+
<DefineConstants>$(DefineConstants);LEGACY_API</DefineConstants>
31+
</PropertyGroup>
2532
<!-- v2 builds -->
2633
<ItemGroup Condition="'$(TargetVer)'=='2'">
2734
<PackageReference Include="StackExchange.Redis"/>

src/StackExchange.Redis/BufferedStreamWriter.Async.cs

Lines changed: 0 additions & 158 deletions
This file was deleted.

0 commit comments

Comments
 (0)