Skip to content

Commit e19f401

Browse files
committed
fix breaks
1 parent 6e6db71 commit e19f401

File tree

5 files changed

+33
-20
lines changed

5 files changed

+33
-20
lines changed

src/RESPite.StackExchange.Redis/RespContextDatabase.Connection.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,21 @@ internal partial class RespContextDatabase
1010
public bool IsConnected(RedisKey key, CommandFlags flags = CommandFlags.None) =>
1111
throw new NotImplementedException();
1212

13-
private static readonly byte[] PingRaw = "*1\r\n$4\r\nping\r\n"u8.ToArray();
13+
internal static readonly byte[] PingRaw = "*1\r\n$4\r\nping\r\n"u8.ToArray();
1414

1515
public Task<TimeSpan> PingAsync(CommandFlags flags = CommandFlags.None) =>
1616
Context(flags).Send("ping"u8, DateTime.UtcNow, PingParser.Default, PingRaw).AsTask();
1717

1818
public TimeSpan Ping(CommandFlags flags = CommandFlags.None) =>
1919
Context(flags).Send("ping"u8, DateTime.UtcNow, PingParser.Default, PingRaw).Wait(SyncTimeout);
2020

21-
private sealed class PingParser : IRespParser<DateTime, TimeSpan>
21+
internal sealed class PingParser : IRespParser<DateTime, TimeSpan>
2222
{
2323
public static readonly PingParser Default = new();
2424
private PingParser() { }
2525
public TimeSpan Parse(in DateTime state, ref RespReader reader) => DateTime.UtcNow - state;
2626
}
27+
2728
public Task<EndPoint?> IdentifyEndpointAsync(RedisKey key = default, CommandFlags flags = CommandFlags.None) =>
2829
throw new NotImplementedException();
2930

src/RESPite.StackExchange.Redis/RespContextDatabase.cs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,7 @@ public RespContextDatabase(IConnectionMultiplexer muxer, IRespContextSource sour
3131
protected void SetSource(IRespContextSource source)
3232
=> this._source = source;
3333

34-
// Question: cache this, or rebuild each time? the latter handles shutdown better.
35-
// internal readonly RespContext Context = proxy.Context.WithDatabase(db);
36-
private RespContext Context(CommandFlags flags)
37-
{
38-
// the flags intentionally align between CommandFlags and RespContextFlags
39-
const RespContext.RespContextFlags flagMask = RespContext.RespContextFlags.DemandPrimary
40-
| RespContext.RespContextFlags.DemandReplica
41-
| RespContext.RespContextFlags.PreferReplica
42-
| RespContext.RespContextFlags.NoRedirect
43-
| RespContext.RespContextFlags.FireAndForget
44-
| RespContext.RespContextFlags.NoScriptCache;
45-
46-
return _source.Context.With(_db, (RespContext.RespContextFlags)flags, flagMask);
47-
}
34+
private RespContext Context(CommandFlags flags) => _source.Context.With(_db, flags);
4835

4936
private TimeSpan SyncTimeout => _source.Context.SyncTimeout;
5037
public int Database => _db;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using StackExchange.Redis;
2+
3+
namespace RESPite.StackExchange.Redis;
4+
5+
internal static class RespContextExtensions
6+
{
7+
// Question: cache this, or rebuild each time? the latter handles shutdown better.
8+
// internal readonly RespContext Context = proxy.Context.WithDatabase(db);
9+
internal static RespContext With(this in RespContext context, int db, CommandFlags flags)
10+
{
11+
// the flags intentionally align between CommandFlags and RespContextFlags
12+
const RespContext.RespContextFlags FlagMask = RespContext.RespContextFlags.DemandPrimary
13+
| RespContext.RespContextFlags.DemandReplica
14+
| RespContext.RespContextFlags.PreferReplica
15+
| RespContext.RespContextFlags.NoRedirect
16+
| RespContext.RespContextFlags.FireAndForget
17+
| RespContext.RespContextFlags.NoScriptCache;
18+
return context.With(db, (RespContext.RespContextFlags)flags, FlagMask);
19+
}
20+
}

src/RESPite.StackExchange.Redis/RespContextServer.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@ namespace RESPite.StackExchange.Redis;
1212
internal sealed class RespContextServer(RespMultiplexer muxer, Node node) : IServer
1313
{
1414
// deliberately not caching this - if the connection changes, we want to know about it
15-
internal ref readonly RespContext Context => ref node.Context;
15+
internal RespContext Context(CommandFlags flags) => node.Context.With(-1, flags);
16+
17+
private TimeSpan SyncTimeout => node.Context.SyncTimeout;
1618

1719
public IConnectionMultiplexer Multiplexer => muxer;
18-
public Task<TimeSpan> PingAsync(CommandFlags flags = CommandFlags.None) => throw new NotImplementedException();
20+
21+
public Task<TimeSpan> PingAsync(CommandFlags flags = CommandFlags.None)
22+
=> Context(flags).Send("ping"u8, DateTime.UtcNow, RespContextDatabase.PingParser.Default, RespContextDatabase.PingRaw).AsTask();
1923

2024
public bool TryWait(Task task) => task.Wait(Multiplexer.TimeoutMilliseconds);
2125

@@ -25,7 +29,8 @@ internal sealed class RespContextServer(RespMultiplexer muxer, Node node) : ISer
2529

2630
public void WaitAll(params Task[] tasks) => Multiplexer.WaitAll(tasks);
2731

28-
public TimeSpan Ping(CommandFlags flags = CommandFlags.None) => throw new NotImplementedException();
32+
public TimeSpan Ping(CommandFlags flags = CommandFlags.None)
33+
=> Context(flags).Send("ping"u8, DateTime.UtcNow, RespContextDatabase.PingParser.Default, RespContextDatabase.PingRaw).Wait(SyncTimeout);
2934

3035
public ClusterConfiguration? ClusterConfiguration => throw new NotImplementedException();
3136
public EndPoint EndPoint => node.Manager.ConnectionFactory.GetEndPoint(node.EndPoint, node.Port);

src/StackExchange.Redis/ConnectionMultiplexer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,7 @@ public IServer GetServer(EndPoint? endpoint, object? asyncState = null)
12291229
throw new NotSupportedException($"The server API is not available via {RawConfig.Proxy}");
12301230
}
12311231
var server = servers[endpoint] as ServerEndPoint ?? throw new ArgumentException("The specified endpoint is not defined", nameof(endpoint));
1232-
return new RedisServer(server, asyncState);
1232+
return server.GetRedisServer(asyncState);
12331233
}
12341234

12351235
/// <inheritdoc cref="IConnectionMultiplexer.GetServer(RedisKey, object, CommandFlags)"/>

0 commit comments

Comments
 (0)