15
15
*/
16
16
package org .springframework .data .redis .connection .lettuce ;
17
17
18
- import static org .springframework .data .redis .connection .lettuce .LettuceConnection .CODEC ;
19
- import static org .springframework .data .redis .connection .lettuce .LettuceConnection .PipeliningFlushPolicy ;
18
+ import static org .springframework .data .redis .connection .lettuce .LettuceConnection .*;
20
19
21
20
import io .lettuce .core .AbstractRedisClient ;
22
21
import io .lettuce .core .ClientOptions ;
50
49
51
50
import org .apache .commons .logging .Log ;
52
51
import org .apache .commons .logging .LogFactory ;
52
+
53
53
import org .springframework .beans .factory .DisposableBean ;
54
54
import org .springframework .beans .factory .InitializingBean ;
55
55
import org .springframework .context .SmartLifecycle ;
59
59
import org .springframework .data .redis .ExceptionTranslationStrategy ;
60
60
import org .springframework .data .redis .PassThroughExceptionTranslationStrategy ;
61
61
import org .springframework .data .redis .RedisConnectionFailureException ;
62
- import org .springframework .data .redis .connection .ClusterCommandExecutor ;
63
- import org .springframework .data .redis .connection .ClusterTopologyProvider ;
64
- import org .springframework .data .redis .connection .ReactiveRedisConnectionFactory ;
65
- import org .springframework .data .redis .connection .RedisClusterConfiguration ;
66
- import org .springframework .data .redis .connection .RedisClusterConnection ;
67
- import org .springframework .data .redis .connection .RedisConfiguration ;
62
+ import org .springframework .data .redis .connection .*;
68
63
import org .springframework .data .redis .connection .RedisConfiguration .ClusterConfiguration ;
69
64
import org .springframework .data .redis .connection .RedisConfiguration .WithDatabaseIndex ;
70
65
import org .springframework .data .redis .connection .RedisConfiguration .WithPassword ;
71
- import org .springframework .data .redis .connection .RedisConnection ;
72
- import org .springframework .data .redis .connection .RedisConnectionFactory ;
73
- import org .springframework .data .redis .connection .RedisPassword ;
74
- import org .springframework .data .redis .connection .RedisSentinelConfiguration ;
75
- import org .springframework .data .redis .connection .RedisSentinelConnection ;
76
- import org .springframework .data .redis .connection .RedisSocketConfiguration ;
77
- import org .springframework .data .redis .connection .RedisStandaloneConfiguration ;
78
- import org .springframework .data .redis .connection .RedisStaticMasterReplicaConfiguration ;
79
66
import org .springframework .data .redis .util .RedisAssertions ;
80
67
import org .springframework .data .util .Optionals ;
81
68
import org .springframework .lang .Nullable ;
85
72
import org .springframework .util .StringUtils ;
86
73
87
74
/**
88
- * {@link RedisConnectionFactory Connection factory} creating <a href="https://lettuce.io/">Lettuce</a>-based connections.
75
+ * {@link RedisConnectionFactory Connection factory} creating <a href="https://lettuce.io/">Lettuce</a>-based
76
+ * connections.
89
77
* <p>
90
78
* This factory creates a new {@link LettuceConnection} on each call to {@link #getConnection()}. While multiple
91
79
* {@link LettuceConnection}s share a single thread-safe native connection by default, {@link LettuceConnection} and its
@@ -676,7 +664,7 @@ public AbstractRedisClient getNativeClient() {
676
664
public AbstractRedisClient getRequiredNativeClient () {
677
665
678
666
return RedisAssertions .requireState (getNativeClient (),
679
- "Client not yet initialized; Did you forget to call initialize the bean" );
667
+ "Client not yet initialized; Did you forget to call initialize the bean" );
680
668
}
681
669
682
670
@ Nullable
@@ -1006,8 +994,8 @@ public RedisConnection getConnection() {
1006
994
return getClusterConnection ();
1007
995
}
1008
996
1009
- LettuceConnection connection =
1010
- doCreateLettuceConnection ( getSharedConnection (), this . connectionProvider , getTimeout (), getDatabase ());
997
+ LettuceConnection connection = doCreateLettuceConnection ( getSharedConnection (), this . connectionProvider ,
998
+ getTimeout (), getDatabase ());
1011
999
1012
1000
connection .setConvertPipelineAndTxResults (this .convertPipelineAndTxResults );
1013
1001
@@ -1145,7 +1133,7 @@ public void resetConnection() {
1145
1133
doInLock (() -> {
1146
1134
1147
1135
Optionals .toStream (Optional .ofNullable (this .connection ), Optional .ofNullable (this .reactiveConnection ))
1148
- .forEach (SharedConnection ::resetConnection );
1136
+ .forEach (SharedConnection ::resetConnection );
1149
1137
1150
1138
this .connection = null ;
1151
1139
this .reactiveConnection = null ;
@@ -1255,7 +1243,7 @@ protected LettuceConnectionProvider doCreateConnectionProvider(AbstractRedisClie
1255
1243
1256
1244
return isStaticMasterReplicaAware () ? createStaticMasterReplicaConnectionProvider ((RedisClient ) client , codec )
1257
1245
: isClusterAware () ? createClusterConnectionProvider ((RedisClusterClient ) client , codec )
1258
- : createStandaloneConnectionProvider ((RedisClient ) client , codec );
1246
+ : createStandaloneConnectionProvider ((RedisClient ) client , codec );
1259
1247
}
1260
1248
1261
1249
@ SuppressWarnings ("all" )
@@ -1282,8 +1270,7 @@ protected AbstractRedisClient createClient() {
1282
1270
1283
1271
return isStaticMasterReplicaAware () ? createStaticMasterReplicaClient ()
1284
1272
: isRedisSentinelAware () ? createSentinelClient ()
1285
- : isClusterAware () ? createClusterClient ()
1286
- : createBasicClient ();
1273
+ : isClusterAware () ? createClusterClient () : createBasicClient ();
1287
1274
}
1288
1275
1289
1276
private RedisClient createStaticMasterReplicaClient () {
@@ -1349,8 +1336,7 @@ private RedisClusterClient createClusterClient() {
1349
1336
ClusterConfiguration clusterConfiguration = (ClusterConfiguration ) this .configuration ;
1350
1337
1351
1338
clusterConfiguration .getClusterNodes ().stream ()
1352
- .map (node -> createRedisURIAndApplySettings (node .getHost (), node .getPort ()))
1353
- .forEach (initialUris ::add );
1339
+ .map (node -> createRedisURIAndApplySettings (node .getHost (), node .getPort ())).forEach (initialUris ::add );
1354
1340
1355
1341
RedisClusterClient clusterClient = this .clientConfiguration .getClientResources ()
1356
1342
.map (clientResources -> RedisClusterClient .create (clientResources , initialUris ))
@@ -1403,8 +1389,8 @@ private void assertStarted() {
1403
1389
switch (current ) {
1404
1390
case CREATED , STOPPED -> throw new IllegalStateException (
1405
1391
String .format ("LettuceConnectionFactory has been %s. Use start() to initialize it" , current ));
1406
- case DESTROYED -> throw new IllegalStateException (
1407
- "LettuceConnectionFactory was destroyed and cannot be used anymore" );
1392
+ case DESTROYED ->
1393
+ throw new IllegalStateException ( "LettuceConnectionFactory was destroyed and cannot be used anymore" );
1408
1394
default -> throw new IllegalStateException (String .format ("LettuceConnectionFactory is %s" , current ));
1409
1395
}
1410
1396
}
@@ -1435,9 +1421,7 @@ private RedisURI createRedisURIAndApplySettings(String host, int port) {
1435
1421
private RedisURI createRedisSocketURIAndApplySettings (String socketPath ) {
1436
1422
1437
1423
return applyAuthentication (RedisURI .Builder .socket (socketPath ))
1438
- .withTimeout (this .clientConfiguration .getCommandTimeout ())
1439
- .withDatabase (getDatabase ())
1440
- .build ();
1424
+ .withTimeout (this .clientConfiguration .getCommandTimeout ()).withDatabase (getDatabase ()).build ();
1441
1425
}
1442
1426
1443
1427
private RedisURI .Builder applyAuthentication (RedisURI .Builder builder ) {
@@ -1471,7 +1455,10 @@ private long getClientTimeout() {
1471
1455
}
1472
1456
1473
1457
private void doInLock (Runnable runnable ) {
1474
- doInLock (() -> { runnable .run (); return null ; });
1458
+ doInLock (() -> {
1459
+ runnable .run ();
1460
+ return null ;
1461
+ });
1475
1462
}
1476
1463
1477
1464
private <T > T doInLock (Supplier <T > supplier ) {
@@ -1480,8 +1467,7 @@ private <T> T doInLock(Supplier<T> supplier) {
1480
1467
1481
1468
try {
1482
1469
return supplier .get ();
1483
- }
1484
- finally {
1470
+ } finally {
1485
1471
this .lock .unlock ();
1486
1472
}
1487
1473
}
@@ -1543,12 +1529,12 @@ private StatefulConnection<E, E> getNativeConnection() {
1543
1529
}
1544
1530
1545
1531
/**
1546
- * Null-safe operation to evaluate whether the given {@link StatefulConnection connetion}
1547
- * is {@link StatefulConnection#isOpen() open}.
1532
+ * Null-safe operation to evaluate whether the given {@link StatefulConnection connetion} is
1533
+ * {@link StatefulConnection#isOpen() open}.
1548
1534
*
1549
1535
* @param connection {@link StatefulConnection} to evaluate.
1550
- * @return a boolean value indicating whether the given {@link StatefulConnection} is not {@literal null}
1551
- * and is {@link StatefulConnection#isOpen() open}.
1536
+ * @return a boolean value indicating whether the given {@link StatefulConnection} is not {@literal null} and is
1537
+ * {@link StatefulConnection#isOpen() open}.
1552
1538
* @see io.lettuce.core.api.StatefulConnection#isOpen()
1553
1539
*/
1554
1540
private boolean isOpen (@ Nullable StatefulConnection <?, ?> connection ) {
@@ -1558,8 +1544,8 @@ private boolean isOpen(@Nullable StatefulConnection<?, ?> connection) {
1558
1544
/**
1559
1545
* Validate the {@link StatefulConnection connection}.
1560
1546
* <p>
1561
- * {@link StatefulConnection Connections} are considered valid if they can send/receive ping packets.
1562
- * Invalid {@link StatefulConnection connections} will be closed and the connection state will be reset.
1547
+ * {@link StatefulConnection Connections} are considered valid if they can send/receive ping packets. Invalid
1548
+ * {@link StatefulConnection connections} will be closed and the connection state will be reset.
1563
1549
*/
1564
1550
void validateConnection () {
1565
1551
0 commit comments