@@ -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