|
44 | 44 |
|
45 | 45 | import org.apache.commons.logging.Log; |
46 | 46 | import org.apache.commons.logging.LogFactory; |
| 47 | + |
47 | 48 | import org.springframework.beans.factory.DisposableBean; |
48 | 49 | import org.springframework.beans.factory.InitializingBean; |
49 | 50 | import org.springframework.dao.DataAccessException; |
|
56 | 57 | import org.springframework.data.redis.connection.RedisConfiguration.DomainSocketConfiguration; |
57 | 58 | import org.springframework.data.redis.connection.RedisConfiguration.WithDatabaseIndex; |
58 | 59 | import org.springframework.data.redis.connection.RedisConfiguration.WithPassword; |
59 | | -import org.springframework.data.redis.connection.lettuce.LettuceConnection.*; |
60 | 60 | import org.springframework.data.util.Optionals; |
61 | 61 | import org.springframework.lang.Nullable; |
62 | 62 | import org.springframework.util.Assert; |
@@ -374,9 +374,7 @@ public RedisClusterConnection getClusterConnection() { |
374 | 374 |
|
375 | 375 | RedisClusterClient clusterClient = (RedisClusterClient) client; |
376 | 376 |
|
377 | | - StatefulRedisClusterConnection<byte[], byte[]> sharedConnection = getShareNativeConnection() |
378 | | - ? (StatefulRedisClusterConnection<byte[], byte[]>) getOrCreateSharedConnection().getConnection() |
379 | | - : null; |
| 377 | + StatefulRedisClusterConnection<byte[], byte[]> sharedConnection = getSharedClusterConnection(); |
380 | 378 |
|
381 | 379 | LettuceClusterTopologyProvider topologyProvider = new LettuceClusterTopologyProvider(clusterClient); |
382 | 380 | return doCreateLettuceClusterConnection(sharedConnection, connectionProvider, topologyProvider, |
@@ -472,7 +470,12 @@ public void initConnection() { |
472 | 470 |
|
473 | 471 | resetConnection(); |
474 | 472 |
|
475 | | - getSharedConnection(); |
| 473 | + if (isClusterAware()) { |
| 474 | + getSharedClusterConnection(); |
| 475 | + } else { |
| 476 | + getSharedConnection(); |
| 477 | + } |
| 478 | + |
476 | 479 | getSharedReactiveConnection(); |
477 | 480 | } |
478 | 481 |
|
@@ -971,12 +974,27 @@ public boolean isClusterAware() { |
971 | 974 | } |
972 | 975 |
|
973 | 976 | /** |
974 | | - * @return the shared connection using {@literal byte} array encoding for imperative API use. {@literal null} if |
975 | | - * {@link #getShareNativeConnection() connection sharing} is disabled. |
| 977 | + * @return the shared connection using {@literal byte[]} encoding for imperative API use. {@literal null} if |
| 978 | + * {@link #getShareNativeConnection() connection sharing} is disabled or when connected to Redis Cluster. |
976 | 979 | */ |
977 | 980 | @Nullable |
978 | 981 | protected StatefulRedisConnection<byte[], byte[]> getSharedConnection() { |
979 | | - return shareNativeConnection ? (StatefulRedisConnection) getOrCreateSharedConnection().getConnection() : null; |
| 982 | + return shareNativeConnection && !isClusterAware() |
| 983 | + ? (StatefulRedisConnection) getOrCreateSharedConnection().getConnection() |
| 984 | + : null; |
| 985 | + } |
| 986 | + |
| 987 | + /** |
| 988 | + * @return the shared cluster connection using {@literal byte[]} encoding for imperative API use. {@literal null} if |
| 989 | + * {@link #getShareNativeConnection() connection sharing} is disabled or when connected to Redis |
| 990 | + * Standalone/Sentinel/Master-Replica. |
| 991 | + * @since 2.4.15 |
| 992 | + */ |
| 993 | + @Nullable |
| 994 | + protected StatefulRedisClusterConnection<byte[], byte[]> getSharedClusterConnection() { |
| 995 | + return shareNativeConnection && isClusterAware() |
| 996 | + ? (StatefulRedisClusterConnection) getOrCreateSharedConnection().getConnection() |
| 997 | + : null; |
980 | 998 | } |
981 | 999 |
|
982 | 1000 | /** |
|
0 commit comments