Skip to content

Commit ae28ae6

Browse files
authored
Internals Rename: *Wrapper -> "KeyPrefixed" (#2282)
This renames the various wrappers to IMO more intuitive "KeyPrefixedX" - just couldn't get used to the previous model when touching N files for an API addition, hoping this makes it a little clearer overall, also has the benefit of batching them in UI due to common prefix.
1 parent c76e9ae commit ae28ae6

12 files changed

+437
-432
lines changed

src/StackExchange.Redis/KeyspaceIsolation/BatchWrapper.cs

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

src/StackExchange.Redis/KeyspaceIsolation/DatabaseExtension.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ public static IDatabase WithKeyPrefix(this IDatabase database, RedisKey keyPrefi
5454
return database; // fine - you can keep using the original, then
5555
}
5656

57-
if (database is DatabaseWrapper wrapper)
57+
if (database is KeyPrefixedDatabase prefixed)
5858
{
5959
// combine the key in advance to minimize indirection
60-
keyPrefix = wrapper.ToInner(keyPrefix);
61-
database = wrapper.Inner;
60+
keyPrefix = prefixed.ToInner(keyPrefix);
61+
database = prefixed.Inner;
6262
}
6363

64-
return new DatabaseWrapper(database, keyPrefix.AsPrefix()!);
64+
return new KeyPrefixedDatabase(database, keyPrefix.AsPrefix()!);
6565
}
6666
}
6767
}

src/StackExchange.Redis/KeyspaceIsolation/WrapperBase.cs renamed to src/StackExchange.Redis/KeyspaceIsolation/KeyPrefixed.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
namespace StackExchange.Redis.KeyspaceIsolation
99
{
10-
internal class WrapperBase<TInner> : IDatabaseAsync where TInner : IDatabaseAsync
10+
internal class KeyPrefixed<TInner> : IDatabaseAsync where TInner : IDatabaseAsync
1111
{
12-
internal WrapperBase(TInner inner, byte[] keyPrefix)
12+
internal KeyPrefixed(TInner inner, byte[] keyPrefix)
1313
{
1414
Inner = inner;
1515
Prefix = keyPrefix;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace StackExchange.Redis.KeyspaceIsolation
2+
{
3+
internal sealed class KeyPrefixedBatch : KeyPrefixed<IBatch>, IBatch
4+
{
5+
public KeyPrefixedBatch(IBatch inner, byte[] prefix) : base(inner, prefix) { }
6+
7+
public void Execute() => Inner.Execute();
8+
}
9+
}

src/StackExchange.Redis/KeyspaceIsolation/DatabaseWrapper.cs renamed to src/StackExchange.Redis/KeyspaceIsolation/KeyPrefixedDatabase.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44

55
namespace StackExchange.Redis.KeyspaceIsolation
66
{
7-
internal sealed class DatabaseWrapper : WrapperBase<IDatabase>, IDatabase
7+
internal sealed class KeyPrefixedDatabase : KeyPrefixed<IDatabase>, IDatabase
88
{
9-
public DatabaseWrapper(IDatabase inner, byte[] prefix) : base(inner, prefix)
9+
public KeyPrefixedDatabase(IDatabase inner, byte[] prefix) : base(inner, prefix)
1010
{
1111
}
1212

1313
public IBatch CreateBatch(object? asyncState = null) =>
14-
new BatchWrapper(Inner.CreateBatch(asyncState), Prefix);
14+
new KeyPrefixedBatch(Inner.CreateBatch(asyncState), Prefix);
1515

1616
public ITransaction CreateTransaction(object? asyncState = null) =>
17-
new TransactionWrapper(Inner.CreateTransaction(asyncState), Prefix);
17+
new KeyPrefixedTransaction(Inner.CreateTransaction(asyncState), Prefix);
1818

1919
public int Database => Inner.Database;
2020

src/StackExchange.Redis/KeyspaceIsolation/TransactionWrapper.cs renamed to src/StackExchange.Redis/KeyspaceIsolation/KeyPrefixedTransaction.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace StackExchange.Redis.KeyspaceIsolation
44
{
5-
internal sealed class TransactionWrapper : WrapperBase<ITransaction>, ITransaction
5+
internal sealed class KeyPrefixedTransaction : KeyPrefixed<ITransaction>, ITransaction
66
{
7-
public TransactionWrapper(ITransaction inner, byte[] prefix) : base(inner, prefix) { }
7+
public KeyPrefixedTransaction(ITransaction inner, byte[] prefix) : base(inner, prefix) { }
88

99
public ConditionResult AddCondition(Condition condition) => Inner.AddCondition(condition.MapKeys(GetMapFunction()));
1010

tests/StackExchange.Redis.Tests/ConfigTests.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,19 +187,25 @@ public void TalkToNonsenseServer()
187187
[Fact]
188188
public async Task TestManaulHeartbeat()
189189
{
190-
using var conn = Create(keepAlive: 2);
190+
var options = ConfigurationOptions.Parse(GetConfiguration());
191+
options.HeartbeatInterval = TimeSpan.FromMilliseconds(100);
192+
using var conn = await ConnectionMultiplexer.ConnectAsync(options);
193+
194+
foreach (var ep in conn.GetServerSnapshot().ToArray())
195+
{
196+
ep.WriteEverySeconds = 1;
197+
}
191198

192199
var db = conn.GetDatabase();
193200
db.Ping();
194201

195202
var before = conn.OperationCount;
196203

197-
Log("sleeping to test heartbeat...");
198-
await Task.Delay(5000).ForAwait();
199-
204+
Log("Sleeping to test heartbeat...");
205+
await UntilConditionAsync(TimeSpan.FromSeconds(5), () => conn.OperationCount > before + 1).ForAwait();
200206
var after = conn.OperationCount;
201207

202-
Assert.True(after >= before + 2, $"after: {after}, before: {before}");
208+
Assert.True(after >= before + 1, $"after: {after}, before: {before}");
203209
}
204210

205211
[Theory]

tests/StackExchange.Redis.Tests/BatchWrapperTests.cs renamed to tests/StackExchange.Redis.Tests/KeyPrefixedBatchTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@
66
namespace StackExchange.Redis.Tests;
77

88
[Collection(nameof(MoqDependentCollection))]
9-
public sealed class BatchWrapperTests
9+
public sealed class KeyPrefixedBatchTests
1010
{
1111
private readonly Mock<IBatch> mock;
12-
private readonly BatchWrapper wrapper;
12+
private readonly KeyPrefixedBatch prefixed;
1313

14-
public BatchWrapperTests()
14+
public KeyPrefixedBatchTests()
1515
{
1616
mock = new Mock<IBatch>();
17-
wrapper = new BatchWrapper(mock.Object, Encoding.UTF8.GetBytes("prefix:"));
17+
prefixed = new KeyPrefixedBatch(mock.Object, Encoding.UTF8.GetBytes("prefix:"));
1818
}
1919

2020
[Fact]
2121
public void Execute()
2222
{
23-
wrapper.Execute();
23+
prefixed.Execute();
2424
mock.Verify(_ => _.Execute(), Times.Once());
2525
}
2626
}

0 commit comments

Comments
 (0)