diff --git a/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java b/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java index b7da8fb2fd..3c891850c0 100644 --- a/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java +++ b/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java @@ -474,6 +474,11 @@ public RedisFuture clusterMyId() { return dispatch(commandBuilder.clusterMyId()); } + @Override + public RedisFuture clusterMyShardId() { + return dispatch(commandBuilder.clusterMyShardId()); + } + @Override public RedisFuture clusterNodes() { return dispatch(commandBuilder.clusterNodes()); diff --git a/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java b/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java index 38404c1ea4..25c4cc66f7 100644 --- a/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java +++ b/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java @@ -496,6 +496,11 @@ public Mono clusterMyId() { return createMono(commandBuilder::clusterMyId); } + @Override + public Mono clusterMyShardId() { + return createMono(commandBuilder::clusterMyShardId); + } + @Override public Mono clusterNodes() { return createMono(commandBuilder::clusterNodes); diff --git a/src/main/java/io/lettuce/core/RedisCommandBuilder.java b/src/main/java/io/lettuce/core/RedisCommandBuilder.java index 1a5e4d1645..939929494d 100644 --- a/src/main/java/io/lettuce/core/RedisCommandBuilder.java +++ b/src/main/java/io/lettuce/core/RedisCommandBuilder.java @@ -656,6 +656,12 @@ Command clusterMyId() { return createCommand(CLUSTER, new StatusOutput<>(codec), args); } + Command clusterMyShardId() { + CommandArgs args = new CommandArgs<>(codec).add(MYSHARDID); + + return createCommand(CLUSTER, new StatusOutput<>(codec), args); + } + Command clusterNodes() { CommandArgs args = new CommandArgs<>(codec).add(NODES); diff --git a/src/main/java/io/lettuce/core/cluster/api/async/RedisClusterAsyncCommands.java b/src/main/java/io/lettuce/core/cluster/api/async/RedisClusterAsyncCommands.java index 6a9c81ade5..2835968fd0 100644 --- a/src/main/java/io/lettuce/core/cluster/api/async/RedisClusterAsyncCommands.java +++ b/src/main/java/io/lettuce/core/cluster/api/async/RedisClusterAsyncCommands.java @@ -217,6 +217,16 @@ public interface RedisClusterAsyncCommands extends BaseRedisAsyncCommands< */ RedisFuture clusterMyId(); + /** + * Obtain the shard ID for the currently connected node. + *

+ * The CLUSTER MYSHARDID command returns the unique, auto-generated identifier that is associated with the shard to which + * the connected cluster node belongs. + * + * @return String simple-string-reply + */ + RedisFuture clusterMyShardId(); + /** * Obtain details about all cluster nodes. Can be parsed using * {@link io.lettuce.core.cluster.models.partitions.ClusterPartitionParser#parse} diff --git a/src/main/java/io/lettuce/core/cluster/api/reactive/RedisClusterReactiveCommands.java b/src/main/java/io/lettuce/core/cluster/api/reactive/RedisClusterReactiveCommands.java index d7e3a9757c..5f1d611f90 100644 --- a/src/main/java/io/lettuce/core/cluster/api/reactive/RedisClusterReactiveCommands.java +++ b/src/main/java/io/lettuce/core/cluster/api/reactive/RedisClusterReactiveCommands.java @@ -216,6 +216,16 @@ public interface RedisClusterReactiveCommands extends BaseRedisReactiveCom */ Mono clusterMyId(); + /** + * Obtain the shard ID for the currently connected node. + *

+ * The CLUSTER MYSHARDID command returns the unique, auto-generated identifier that is associated with the shard to which + * the connected cluster node belongs. + * + * @return String simple-string-reply + */ + Mono clusterMyShardId(); + /** * Obtain details about all cluster nodes. Can be parsed using * {@link io.lettuce.core.cluster.models.partitions.ClusterPartitionParser#parse} diff --git a/src/main/java/io/lettuce/core/cluster/api/sync/RedisClusterCommands.java b/src/main/java/io/lettuce/core/cluster/api/sync/RedisClusterCommands.java index 597ec53d75..2e18bc68da 100644 --- a/src/main/java/io/lettuce/core/cluster/api/sync/RedisClusterCommands.java +++ b/src/main/java/io/lettuce/core/cluster/api/sync/RedisClusterCommands.java @@ -214,6 +214,16 @@ public interface RedisClusterCommands extends BaseRedisCommands, Red */ String clusterMyId(); + /** + * Obtain the shard ID for the currently connected node. + *

+ * The CLUSTER MYSHARDID command returns the unique, auto-generated identifier that is associated with the shard to which + * the connected cluster node belongs. + * + * @return String simple-string-reply + */ + String clusterMyShardId(); + /** * Obtain details about all cluster nodes. Can be parsed using * {@link io.lettuce.core.cluster.models.partitions.ClusterPartitionParser#parse} diff --git a/src/main/java/io/lettuce/core/protocol/CommandType.java b/src/main/java/io/lettuce/core/protocol/CommandType.java index 427ce80184..4a44d6087e 100644 --- a/src/main/java/io/lettuce/core/protocol/CommandType.java +++ b/src/main/java/io/lettuce/core/protocol/CommandType.java @@ -42,7 +42,7 @@ public enum CommandType implements ProtocolKeyword { // Server - BGREWRITEAOF, BGSAVE, CLIENT, COMMAND, CONFIG, DBSIZE, DEBUG, FLUSHALL, FLUSHDB, INFO, MYID, LASTSAVE, REPLICAOF, ROLE, MONITOR, SAVE, SHUTDOWN, SLAVEOF, SLOWLOG, SYNC, MEMORY, + BGREWRITEAOF, BGSAVE, CLIENT, COMMAND, CONFIG, DBSIZE, DEBUG, FLUSHALL, FLUSHDB, INFO, MYID, MYSHARDID, LASTSAVE, REPLICAOF, ROLE, MONITOR, SAVE, SHUTDOWN, SLAVEOF, SLOWLOG, SYNC, MEMORY, // Keys diff --git a/src/main/templates/io/lettuce/core/api/RedisHashCommands.java b/src/main/templates/io/lettuce/core/api/RedisHashCommands.java index ac05591741..461563ad6a 100644 --- a/src/main/templates/io/lettuce/core/api/RedisHashCommands.java +++ b/src/main/templates/io/lettuce/core/api/RedisHashCommands.java @@ -19,9 +19,13 @@ */ package io.lettuce.core.api; +import java.time.Duration; +import java.time.Instant; +import java.util.Date; import java.util.List; import java.util.Map; +import io.lettuce.core.ExpireArgs; import io.lettuce.core.KeyScanCursor; import io.lettuce.core.KeyValue; import io.lettuce.core.MapScanCursor; diff --git a/src/main/templates/io/lettuce/core/api/RedisKeyCommands.java b/src/main/templates/io/lettuce/core/api/RedisKeyCommands.java index 602b0442ad..0357998dbb 100644 --- a/src/main/templates/io/lettuce/core/api/RedisKeyCommands.java +++ b/src/main/templates/io/lettuce/core/api/RedisKeyCommands.java @@ -24,9 +24,7 @@ import java.util.Date; import java.util.List; -import io.lettuce.core.ExpireArgs; -import io.lettuce.core.KeyScanArgs; -import io.lettuce.core.RestoreArgs; +import io.lettuce.core.*; import io.lettuce.core.output.KeyStreamingChannel; import io.lettuce.core.output.ValueStreamingChannel; diff --git a/src/main/templates/io/lettuce/core/api/RedisStreamCommands.java b/src/main/templates/io/lettuce/core/api/RedisStreamCommands.java index 232f1f618c..954216a544 100644 --- a/src/main/templates/io/lettuce/core/api/RedisStreamCommands.java +++ b/src/main/templates/io/lettuce/core/api/RedisStreamCommands.java @@ -22,15 +22,9 @@ import java.util.List; import java.util.Map; -import io.lettuce.core.Consumer; -import io.lettuce.core.Limit; -import io.lettuce.core.Range; -import io.lettuce.core.StreamMessage; -import io.lettuce.core.XAddArgs; -import io.lettuce.core.XGroupCreateArgs; -import io.lettuce.core.XReadArgs; -import io.lettuce.core.XClaimArgs; +import io.lettuce.core.*; import io.lettuce.core.XReadArgs.StreamOffset; +import io.lettuce.core.models.stream.ClaimedMessages; import io.lettuce.core.models.stream.PendingMessage; import io.lettuce.core.models.stream.PendingMessages; diff --git a/src/test/java/io/lettuce/core/RedisCommandBuilderUnitTests.java b/src/test/java/io/lettuce/core/RedisCommandBuilderUnitTests.java index 5e6eba1939..1657e70293 100644 --- a/src/test/java/io/lettuce/core/RedisCommandBuilderUnitTests.java +++ b/src/test/java/io/lettuce/core/RedisCommandBuilderUnitTests.java @@ -146,4 +146,15 @@ void shouldCorrectlyConstructHpttl() { + "3\r\n" + "$7\r\n" + "hField1\r\n" + "$7\r\n" + "hField2\r\n" + "$7\r\n" + "hField3\r\n"); } + @Test + void shouldCorrectlyConstructClusterMyshardid() { + + Command command = sut.clusterMyShardId(); + ByteBuf buf = Unpooled.directBuffer(); + command.encode(buf); + + assertThat(buf.toString(StandardCharsets.UTF_8)) + .isEqualTo("*2\r\n" + "$7\r\n" + "CLUSTER\r\n" + "$9\r\n" + "MYSHARDID\r\n"); + } + }