Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reformat clientSideCache variable names #3761

Merged
merged 1 commit into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/main/java/redis/clients/jedis/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();

Expand Down
5 changes: 1 addition & 4 deletions src/main/java/redis/clients/jedis/ConnectionFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ public void destroyObject(PooledObject<Connection> pooledConnection) throws Exce
@Override
public PooledObject<Connection> 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);
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/redis/clients/jedis/ConnectionPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Connection> factory) {
Expand All @@ -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<Connection> poolConfig) {
this(new ConnectionFactory(hostAndPort, clientConfig, csCache), poolConfig);
this(new ConnectionFactory(hostAndPort, clientConfig, clientSideCache), poolConfig);
}

public ConnectionPool(PooledObjectFactory<Connection> factory,
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/redis/clients/jedis/JedisClusterInfoCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,19 @@ public JedisClusterInfoCache(final JedisClientConfig clientConfig, final Set<Hos
this(clientConfig, null, null, startNodes);
}

public JedisClusterInfoCache(final JedisClientConfig clientConfig, ClientSideCache csCache, final Set<HostAndPort> startNodes) {
this(clientConfig, csCache, null, startNodes);
public JedisClusterInfoCache(final JedisClientConfig clientConfig, ClientSideCache clientSideCache,
final Set<HostAndPort> startNodes) {
this(clientConfig, clientSideCache, null, startNodes);
}

public JedisClusterInfoCache(final JedisClientConfig clientConfig,
final GenericObjectPoolConfig<Connection> poolConfig, final Set<HostAndPort> startNodes) {
this(clientConfig, null, poolConfig, startNodes);
}

public JedisClusterInfoCache(final JedisClientConfig clientConfig, ClientSideCache csCache,
public JedisClusterInfoCache(final JedisClientConfig clientConfig, ClientSideCache clientSideCache,
final GenericObjectPoolConfig<Connection> poolConfig, final Set<HostAndPort> startNodes) {
this(clientConfig, csCache, poolConfig, startNodes, null);
this(clientConfig, clientSideCache, poolConfig, startNodes, null);
}

public JedisClusterInfoCache(final JedisClientConfig clientConfig,
Expand All @@ -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<Connection> poolConfig, final Set<HostAndPort> 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);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/redis/clients/jedis/JedisPooled.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Connection> factory) {
Expand Down Expand Up @@ -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<Connection> 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<Connection> poolConfig,
Expand Down
20 changes: 0 additions & 20 deletions src/main/java/redis/clients/jedis/Protocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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(" ");
Expand Down Expand Up @@ -196,24 +183,19 @@ private static byte[] processBulkReply(final RedisInputStream is) {
}

private static List<Object> processMultiBulkReply(final RedisInputStream is) {
// private static List<Object> 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<Object> 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);
}
}
return ret;
}

// private static List<Object> processMultiBulkReply(final RedisInputStream is) {
// private static List<Object> processMultiBulkReply(final int num, final RedisInputStream is) {
private static List<KeyValue> processMapKeyValueReply(final RedisInputStream is) {
final int num = is.readIntCrLf();
if (num == -1) return null;
Expand All @@ -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);
Expand All @@ -246,7 +227,6 @@ private static void readPushes(final RedisInputStream is, final ClientSideCache

private static void processPush(final RedisInputStream is, ClientSideCache cache) {
List<Object> 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public ClusterConnectionProvider(Set<HostAndPort> clusterNodes, JedisClientConfi
initializeSlotsCache(clusterNodes, clientConfig);
}

public ClusterConnectionProvider(Set<HostAndPort> clusterNodes, JedisClientConfig clientConfig, ClientSideCache csCache) {
this.cache = new JedisClusterInfoCache(clientConfig, csCache, clusterNodes);
public ClusterConnectionProvider(Set<HostAndPort> clusterNodes, JedisClientConfig clientConfig, ClientSideCache clientSideCache) {
this.cache = new JedisClusterInfoCache(clientConfig, clientSideCache, clusterNodes);
initializeSlotsCache(clusterNodes, clientConfig);
}

Expand All @@ -41,9 +41,9 @@ public ClusterConnectionProvider(Set<HostAndPort> clusterNodes, JedisClientConfi
initializeSlotsCache(clusterNodes, clientConfig);
}

public ClusterConnectionProvider(Set<HostAndPort> clusterNodes, JedisClientConfig clientConfig, ClientSideCache csCache,
public ClusterConnectionProvider(Set<HostAndPort> clusterNodes, JedisClientConfig clientConfig, ClientSideCache clientSideCache,
GenericObjectPoolConfig<Connection> poolConfig) {
this.cache = new JedisClusterInfoCache(clientConfig, csCache, poolConfig, clusterNodes);
this.cache = new JedisClusterInfoCache(clientConfig, clientSideCache, poolConfig, clusterNodes);
initializeSlotsCache(clusterNodes, clientConfig);
}

Expand All @@ -53,9 +53,9 @@ public ClusterConnectionProvider(Set<HostAndPort> clusterNodes, JedisClientConfi
initializeSlotsCache(clusterNodes, clientConfig);
}

public ClusterConnectionProvider(Set<HostAndPort> clusterNodes, JedisClientConfig clientConfig, ClientSideCache csCache,
public ClusterConnectionProvider(Set<HostAndPort> clusterNodes, JedisClientConfig clientConfig, ClientSideCache clientSideCache,
GenericObjectPoolConfig<Connection> poolConfig, Duration topologyRefreshPeriod) {
this.cache = new JedisClusterInfoCache(clientConfig, csCache, poolConfig, clusterNodes, topologyRefreshPeriod);
this.cache = new JedisClusterInfoCache(clientConfig, clientSideCache, poolConfig, clusterNodes, topologyRefreshPeriod);
initializeSlotsCache(clusterNodes, clientConfig);
}

Expand Down Expand Up @@ -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<ConnectionPool> pools = cache.getShuffledNodesPool();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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<Connection> poolConfig) {
this(new ConnectionPool(hostAndPort, clientConfig, csCache, poolConfig));
this(new ConnectionPool(hostAndPort, clientConfig, clientSideCache, poolConfig));
this.connectionMapKey = hostAndPort;
}

Expand Down
Loading