Avoid cast to StatefulRedisConnection upon eager LettuceConnectionFactory initialization.

We now no longer try to cast the Lettuce connection to StatefulRedisConnection when eagerly initializing the shared connection. Instead, we now introduced another method to obtain the cluster connection.

Closes #2186
This commit is contained in:
Mark Paluch
2021-11-12 08:51:41 +01:00
parent b2f7b6f4b2
commit 518fd6d946
2 changed files with 68 additions and 11 deletions

View File

@@ -438,9 +438,7 @@ public class LettuceConnectionFactory
RedisClusterClient clusterClient = (RedisClusterClient) client;
StatefulRedisClusterConnection<byte[], byte[]> sharedConnection = getShareNativeConnection()
? (StatefulRedisClusterConnection<byte[], byte[]>) getOrCreateSharedConnection().getConnection()
: null;
StatefulRedisClusterConnection<byte[], byte[]> sharedConnection = getSharedClusterConnection();
LettuceClusterTopologyProvider topologyProvider = new LettuceClusterTopologyProvider(clusterClient);
return doCreateLettuceClusterConnection(sharedConnection, connectionProvider, topologyProvider,
@@ -540,7 +538,12 @@ public class LettuceConnectionFactory
resetConnection();
getSharedConnection();
if (isClusterAware()) {
getSharedClusterConnection();
} else {
getSharedConnection();
}
getSharedReactiveConnection();
}
@@ -1081,12 +1084,27 @@ public class LettuceConnectionFactory
}
/**
* @return the shared connection using {@literal byte} array encoding for imperative API use. {@literal null} if
* {@link #getShareNativeConnection() connection sharing} is disabled.
* @return the shared connection using {@literal byte[]} encoding for imperative API use. {@literal null} if
* {@link #getShareNativeConnection() connection sharing} is disabled or when connected to Redis Cluster.
*/
@Nullable
protected StatefulRedisConnection<byte[], byte[]> getSharedConnection() {
return shareNativeConnection ? (StatefulRedisConnection) getOrCreateSharedConnection().getConnection() : null;
return shareNativeConnection && !isClusterAware()
? (StatefulRedisConnection) getOrCreateSharedConnection().getConnection()
: null;
}
/**
* @return the shared cluster connection using {@literal byte[]} encoding for imperative API use. {@literal null} if
* {@link #getShareNativeConnection() connection sharing} is disabled or when connected to Redis
* Standalone/Sentinel/Master-Replica.
* @since 2.5.7
*/
@Nullable
protected StatefulRedisClusterConnection<byte[], byte[]> getSharedClusterConnection() {
return shareNativeConnection && isClusterAware()
? (StatefulRedisClusterConnection) getOrCreateSharedConnection().getConnection()
: null;
}
/**