Skip to content

Commit

Permalink
Support the command (#2920)
Browse files Browse the repository at this point in the history
  • Loading branch information
tishun authored Jul 29, 2024
1 parent dee8020 commit 666b4d7
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 12 deletions.
5 changes: 5 additions & 0 deletions src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,11 @@ public RedisFuture<String> clusterMyId() {
return dispatch(commandBuilder.clusterMyId());
}

@Override
public RedisFuture<String> clusterMyShardId() {
return dispatch(commandBuilder.clusterMyShardId());
}

@Override
public RedisFuture<String> clusterNodes() {
return dispatch(commandBuilder.clusterNodes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,11 @@ public Mono<String> clusterMyId() {
return createMono(commandBuilder::clusterMyId);
}

@Override
public Mono<String> clusterMyShardId() {
return createMono(commandBuilder::clusterMyShardId);
}

@Override
public Mono<String> clusterNodes() {
return createMono(commandBuilder::clusterNodes);
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/io/lettuce/core/RedisCommandBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,12 @@ Command<K, V, String> clusterMyId() {
return createCommand(CLUSTER, new StatusOutput<>(codec), args);
}

Command<K, V, String> clusterMyShardId() {
CommandArgs<K, V> args = new CommandArgs<>(codec).add(MYSHARDID);

return createCommand(CLUSTER, new StatusOutput<>(codec), args);
}

Command<K, V, String> clusterNodes() {
CommandArgs<K, V> args = new CommandArgs<>(codec).add(NODES);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,16 @@ public interface RedisClusterAsyncCommands<K, V> extends BaseRedisAsyncCommands<
*/
RedisFuture<String> clusterMyId();

/**
* Obtain the shard ID for the currently connected node.
* <p>
* 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<String> clusterMyShardId();

/**
* Obtain details about all cluster nodes. Can be parsed using
* {@link io.lettuce.core.cluster.models.partitions.ClusterPartitionParser#parse}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ public interface RedisClusterReactiveCommands<K, V> extends BaseRedisReactiveCom
*/
Mono<String> clusterMyId();

/**
* Obtain the shard ID for the currently connected node.
* <p>
* 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<String> clusterMyShardId();

/**
* Obtain details about all cluster nodes. Can be parsed using
* {@link io.lettuce.core.cluster.models.partitions.ClusterPartitionParser#parse}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,16 @@ public interface RedisClusterCommands<K, V> extends BaseRedisCommands<K, V>, Red
*/
String clusterMyId();

/**
* Obtain the shard ID for the currently connected node.
* <p>
* 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}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/lettuce/core/protocol/CommandType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions src/main/templates/io/lettuce/core/api/RedisHashCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions src/main/templates/io/lettuce/core/api/RedisKeyCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 2 additions & 8 deletions src/main/templates/io/lettuce/core/api/RedisStreamCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
11 changes: 11 additions & 0 deletions src/test/java/io/lettuce/core/RedisCommandBuilderUnitTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String, ?> 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");
}

}

0 comments on commit 666b4d7

Please sign in to comment.