diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnectionFactory.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnectionFactory.java index 8e1bccb9f..9e5dc89fe 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnectionFactory.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnectionFactory.java @@ -74,9 +74,11 @@ import org.springframework.util.ObjectUtils; *
- * This connection factory must be {@link #afterPropertiesSet() initialized} and {@link SmartLifecycle#start() started} - * prior to {@link #getConnection obtaining connections}. You can {@link SmartLifecycle#stop()} and - * {@link SmartLifecycle#start() restart} this connection factory if needed. + * This connection factory implements {@link InitializingBean} and {@link SmartLifecycle} for flexible lifecycle + * control. It must be {@link #afterPropertiesSet() initialized} and {@link #start() started} before you can obtain a + * connection. {@link #afterPropertiesSet() Initialization} {@link SmartLifecycle#start() starts} this bean + * {@link #isAutoStartup() by default}. You can {@link SmartLifecycle#stop()} and {@link SmartLifecycle#start() restart} + * this connection factory if needed. * * @author Costin Leau * @author Thomas Darimont @@ -96,12 +98,15 @@ public class JedisConnectionFactory private final JedisClientConfiguration clientConfiguration; - private boolean convertPipelineAndTxResults = true; private RedisStandaloneConfiguration standaloneConfig = new RedisStandaloneConfiguration("localhost", Protocol.DEFAULT_PORT); private @Nullable RedisConfiguration configuration; + private int phase = 0; // in between min and max values + + private boolean convertPipelineAndTxResults = true; + /** * Lifecycle state of this factory. */ @@ -118,8 +123,6 @@ public class JedisConnectionFactory private @Nullable ClusterTopologyProvider topologyProvider; private @Nullable ClusterCommandExecutor clusterCommandExecutor; - private int phase = DEFAULT_PHASE - 10; - /** * Constructs a new {@link JedisConnectionFactory} instance with default settings (default connection pooling). */ @@ -266,7 +269,8 @@ public class JedisConnectionFactory public void afterPropertiesSet() { clientConfig = createClientConfig(getDatabase(), getRedisUsername(), getRedisPassword()); - if(isAutoStartup()) { + + if (isAutoStartup()) { start(); } } @@ -368,6 +372,21 @@ public class JedisConnectionFactory } } + @Override + public int getPhase() { + return phase; + } + + /** + * Specify the lifecycle phase for pausing and resuming this executor. The default is {@code 0}. + * + * @since 3.2 + * @see SmartLifecycle#getPhase() + */ + public void setPhase(int phase) { + this.phase = phase; + } + @Override public boolean isRunning() { return State.STARTED.equals(state.get()); @@ -859,21 +878,6 @@ public class JedisConnectionFactory return RedisConfiguration.isClusterConfiguration(configuration); } - @Override - public int getPhase() { - return phase; - } - - /** - * Specify the lifecycle phase for pausing and resuming this executor. - * The default is {@link #DEFAULT_PHASE} - 10. - * @since 3.2 - * @see SmartLifecycle#getPhase() - */ - public void setPhase(int phase) { - this.phase = phase; - } - @Override public RedisSentinelConnection getSentinelConnection() { diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java index f494f6c1a..12aa16a46 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java @@ -89,9 +89,11 @@ import org.springframework.util.StringUtils; *
- * This connection factory must be {@link #afterPropertiesSet() initialized} and {@link SmartLifecycle#start() started} - * prior to {@link #getConnection obtaining connections}. You can {@link SmartLifecycle#stop()} and - * {@link SmartLifecycle#start() restart} this connection factory if needed. + * This connection factory implements {@link InitializingBean} and {@link SmartLifecycle} for flexible lifecycle + * control. It must be {@link #afterPropertiesSet() initialized} and {@link #start() started} before you can obtain a + * connection. {@link #afterPropertiesSet() Initialization} {@link SmartLifecycle#start() starts} this bean + * {@link #isAutoStartup() by default}. You can {@link SmartLifecycle#stop()} and {@link SmartLifecycle#start() restart} + * this connection factory if needed. * * @author Costin Leau * @author Jennifer Hickey @@ -120,6 +122,7 @@ public class LettuceConnectionFactory implements RedisConnectionFactory, Reactiv private RedisStandaloneConfiguration standaloneConfig = new RedisStandaloneConfiguration("localhost", 6379); private @Nullable RedisConfiguration configuration; + private int phase = 0; // in between min and max values private boolean validateConnection = false; private boolean shareNativeConnection = true; @@ -128,8 +131,6 @@ public class LettuceConnectionFactory implements RedisConnectionFactory, Reactiv private PipeliningFlushPolicy pipeliningFlushPolicy = PipeliningFlushPolicy.flushEachCommand(); - private int phase = DEFAULT_PHASE - 10; - /** * Lifecycle state of this factory. */ @@ -395,6 +396,21 @@ public class LettuceConnectionFactory implements RedisConnectionFactory, Reactiv state.set(State.STOPPED); } + @Override + public int getPhase() { + return phase; + } + + /** + * Specify the lifecycle phase for pausing and resuming this executor. The default is {@code 0}. + * + * @since 3.2 + * @see SmartLifecycle#getPhase() + */ + public void setPhase(int phase) { + this.phase = phase; + } + @Override public boolean isRunning() { return State.STARTED.equals(state.get()); @@ -402,7 +418,7 @@ public class LettuceConnectionFactory implements RedisConnectionFactory, Reactiv @Override public void afterPropertiesSet() { - if(isAutoStartup()) { + if (isAutoStartup()) { start(); } } @@ -1101,21 +1117,6 @@ public class LettuceConnectionFactory implements RedisConnectionFactory, Reactiv return RedisConfiguration.isClusterConfiguration(configuration); } - @Override - public int getPhase() { - return phase; - } - - /** - * Specify the lifecycle phase for pausing and resuming this executor. - * The default is {@link #DEFAULT_PHASE} - 10. - * @since 3.2 - * @see SmartLifecycle#getPhase() - */ - public void setPhase(int phase) { - this.phase = phase; - } - /** * @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.