Skip to content

Commit

Permalink
Polish "Adding CacheConfig"
Browse files Browse the repository at this point in the history
Polish #3919 - address some pending change requests

- Swap contructor placements
- Fix grammar in exception message
  • Loading branch information
sazzad16 committed Aug 28, 2024
1 parent 88cf9bc commit 1d213bb
Showing 5 changed files with 32 additions and 31 deletions.
13 changes: 6 additions & 7 deletions src/main/java/redis/clients/jedis/JedisCluster.java
Original file line number Diff line number Diff line change
@@ -222,22 +222,21 @@ private JedisCluster(ClusterConnectionProvider provider, int maxAttempts, Durati
}

@Experimental
public JedisCluster(Set<HostAndPort> clusterNodes, JedisClientConfig clientConfig, Cache clientSideCache) {
this(clusterNodes, clientConfig, clientSideCache, DEFAULT_MAX_ATTEMPTS,
Duration.ofMillis(DEFAULT_MAX_ATTEMPTS * clientConfig.getSocketTimeoutMillis()));
public JedisCluster(Set<HostAndPort> hnp, JedisClientConfig jedisClientConfig, CacheConfig cacheConfig) {
this(hnp, jedisClientConfig, new CacheProvider().getCache(cacheConfig));
}

@Experimental
public JedisCluster(Set<HostAndPort> hnp, JedisClientConfig jedisClientConfig, CacheConfig cacheConfig) {
this(hnp, jedisClientConfig, new CacheProvider().getCache(cacheConfig));
public JedisCluster(Set<HostAndPort> clusterNodes, JedisClientConfig clientConfig, Cache clientSideCache) {
this(clusterNodes, clientConfig, clientSideCache, DEFAULT_MAX_ATTEMPTS,
Duration.ofMillis(DEFAULT_MAX_ATTEMPTS * clientConfig.getSocketTimeoutMillis()));
}

@Experimental
public JedisCluster(Set<HostAndPort> 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
18 changes: 9 additions & 9 deletions src/main/java/redis/clients/jedis/JedisPooled.java
Original file line number Diff line number Diff line change
@@ -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<Connection> 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<Connection> 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<Connection> poolConfig) {
this(hostAndPort, clientConfig, new CacheProvider().getCache(cacheConfig), poolConfig);
super(new PooledConnectionProvider(hostAndPort, clientConfig, clientSideCache, poolConfig),
clientConfig.getRedisProtocol(), clientSideCache);
}

public JedisPooled(final GenericObjectPoolConfig<Connection> poolConfig,
12 changes: 6 additions & 6 deletions src/main/java/redis/clients/jedis/JedisSentineled.java
Original file line number Diff line number Diff line change
@@ -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<HostAndPort> 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<HostAndPort> 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,
2 changes: 1 addition & 1 deletion src/main/java/redis/clients/jedis/Protocol.java
Original file line number Diff line number Diff line change
@@ -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)) {
18 changes: 10 additions & 8 deletions src/main/java/redis/clients/jedis/UnifiedJedis.java
Original file line number Diff line number Diff line change
@@ -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));

0 comments on commit 1d213bb

Please sign in to comment.