From c85765053c253ee860ae39dd5fb7f6afaffe8a7e Mon Sep 17 00:00:00 2001 From: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> Date: Sun, 10 Mar 2024 21:44:05 +0600 Subject: [PATCH] Reformat clientSideCache variable names --- .../java/redis/clients/jedis/Connection.java | 11 +++++----- .../clients/jedis/ConnectionFactory.java | 5 +---- .../redis/clients/jedis/ConnectionPool.java | 8 ++++---- .../clients/jedis/JedisClusterInfoCache.java | 13 ++++++------ .../java/redis/clients/jedis/JedisPooled.java | 10 +++++----- .../java/redis/clients/jedis/Protocol.java | 20 ------------------- .../providers/ClusterConnectionProvider.java | 17 ++++++++-------- .../providers/PooledConnectionProvider.java | 8 ++++---- 8 files changed, 35 insertions(+), 57 deletions(-) diff --git a/src/main/java/redis/clients/jedis/Connection.java b/src/main/java/redis/clients/jedis/Connection.java index b2d2aac27e..cada041461 100644 --- a/src/main/java/redis/clients/jedis/Connection.java +++ b/src/main/java/redis/clients/jedis/Connection.java @@ -64,15 +64,16 @@ public Connection(final JedisSocketFactory socketFactory, JedisClientConfig clie this.socketFactory = socketFactory; this.soTimeout = clientConfig.getSocketTimeoutMillis(); this.infiniteSoTimeout = clientConfig.getBlockingSocketTimeoutMillis(); - initializeConnection(clientConfig); + initializeFromClientConfig(clientConfig); } - public Connection(final JedisSocketFactory socketFactory, JedisClientConfig clientConfig, ClientSideCache csCache) { + public Connection(final JedisSocketFactory socketFactory, JedisClientConfig clientConfig, + ClientSideCache clientSideCache) { this.socketFactory = socketFactory; this.soTimeout = clientConfig.getSocketTimeoutMillis(); this.infiniteSoTimeout = clientConfig.getBlockingSocketTimeoutMillis(); - initializeConnection(clientConfig); - initializeClientSideCache(csCache); + initializeFromClientConfig(clientConfig); + initializeClientSideCache(clientSideCache); } @Override @@ -392,7 +393,7 @@ private static boolean validateClientInfo(String info) { return true; } - private void initializeConnection(final JedisClientConfig config) { + private void initializeFromClientConfig(final JedisClientConfig config) { try { connect(); diff --git a/src/main/java/redis/clients/jedis/ConnectionFactory.java b/src/main/java/redis/clients/jedis/ConnectionFactory.java index 2d122aab15..270cf1fca1 100644 --- a/src/main/java/redis/clients/jedis/ConnectionFactory.java +++ b/src/main/java/redis/clients/jedis/ConnectionFactory.java @@ -61,10 +61,7 @@ public void destroyObject(PooledObject pooledConnection) throws Exce @Override public PooledObject makeObject() throws Exception { try { - Connection jedis = clientSideCache == null - ? new Connection(jedisSocketFactory, clientConfig) - : new Connection(jedisSocketFactory, clientConfig, clientSideCache); - + Connection jedis = new Connection(jedisSocketFactory, clientConfig, clientSideCache); return new DefaultPooledObject<>(jedis); } catch (JedisException je) { logger.debug("Error while makeObject", je); diff --git a/src/main/java/redis/clients/jedis/ConnectionPool.java b/src/main/java/redis/clients/jedis/ConnectionPool.java index 59f416649c..b3c10ecd21 100644 --- a/src/main/java/redis/clients/jedis/ConnectionPool.java +++ b/src/main/java/redis/clients/jedis/ConnectionPool.java @@ -11,8 +11,8 @@ public ConnectionPool(HostAndPort hostAndPort, JedisClientConfig clientConfig) { this(new ConnectionFactory(hostAndPort, clientConfig)); } - public ConnectionPool(HostAndPort hostAndPort, JedisClientConfig clientConfig, ClientSideCache csCache) { - this(new ConnectionFactory(hostAndPort, clientConfig, csCache)); + public ConnectionPool(HostAndPort hostAndPort, JedisClientConfig clientConfig, ClientSideCache clientSideCache) { + this(new ConnectionFactory(hostAndPort, clientConfig, clientSideCache)); } public ConnectionPool(PooledObjectFactory factory) { @@ -24,9 +24,9 @@ public ConnectionPool(HostAndPort hostAndPort, JedisClientConfig clientConfig, this(new ConnectionFactory(hostAndPort, clientConfig), poolConfig); } - public ConnectionPool(HostAndPort hostAndPort, JedisClientConfig clientConfig, ClientSideCache csCache, + public ConnectionPool(HostAndPort hostAndPort, JedisClientConfig clientConfig, ClientSideCache clientSideCache, GenericObjectPoolConfig poolConfig) { - this(new ConnectionFactory(hostAndPort, clientConfig, csCache), poolConfig); + this(new ConnectionFactory(hostAndPort, clientConfig, clientSideCache), poolConfig); } public ConnectionPool(PooledObjectFactory factory, diff --git a/src/main/java/redis/clients/jedis/JedisClusterInfoCache.java b/src/main/java/redis/clients/jedis/JedisClusterInfoCache.java index 482fe12cb5..48ab655b46 100644 --- a/src/main/java/redis/clients/jedis/JedisClusterInfoCache.java +++ b/src/main/java/redis/clients/jedis/JedisClusterInfoCache.java @@ -66,8 +66,9 @@ public JedisClusterInfoCache(final JedisClientConfig clientConfig, final Set startNodes) { - this(clientConfig, csCache, null, startNodes); + public JedisClusterInfoCache(final JedisClientConfig clientConfig, ClientSideCache clientSideCache, + final Set startNodes) { + this(clientConfig, clientSideCache, null, startNodes); } public JedisClusterInfoCache(final JedisClientConfig clientConfig, @@ -75,9 +76,9 @@ public JedisClusterInfoCache(final JedisClientConfig clientConfig, this(clientConfig, null, poolConfig, startNodes); } - public JedisClusterInfoCache(final JedisClientConfig clientConfig, ClientSideCache csCache, + public JedisClusterInfoCache(final JedisClientConfig clientConfig, ClientSideCache clientSideCache, final GenericObjectPoolConfig poolConfig, final Set startNodes) { - this(clientConfig, csCache, poolConfig, startNodes, null); + this(clientConfig, clientSideCache, poolConfig, startNodes, null); } public JedisClusterInfoCache(final JedisClientConfig clientConfig, @@ -86,12 +87,12 @@ public JedisClusterInfoCache(final JedisClientConfig clientConfig, this(clientConfig, null, poolConfig, startNodes, topologyRefreshPeriod); } - public JedisClusterInfoCache(final JedisClientConfig clientConfig, ClientSideCache csCache, + public JedisClusterInfoCache(final JedisClientConfig clientConfig, ClientSideCache clientSideCache, final GenericObjectPoolConfig poolConfig, final Set startNodes, final Duration topologyRefreshPeriod) { this.poolConfig = poolConfig; this.clientConfig = clientConfig; - this.clientSideCache = csCache; + this.clientSideCache = clientSideCache; this.startNodes = startNodes; if (topologyRefreshPeriod != null) { logger.info("Cluster topology refresh start, period: {}, startNodes: {}", topologyRefreshPeriod, startNodes); diff --git a/src/main/java/redis/clients/jedis/JedisPooled.java b/src/main/java/redis/clients/jedis/JedisPooled.java index 4bda1d1ebb..5be534fcff 100644 --- a/src/main/java/redis/clients/jedis/JedisPooled.java +++ b/src/main/java/redis/clients/jedis/JedisPooled.java @@ -76,8 +76,8 @@ public JedisPooled(final HostAndPort hostAndPort, final JedisClientConfig client super(hostAndPort, clientConfig); } - public JedisPooled(final HostAndPort hostAndPort, final JedisClientConfig clientConfig, ClientSideCache csCache) { - super(hostAndPort, clientConfig, csCache); + public JedisPooled(final HostAndPort hostAndPort, final JedisClientConfig clientConfig, ClientSideCache clientSideCache) { + super(hostAndPort, clientConfig, clientSideCache); } public JedisPooled(PooledObjectFactory factory) { @@ -380,10 +380,10 @@ public JedisPooled(final HostAndPort hostAndPort, final JedisClientConfig client super(new PooledConnectionProvider(hostAndPort, clientConfig, poolConfig), clientConfig.getRedisProtocol()); } - public JedisPooled(final HostAndPort hostAndPort, final JedisClientConfig clientConfig, ClientSideCache csCache, + public JedisPooled(final HostAndPort hostAndPort, final JedisClientConfig clientConfig, ClientSideCache clientSideCache, final GenericObjectPoolConfig poolConfig) { - super(new PooledConnectionProvider(hostAndPort, clientConfig, csCache, poolConfig), - clientConfig.getRedisProtocol(), csCache); + super(new PooledConnectionProvider(hostAndPort, clientConfig, clientSideCache, poolConfig), + clientConfig.getRedisProtocol(), clientSideCache); } public JedisPooled(final GenericObjectPoolConfig poolConfig, diff --git a/src/main/java/redis/clients/jedis/Protocol.java b/src/main/java/redis/clients/jedis/Protocol.java index ad676d88ce..40989c2502 100644 --- a/src/main/java/redis/clients/jedis/Protocol.java +++ b/src/main/java/redis/clients/jedis/Protocol.java @@ -88,13 +88,9 @@ private static void processError(final RedisInputStream is) { // Maybe Read only first 5 bytes instead? if (message.startsWith(MOVED_PREFIX)) { String[] movedInfo = parseTargetHostAndSlot(message); -// throw new JedisMovedDataException(message, new HostAndPort(movedInfo[1], -// Integer.parseInt(movedInfo[2])), Integer.parseInt(movedInfo[0])); throw new JedisMovedDataException(message, HostAndPort.from(movedInfo[1]), Integer.parseInt(movedInfo[0])); } else if (message.startsWith(ASK_PREFIX)) { String[] askInfo = parseTargetHostAndSlot(message); -// throw new JedisAskDataException(message, new HostAndPort(askInfo[1], -// Integer.parseInt(askInfo[2])), Integer.parseInt(askInfo[0])); throw new JedisAskDataException(message, HostAndPort.from(askInfo[1]), Integer.parseInt(askInfo[0])); } else if (message.startsWith(CLUSTERDOWN_PREFIX)) { throw new JedisClusterException(message); @@ -119,15 +115,6 @@ public static String readErrorLineIfPossible(RedisInputStream is) { return is.readLine(); } -// private static String[] parseTargetHostAndSlot(String clusterRedirectResponse) { -// String[] response = new String[3]; -// String[] messageInfo = clusterRedirectResponse.split(" "); -// String[] targetHostAndPort = HostAndPort.extractParts(messageInfo[2]); -// response[0] = messageInfo[1]; -// response[1] = targetHostAndPort[0]; -// response[2] = targetHostAndPort[1]; -// return response; -// } private static String[] parseTargetHostAndSlot(String clusterRedirectResponse) { String[] response = new String[2]; String[] messageInfo = clusterRedirectResponse.split(" "); @@ -196,15 +183,12 @@ private static byte[] processBulkReply(final RedisInputStream is) { } private static List processMultiBulkReply(final RedisInputStream is) { - // private static List processMultiBulkReply(final int num, final RedisInputStream is) { final int num = is.readIntCrLf(); - //System.out.println("MULTI BULK: " + num); if (num == -1) return null; final List ret = new ArrayList<>(num); for (int i = 0; i < num; i++) { try { ret.add(process(is)); - //System.out.println("MULTI >> " + (i+1) + ": " + SafeEncoder.encodeObject(ret.get(i))); } catch (JedisDataException e) { ret.add(e); } @@ -212,8 +196,6 @@ private static List processMultiBulkReply(final RedisInputStream is) { return ret; } - // private static List processMultiBulkReply(final RedisInputStream is) { - // private static List processMultiBulkReply(final int num, final RedisInputStream is) { private static List processMapKeyValueReply(final RedisInputStream is) { final int num = is.readIntCrLf(); if (num == -1) return null; @@ -236,7 +218,6 @@ public static Object read(final RedisInputStream is, final ClientSideCache cache private static void readPushes(final RedisInputStream is, final ClientSideCache cache) { if (cache != null) { - //System.out.println("PEEK: " + is.peekByte()); while (is.peek(GREATER_THAN_BYTE)) { is.readByte(); processPush(is, cache); @@ -246,7 +227,6 @@ private static void readPushes(final RedisInputStream is, final ClientSideCache private static void processPush(final RedisInputStream is, ClientSideCache cache) { List list = processMultiBulkReply(is); - //System.out.println("PUSH: " + SafeEncoder.encodeObject(list)); if (list.size() == 2 && list.get(0) instanceof byte[] && Arrays.equals(INVALIDATE_BYTES, (byte[]) list.get(0))) { cache.invalidate((List) list.get(1)); diff --git a/src/main/java/redis/clients/jedis/providers/ClusterConnectionProvider.java b/src/main/java/redis/clients/jedis/providers/ClusterConnectionProvider.java index 6b148a5e77..ad3c2e0872 100644 --- a/src/main/java/redis/clients/jedis/providers/ClusterConnectionProvider.java +++ b/src/main/java/redis/clients/jedis/providers/ClusterConnectionProvider.java @@ -30,8 +30,8 @@ public ClusterConnectionProvider(Set clusterNodes, JedisClientConfi initializeSlotsCache(clusterNodes, clientConfig); } - public ClusterConnectionProvider(Set clusterNodes, JedisClientConfig clientConfig, ClientSideCache csCache) { - this.cache = new JedisClusterInfoCache(clientConfig, csCache, clusterNodes); + public ClusterConnectionProvider(Set clusterNodes, JedisClientConfig clientConfig, ClientSideCache clientSideCache) { + this.cache = new JedisClusterInfoCache(clientConfig, clientSideCache, clusterNodes); initializeSlotsCache(clusterNodes, clientConfig); } @@ -41,9 +41,9 @@ public ClusterConnectionProvider(Set clusterNodes, JedisClientConfi initializeSlotsCache(clusterNodes, clientConfig); } - public ClusterConnectionProvider(Set clusterNodes, JedisClientConfig clientConfig, ClientSideCache csCache, + public ClusterConnectionProvider(Set clusterNodes, JedisClientConfig clientConfig, ClientSideCache clientSideCache, GenericObjectPoolConfig poolConfig) { - this.cache = new JedisClusterInfoCache(clientConfig, csCache, poolConfig, clusterNodes); + this.cache = new JedisClusterInfoCache(clientConfig, clientSideCache, poolConfig, clusterNodes); initializeSlotsCache(clusterNodes, clientConfig); } @@ -53,9 +53,9 @@ public ClusterConnectionProvider(Set clusterNodes, JedisClientConfi initializeSlotsCache(clusterNodes, clientConfig); } - public ClusterConnectionProvider(Set clusterNodes, JedisClientConfig clientConfig, ClientSideCache csCache, + public ClusterConnectionProvider(Set clusterNodes, JedisClientConfig clientConfig, ClientSideCache clientSideCache, GenericObjectPoolConfig poolConfig, Duration topologyRefreshPeriod) { - this.cache = new JedisClusterInfoCache(clientConfig, csCache, poolConfig, clusterNodes, topologyRefreshPeriod); + this.cache = new JedisClusterInfoCache(clientConfig, clientSideCache, poolConfig, clusterNodes, topologyRefreshPeriod); initializeSlotsCache(clusterNodes, clientConfig); } @@ -122,9 +122,8 @@ public Connection getConnection(CommandArguments args) { @Override public Connection getConnection() { - // In antirez's redis-rb-cluster implementation, getRandomConnection always - // return valid connection (able to ping-pong) or exception if all - // connections are invalid + // In antirez's redis-rb-cluster implementation, getRandomConnection always return + // valid connection (able to ping-pong) or exception if all connections are invalid List pools = cache.getShuffledNodesPool(); diff --git a/src/main/java/redis/clients/jedis/providers/PooledConnectionProvider.java b/src/main/java/redis/clients/jedis/providers/PooledConnectionProvider.java index 0d85fabad2..0b50ec4e87 100644 --- a/src/main/java/redis/clients/jedis/providers/PooledConnectionProvider.java +++ b/src/main/java/redis/clients/jedis/providers/PooledConnectionProvider.java @@ -29,8 +29,8 @@ public PooledConnectionProvider(HostAndPort hostAndPort, JedisClientConfig clien this.connectionMapKey = hostAndPort; } - public PooledConnectionProvider(HostAndPort hostAndPort, JedisClientConfig clientConfig, ClientSideCache csCache) { - this(new ConnectionPool(hostAndPort, clientConfig, csCache)); + public PooledConnectionProvider(HostAndPort hostAndPort, JedisClientConfig clientConfig, ClientSideCache clientSideCache) { + this(new ConnectionPool(hostAndPort, clientConfig, clientSideCache)); this.connectionMapKey = hostAndPort; } @@ -40,9 +40,9 @@ public PooledConnectionProvider(HostAndPort hostAndPort, JedisClientConfig clien this.connectionMapKey = hostAndPort; } - public PooledConnectionProvider(HostAndPort hostAndPort, JedisClientConfig clientConfig, ClientSideCache csCache, + public PooledConnectionProvider(HostAndPort hostAndPort, JedisClientConfig clientConfig, ClientSideCache clientSideCache, GenericObjectPoolConfig poolConfig) { - this(new ConnectionPool(hostAndPort, clientConfig, csCache, poolConfig)); + this(new ConnectionPool(hostAndPort, clientConfig, clientSideCache, poolConfig)); this.connectionMapKey = hostAndPort; }