Skip to content

Commit 65eb889

Browse files
authored
Merge branch 'main' into marc/vectorsets
2 parents 536efe4 + 4d2da7a commit 65eb889

File tree

14 files changed

+559
-316
lines changed

14 files changed

+559
-316
lines changed

docs/ReleaseNotes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Current package versions:
1414
- Add support for XPENDING Idle time filter ([#2822 by david-brink-talogy](https://github.com/StackExchange/StackExchange.Redis/pull/2822))
1515
- Improve `double` formatting performance on net8+ ([#2928 by mgravell](https://github.com/StackExchange/StackExchange.Redis/pull/2928))
1616
- Add vector-set support ([#2939 by mgravell](https://github.com/StackExchange/StackExchange.Redis/pull/2939))
17+
- Add `GetServer(RedisKey, ...)` API ([#2936 by mgravell](https://github.com/StackExchange/StackExchange.Redis/pull/2936))
18+
- Fix error constructing `StreamAdd` message ([#2941 by mgravell](https://github.com/StackExchange/StackExchange.Redis/pull/2941))
1719

1820
## 2.8.58
1921

src/StackExchange.Redis/ConnectionMultiplexer.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ internal async Task MakePrimaryAsync(ServerEndPoint server, ReplicationChangeOpt
210210
{
211211
throw ExceptionFactory.AdminModeNotEnabled(RawConfig.IncludeDetailInExceptions, cmd, null, server);
212212
}
213-
var srv = new RedisServer(this, server, null);
213+
var srv = server.GetRedisServer(null);
214214
if (!srv.IsConnected)
215215
{
216216
throw ExceptionFactory.NoConnectionAvailable(this, null, server, GetServerSnapshot(), command: cmd);
@@ -1229,7 +1229,21 @@ 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(this, server, asyncState);
1232+
return server.GetRedisServer(asyncState);
1233+
}
1234+
1235+
/// <inheritdoc cref="IConnectionMultiplexer.GetServer(RedisKey, object, CommandFlags)"/>
1236+
#pragma warning disable RS0026
1237+
public IServer GetServer(RedisKey key, object? asyncState = null, CommandFlags flags = CommandFlags.None)
1238+
#pragma warning restore RS0026
1239+
{
1240+
// We'll spoof the GET command for this; we're not supporting ad-hoc access to the pub/sub channel, because: bad things.
1241+
// Any read-only-replica vs writable-primary concerns should be managed by the caller via "flags"; the default is PreferPrimary.
1242+
// Note that ServerSelectionStrategy treats "null" (default) keys as NoSlot, aka Any.
1243+
return (SelectServer(RedisCommand.GET, flags, key) ?? Throw()).GetRedisServer(asyncState);
1244+
1245+
[DoesNotReturn]
1246+
static ServerEndPoint Throw() => throw new InvalidOperationException("It was not possible to resolve a connection to the server owning the specified key");
12331247
}
12341248

12351249
/// <summary>
@@ -1241,7 +1255,7 @@ public IServer[] GetServers()
12411255
var result = new IServer[snapshot.Length];
12421256
for (var i = 0; i < snapshot.Length; i++)
12431257
{
1244-
result[i] = new RedisServer(this, snapshot[i], null);
1258+
result[i] = snapshot[i].GetRedisServer(null);
12451259
}
12461260
return result;
12471261
}

0 commit comments

Comments
 (0)