Skip to content

Commit 8823228

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

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
import org.apache.commons.logging.Log;
4040
import org.apache.commons.logging.LogFactory;
41+
4142
import org.springframework.beans.DirectFieldAccessor;
4243
import org.springframework.beans.PropertyAccessor;
4344
import org.springframework.dao.DataAccessException;
@@ -691,6 +692,15 @@ public Integer clusterGetSlotForKey(byte[] key) {
691692
.clusterKeySlot(JedisConverters.toString(key)).intValue()).getValue();
692693
}
693694

695+
/*
696+
* (non-Javadoc)
697+
* @see org.springframework.data.redis.connection.RedisClusterCommands#clusterGetNodeForKey(byte[])
698+
*/
699+
@Override
700+
public RedisClusterNode clusterGetNodeForKey(byte[] key) {
701+
return topologyProvider.getTopology().getKeyServingMasterNode(key);
702+
}
703+
694704
/*
695705
* (non-Javadoc)
696706
* @see org.springframework.data.redis.connection.RedisClusterCommands#clusterGetNodeForSlot(int)
@@ -757,15 +767,6 @@ public Map<RedisClusterNode, Collection<RedisClusterNode>> clusterGetMasterSlave
757767
return result;
758768
}
759769

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-
769770
/*
770771
* (non-Javadoc)
771772
* @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
@@ -441,7 +441,7 @@ public Long pTtl(byte[] key) {
441441

442442
return connection.getClusterCommandExecutor()
443443
.executeCommandOnSingleNode((JedisClusterCommandCallback<Long>) client -> client.pttl(key),
444-
connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key))
444+
connection.clusterGetNodeForKey(key))
445445
.getValue();
446446
}
447447

@@ -457,7 +457,7 @@ public Long pTtl(byte[] key, TimeUnit timeUnit) {
457457
return connection.getClusterCommandExecutor()
458458
.executeCommandOnSingleNode(
459459
(JedisClusterCommandCallback<Long>) client -> Converters.millisecondsToTimeUnit(client.pttl(key), timeUnit),
460-
connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key))
460+
connection.clusterGetNodeForKey(key))
461461
.getValue();
462462
}
463463

@@ -472,7 +472,7 @@ public byte[] dump(byte[] key) {
472472

473473
return connection.getClusterCommandExecutor()
474474
.executeCommandOnSingleNode((JedisClusterCommandCallback<byte[]>) client -> client.dump(key),
475-
connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key))
475+
connection.clusterGetNodeForKey(key))
476476
.getValue();
477477
}
478478

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

502-
}, connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key));
502+
}, connection.clusterGetNodeForKey(key));
503503
}
504504

505505
/*
@@ -582,7 +582,7 @@ public ValueEncoding encodingOf(byte[] key) {
582582

583583
return connection.getClusterCommandExecutor()
584584
.executeCommandOnSingleNode((JedisClusterCommandCallback<byte[]>) client -> client.objectEncoding(key),
585-
connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key))
585+
connection.clusterGetNodeForKey(key))
586586
.mapValue(JedisConverters::toEncoding);
587587
}
588588

@@ -598,7 +598,7 @@ public Duration idletime(byte[] key) {
598598

599599
return connection.getClusterCommandExecutor()
600600
.executeCommandOnSingleNode((JedisClusterCommandCallback<Long>) client -> client.objectIdletime(key),
601-
connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key))
601+
connection.clusterGetNodeForKey(key))
602602
.mapValue(Converters::secondsToDuration);
603603
}
604604

@@ -614,7 +614,7 @@ public Long refcount(byte[] key) {
614614

615615
return connection.getClusterCommandExecutor()
616616
.executeCommandOnSingleNode((JedisClusterCommandCallback<Long>) client -> client.objectRefcount(key),
617-
connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key))
617+
connection.clusterGetNodeForKey(key))
618618
.getValue();
619619

620620
}

0 commit comments

Comments
 (0)