Polishing.

Revert changes in JedisClusterKeyCommands. Switch clusterGetNodeForKey method to calculate the slot locally.

See #2156
Original pull request: #2159.
This commit is contained in:
Mark Paluch
2021-09-14 09:35:10 +02:00
parent 5d617ed11b
commit 125342f19a
2 changed files with 17 additions and 17 deletions

View File

@@ -16,7 +16,6 @@
package org.springframework.data.redis.connection.jedis;
import redis.clients.jedis.BinaryJedis;
import redis.clients.jedis.BinaryJedisPubSub;
import redis.clients.jedis.Client;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.Jedis;
@@ -38,6 +37,7 @@ import java.util.function.Function;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.PropertyAccessor;
import org.springframework.dao.DataAccessException;
@@ -691,6 +691,15 @@ public class JedisClusterConnection implements DefaultedRedisClusterConnection {
.clusterKeySlot(JedisConverters.toString(key)).intValue()).getValue();
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisClusterCommands#clusterGetNodeForKey(byte[])
*/
@Override
public RedisClusterNode clusterGetNodeForKey(byte[] key) {
return topologyProvider.getTopology().getKeyServingMasterNode(key);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisClusterCommands#clusterGetNodeForSlot(int)
@@ -757,15 +766,6 @@ public class JedisClusterConnection implements DefaultedRedisClusterConnection {
return result;
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisClusterCommands#clusterGetNodeForKey(byte[])
*/
@Override
public RedisClusterNode clusterGetNodeForKey(byte[] key) {
return clusterGetNodeForSlot(clusterGetSlotForKey(key));
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisClusterCommands#clusterGetClusterInfo()

View File

@@ -455,7 +455,7 @@ class JedisClusterKeyCommands implements RedisKeyCommands {
return connection.getClusterCommandExecutor()
.executeCommandOnSingleNode((JedisClusterCommandCallback<Long>) client -> client.pttl(key),
connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key))
connection.clusterGetNodeForKey(key))
.getValue();
}
@@ -471,7 +471,7 @@ class JedisClusterKeyCommands implements RedisKeyCommands {
return connection.getClusterCommandExecutor()
.executeCommandOnSingleNode(
(JedisClusterCommandCallback<Long>) client -> Converters.millisecondsToTimeUnit(client.pttl(key), timeUnit),
connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key))
connection.clusterGetNodeForKey(key))
.getValue();
}
@@ -486,7 +486,7 @@ class JedisClusterKeyCommands implements RedisKeyCommands {
return connection.getClusterCommandExecutor()
.executeCommandOnSingleNode((JedisClusterCommandCallback<byte[]>) client -> client.dump(key),
connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key))
connection.clusterGetNodeForKey(key))
.getValue();
}
@@ -513,7 +513,7 @@ class JedisClusterKeyCommands implements RedisKeyCommands {
return JedisConverters.toString(this.connection.execute("RESTORE", key,
Arrays.asList(JedisConverters.toBytes(ttlInMillis), serializedValue, JedisConverters.toBytes("REPLACE"))));
}, connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key));
}, connection.clusterGetNodeForKey(key));
}
/*
@@ -596,7 +596,7 @@ class JedisClusterKeyCommands implements RedisKeyCommands {
return connection.getClusterCommandExecutor()
.executeCommandOnSingleNode((JedisClusterCommandCallback<byte[]>) client -> client.objectEncoding(key),
connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key))
connection.clusterGetNodeForKey(key))
.mapValue(JedisConverters::toEncoding);
}
@@ -612,7 +612,7 @@ class JedisClusterKeyCommands implements RedisKeyCommands {
return connection.getClusterCommandExecutor()
.executeCommandOnSingleNode((JedisClusterCommandCallback<Long>) client -> client.objectIdletime(key),
connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key))
connection.clusterGetNodeForKey(key))
.mapValue(Converters::secondsToDuration);
}
@@ -628,7 +628,7 @@ class JedisClusterKeyCommands implements RedisKeyCommands {
return connection.getClusterCommandExecutor()
.executeCommandOnSingleNode((JedisClusterCommandCallback<Long>) client -> client.objectRefcount(key),
connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key))
connection.clusterGetNodeForKey(key))
.getValue();
}