Skip to content

Commit 125342f

Browse files
committed
Polishing.
Revert changes in JedisClusterKeyCommands. Switch clusterGetNodeForKey method to calculate the slot locally. See #2156 Original pull request: #2159.
1 parent 5d617ed commit 125342f

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterConnection.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package org.springframework.data.redis.connection.jedis;
1717

1818
import redis.clients.jedis.BinaryJedis;
19-
import redis.clients.jedis.BinaryJedisPubSub;
2019
import redis.clients.jedis.Client;
2120
import redis.clients.jedis.HostAndPort;
2221
import redis.clients.jedis.Jedis;
@@ -38,6 +37,7 @@
3837

3938
import org.apache.commons.logging.Log;
4039
import org.apache.commons.logging.LogFactory;
40+
4141
import org.springframework.beans.DirectFieldAccessor;
4242
import org.springframework.beans.PropertyAccessor;
4343
import org.springframework.dao.DataAccessException;
@@ -691,6 +691,15 @@ public Integer clusterGetSlotForKey(byte[] key) {
691691
.clusterKeySlot(JedisConverters.toString(key)).intValue()).getValue();
692692
}
693693

694+
/*
695+
* (non-Javadoc)
696+
* @see org.springframework.data.redis.connection.RedisClusterCommands#clusterGetNodeForKey(byte[])
697+
*/
698+
@Override
699+
public RedisClusterNode clusterGetNodeForKey(byte[] key) {
700+
return topologyProvider.getTopology().getKeyServingMasterNode(key);
701+
}
702+
694703
/*
695704
* (non-Javadoc)
696705
* @see org.springframework.data.redis.connection.RedisClusterCommands#clusterGetNodeForSlot(int)
@@ -757,15 +766,6 @@ public Map<RedisClusterNode, Collection<RedisClusterNode>> clusterGetMasterSlave
757766
return result;
758767
}
759768

760-
/*
761-
* (non-Javadoc)
762-
* @see org.springframework.data.redis.connection.RedisClusterCommands#clusterGetNodeForKey(byte[])
763-
*/
764-
@Override
765-
public RedisClusterNode clusterGetNodeForKey(byte[] key) {
766-
return clusterGetNodeForSlot(clusterGetSlotForKey(key));
767-
}
768-
769769
/*
770770
* (non-Javadoc)
771771
* @see org.springframework.data.redis.connection.RedisClusterCommands#clusterGetClusterInfo()

src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterKeyCommands.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ public Long pTtl(byte[] key) {
455455

456456
return connection.getClusterCommandExecutor()
457457
.executeCommandOnSingleNode((JedisClusterCommandCallback<Long>) client -> client.pttl(key),
458-
connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key))
458+
connection.clusterGetNodeForKey(key))
459459
.getValue();
460460
}
461461

@@ -471,7 +471,7 @@ public Long pTtl(byte[] key, TimeUnit timeUnit) {
471471
return connection.getClusterCommandExecutor()
472472
.executeCommandOnSingleNode(
473473
(JedisClusterCommandCallback<Long>) client -> Converters.millisecondsToTimeUnit(client.pttl(key), timeUnit),
474-
connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key))
474+
connection.clusterGetNodeForKey(key))
475475
.getValue();
476476
}
477477

@@ -486,7 +486,7 @@ public byte[] dump(byte[] key) {
486486

487487
return connection.getClusterCommandExecutor()
488488
.executeCommandOnSingleNode((JedisClusterCommandCallback<byte[]>) client -> client.dump(key),
489-
connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key))
489+
connection.clusterGetNodeForKey(key))
490490
.getValue();
491491
}
492492

@@ -513,7 +513,7 @@ public void restore(byte[] key, long ttlInMillis, byte[] serializedValue, boolea
513513
return JedisConverters.toString(this.connection.execute("RESTORE", key,
514514
Arrays.asList(JedisConverters.toBytes(ttlInMillis), serializedValue, JedisConverters.toBytes("REPLACE"))));
515515

516-
}, connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key));
516+
}, connection.clusterGetNodeForKey(key));
517517
}
518518

519519
/*
@@ -596,7 +596,7 @@ public ValueEncoding encodingOf(byte[] key) {
596596

597597
return connection.getClusterCommandExecutor()
598598
.executeCommandOnSingleNode((JedisClusterCommandCallback<byte[]>) client -> client.objectEncoding(key),
599-
connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key))
599+
connection.clusterGetNodeForKey(key))
600600
.mapValue(JedisConverters::toEncoding);
601601
}
602602

@@ -612,7 +612,7 @@ public Duration idletime(byte[] key) {
612612

613613
return connection.getClusterCommandExecutor()
614614
.executeCommandOnSingleNode((JedisClusterCommandCallback<Long>) client -> client.objectIdletime(key),
615-
connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key))
615+
connection.clusterGetNodeForKey(key))
616616
.mapValue(Converters::secondsToDuration);
617617
}
618618

@@ -628,7 +628,7 @@ public Long refcount(byte[] key) {
628628

629629
return connection.getClusterCommandExecutor()
630630
.executeCommandOnSingleNode((JedisClusterCommandCallback<Long>) client -> client.objectRefcount(key),
631-
connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key))
631+
connection.clusterGetNodeForKey(key))
632632
.getValue();
633633

634634
}

0 commit comments

Comments
 (0)