From 1d213bbf7860eda4c0b3bff8590843238d685c77 Mon Sep 17 00:00:00 2001 From: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> Date: Wed, 28 Aug 2024 22:42:59 +0600 Subject: [PATCH] Polish "Adding CacheConfig" Polish #3919 - address some pending change requests - Swap contructor placements - Fix grammar in exception message --- .../java/redis/clients/jedis/JedisCluster.java | 13 ++++++------- .../java/redis/clients/jedis/JedisPooled.java | 18 +++++++++--------- .../redis/clients/jedis/JedisSentineled.java | 12 ++++++------ .../java/redis/clients/jedis/Protocol.java | 2 +- .../java/redis/clients/jedis/UnifiedJedis.java | 18 ++++++++++-------- 5 files changed, 32 insertions(+), 31 deletions(-) diff --git a/src/main/java/redis/clients/jedis/JedisCluster.java b/src/main/java/redis/clients/jedis/JedisCluster.java index 4988b5ee2f..ca1dddc0f6 100644 --- a/src/main/java/redis/clients/jedis/JedisCluster.java +++ b/src/main/java/redis/clients/jedis/JedisCluster.java @@ -222,22 +222,21 @@ private JedisCluster(ClusterConnectionProvider provider, int maxAttempts, Durati } @Experimental - public JedisCluster(Set clusterNodes, JedisClientConfig clientConfig, Cache clientSideCache) { - this(clusterNodes, clientConfig, clientSideCache, DEFAULT_MAX_ATTEMPTS, - Duration.ofMillis(DEFAULT_MAX_ATTEMPTS * clientConfig.getSocketTimeoutMillis())); + public JedisCluster(Set hnp, JedisClientConfig jedisClientConfig, CacheConfig cacheConfig) { + this(hnp, jedisClientConfig, new CacheProvider().getCache(cacheConfig)); } @Experimental - public JedisCluster(Set hnp, JedisClientConfig jedisClientConfig, CacheConfig cacheConfig) { - this(hnp, jedisClientConfig, new CacheProvider().getCache(cacheConfig)); + public JedisCluster(Set clusterNodes, JedisClientConfig clientConfig, Cache clientSideCache) { + this(clusterNodes, clientConfig, clientSideCache, DEFAULT_MAX_ATTEMPTS, + Duration.ofMillis(DEFAULT_MAX_ATTEMPTS * clientConfig.getSocketTimeoutMillis())); } @Experimental public JedisCluster(Set clusterNodes, JedisClientConfig clientConfig, Cache clientSideCache, int maxAttempts, Duration maxTotalRetriesDuration) { this(new ClusterConnectionProvider(clusterNodes, clientConfig, clientSideCache), maxAttempts, - maxTotalRetriesDuration, - clientConfig.getRedisProtocol(), clientSideCache); + maxTotalRetriesDuration, clientConfig.getRedisProtocol(), clientSideCache); } @Experimental diff --git a/src/main/java/redis/clients/jedis/JedisPooled.java b/src/main/java/redis/clients/jedis/JedisPooled.java index 7eb67374ae..eff097c1be 100644 --- a/src/main/java/redis/clients/jedis/JedisPooled.java +++ b/src/main/java/redis/clients/jedis/JedisPooled.java @@ -80,13 +80,13 @@ public JedisPooled(final HostAndPort hostAndPort, final JedisClientConfig client } @Experimental - public JedisPooled(final HostAndPort hostAndPort, final JedisClientConfig clientConfig, Cache clientSideCache) { - super(hostAndPort, clientConfig, clientSideCache); + public JedisPooled(final HostAndPort hostAndPort, final JedisClientConfig clientConfig, CacheConfig cacheConfig) { + this(hostAndPort, clientConfig, new CacheProvider().getCache(cacheConfig)); } @Experimental - public JedisPooled(final HostAndPort hostAndPort, final JedisClientConfig clientConfig, CacheConfig cacheConfig) { - this(hostAndPort, clientConfig, new CacheProvider().getCache(cacheConfig)); + public JedisPooled(final HostAndPort hostAndPort, final JedisClientConfig clientConfig, Cache clientSideCache) { + super(hostAndPort, clientConfig, clientSideCache); } public JedisPooled(PooledObjectFactory factory) { @@ -390,16 +390,16 @@ public JedisPooled(final HostAndPort hostAndPort, final JedisClientConfig client } @Experimental - public JedisPooled(final HostAndPort hostAndPort, final JedisClientConfig clientConfig, Cache clientSideCache, + public JedisPooled(final HostAndPort hostAndPort, final JedisClientConfig clientConfig, CacheConfig cacheConfig, final GenericObjectPoolConfig poolConfig) { - super(new PooledConnectionProvider(hostAndPort, clientConfig, clientSideCache, poolConfig), - clientConfig.getRedisProtocol(), clientSideCache); + this(hostAndPort, clientConfig, new CacheProvider().getCache(cacheConfig), poolConfig); } @Experimental - public JedisPooled(final HostAndPort hostAndPort, final JedisClientConfig clientConfig, CacheConfig cacheConfig, + public JedisPooled(final HostAndPort hostAndPort, final JedisClientConfig clientConfig, Cache clientSideCache, final GenericObjectPoolConfig poolConfig) { - this(hostAndPort, clientConfig, new CacheProvider().getCache(cacheConfig), poolConfig); + super(new PooledConnectionProvider(hostAndPort, clientConfig, clientSideCache, poolConfig), + clientConfig.getRedisProtocol(), clientSideCache); } public JedisPooled(final GenericObjectPoolConfig poolConfig, diff --git a/src/main/java/redis/clients/jedis/JedisSentineled.java b/src/main/java/redis/clients/jedis/JedisSentineled.java index da9eba4baf..03fbdbb9d6 100644 --- a/src/main/java/redis/clients/jedis/JedisSentineled.java +++ b/src/main/java/redis/clients/jedis/JedisSentineled.java @@ -17,17 +17,17 @@ public JedisSentineled(String masterName, final JedisClientConfig masterClientCo } @Experimental - public JedisSentineled(String masterName, final JedisClientConfig masterClientConfig, Cache clientSideCache, + public JedisSentineled(String masterName, final JedisClientConfig masterClientConfig, CacheConfig cacheConfig, Set sentinels, final JedisClientConfig sentinelClientConfig) { - super(new SentineledConnectionProvider(masterName, masterClientConfig, clientSideCache, - sentinels, sentinelClientConfig), masterClientConfig.getRedisProtocol(), clientSideCache); + this(masterName, masterClientConfig, new CacheProvider().getCache(cacheConfig), + sentinels, sentinelClientConfig); } @Experimental - public JedisSentineled(String masterName, final JedisClientConfig masterClientConfig, CacheConfig cacheConfig, + public JedisSentineled(String masterName, final JedisClientConfig masterClientConfig, Cache clientSideCache, Set sentinels, final JedisClientConfig sentinelClientConfig) { - this(masterName, masterClientConfig, new CacheProvider().getCache(cacheConfig), - sentinels, sentinelClientConfig); + super(new SentineledConnectionProvider(masterName, masterClientConfig, clientSideCache, + sentinels, sentinelClientConfig), masterClientConfig.getRedisProtocol(), clientSideCache); } public JedisSentineled(String masterName, final JedisClientConfig masterClientConfig, diff --git a/src/main/java/redis/clients/jedis/Protocol.java b/src/main/java/redis/clients/jedis/Protocol.java index f8bb5bfb8b..cd6e41581f 100644 --- a/src/main/java/redis/clients/jedis/Protocol.java +++ b/src/main/java/redis/clients/jedis/Protocol.java @@ -236,7 +236,7 @@ public static void readPushes(final RedisInputStream is, final Cache cache, bool processPush(is, cache); } } catch (IOException e) { - throw new JedisConnectionException("Failed to read pending buffer for push messages !", e); + throw new JedisConnectionException("Failed to read pending buffer for push messages!", e); } } else { while (is.peek(GREATER_THAN_BYTE)) { diff --git a/src/main/java/redis/clients/jedis/UnifiedJedis.java b/src/main/java/redis/clients/jedis/UnifiedJedis.java index 679cd8eb78..706c61be1b 100644 --- a/src/main/java/redis/clients/jedis/UnifiedJedis.java +++ b/src/main/java/redis/clients/jedis/UnifiedJedis.java @@ -99,14 +99,13 @@ public UnifiedJedis(HostAndPort hostAndPort, JedisClientConfig clientConfig) { } @Experimental - public UnifiedJedis(HostAndPort hostAndPort, JedisClientConfig clientConfig, Cache cache) { - this(new PooledConnectionProvider(hostAndPort, clientConfig, cache), clientConfig.getRedisProtocol(), - cache); + public UnifiedJedis(HostAndPort hostAndPort, JedisClientConfig clientConfig, CacheConfig cacheConfig) { + this(hostAndPort, clientConfig, new CacheProvider().getCache(cacheConfig)); } @Experimental - public UnifiedJedis(HostAndPort hostAndPort, JedisClientConfig clientConfig, CacheConfig cacheConfig) { - this(hostAndPort, clientConfig, new CacheProvider().getCache(cacheConfig)); + public UnifiedJedis(HostAndPort hostAndPort, JedisClientConfig clientConfig, Cache cache) { + this(new PooledConnectionProvider(hostAndPort, clientConfig, cache), clientConfig.getRedisProtocol(), cache); } public UnifiedJedis(ConnectionProvider provider) { @@ -153,8 +152,9 @@ public UnifiedJedis(Connection connection) { this.executor = new SimpleCommandExecutor(connection); this.commandObjects = new CommandObjects(); RedisProtocol proto = connection.getRedisProtocol(); - if (proto != null) + if (proto != null) { this.commandObjects.setProtocol(proto); + } this.graphCommandObjects = new GraphCommandObjects(this); if (connection instanceof CacheConnection) { this.cache = ((CacheConnection) connection).getCache(); @@ -257,8 +257,9 @@ public UnifiedJedis(CommandExecutor executor, ConnectionProvider provider, Comma try (Connection conn = this.provider.getConnection()) { if (conn != null) { RedisProtocol proto = conn.getRedisProtocol(); - if (proto != null) + if (proto != null) { this.commandObjects.setProtocol(proto); + } } } catch (JedisException je) { } @@ -283,8 +284,9 @@ private UnifiedJedis(CommandExecutor executor, ConnectionProvider provider, Comm this.executor = executor; this.commandObjects = commandObjects; - if (protocol != null) + if (protocol != null) { this.commandObjects.setProtocol(protocol); + } this.graphCommandObjects = new GraphCommandObjects(this); this.graphCommandObjects.setBaseCommandArgumentsCreator((comm) -> this.commandObjects.commandArguments(comm));