From 1e0e27d1258ec3171e94a14074d3a9c73474e3ca Mon Sep 17 00:00:00 2001 From: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> Date: Thu, 18 May 2023 17:54:00 +0600 Subject: [PATCH] Add CLUSTER MYSHARDID command and update CLUSTER BUMPEPOCH command and other tests --- pom.xml | 4 ++-- src/main/java/redis/clients/jedis/Jedis.java | 9 ++++++++- src/main/java/redis/clients/jedis/Protocol.java | 3 ++- .../clients/jedis/commands/ClusterCommands.java | 2 ++ .../jedis/commands/jedis/ClusterCommandsTest.java | 15 ++++++++++++++- 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index cfff50b453..78e10c3374 100644 --- a/pom.xml +++ b/pom.xml @@ -80,8 +80,8 @@ org.hamcrest - hamcrest-library - 1.3 + hamcrest + 2.2 test diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index d9ba05fc59..a0ee4ac7c3 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -8827,7 +8827,7 @@ public String clusterSetConfigEpoch(long configEpoch) { public String clusterBumpEpoch() { checkIsInMultiOrPipeline(); connection.sendCommand(CLUSTER, ClusterKeyword.BUMPEPOCH); - return connection.getStatusCodeReply(); + return connection.getBulkReply(); } @Override @@ -8880,6 +8880,13 @@ public String clusterMyId() { return connection.getBulkReply(); } + @Override + public String clusterMyShardId() { + checkIsInMultiOrPipeline(); + connection.sendCommand(CLUSTER, ClusterKeyword.MYSHARDID); + return connection.getBulkReply(); + } + @Override public List> clusterLinks() { checkIsInMultiOrPipeline(); diff --git a/src/main/java/redis/clients/jedis/Protocol.java b/src/main/java/redis/clients/jedis/Protocol.java index 4ea8bcd0f3..9bcfd5700a 100644 --- a/src/main/java/redis/clients/jedis/Protocol.java +++ b/src/main/java/redis/clients/jedis/Protocol.java @@ -319,7 +319,8 @@ public static enum ClusterKeyword implements Rawable { MEET, RESET, INFO, FAILOVER, SLOTS, NODES, REPLICAS, SLAVES, MYID, ADDSLOTS, DELSLOTS, GETKEYSINSLOT, SETSLOT, NODE, MIGRATING, IMPORTING, STABLE, FORGET, FLUSHSLOTS, KEYSLOT, - COUNTKEYSINSLOT, SAVECONFIG, REPLICATE, LINKS, ADDSLOTSRANGE, DELSLOTSRANGE, BUMPEPOCH; + COUNTKEYSINSLOT, SAVECONFIG, REPLICATE, LINKS, ADDSLOTSRANGE, DELSLOTSRANGE, BUMPEPOCH, + MYSHARDID; private final byte[] raw; diff --git a/src/main/java/redis/clients/jedis/commands/ClusterCommands.java b/src/main/java/redis/clients/jedis/commands/ClusterCommands.java index 8fdf5d7335..7a052146eb 100644 --- a/src/main/java/redis/clients/jedis/commands/ClusterCommands.java +++ b/src/main/java/redis/clients/jedis/commands/ClusterCommands.java @@ -93,6 +93,8 @@ public interface ClusterCommands { String clusterMyId(); + String clusterMyShardId(); + /** * return the information of all such peer links as an array, where each array element is a map that contains * attributes and their values for an individual link. diff --git a/src/test/java/redis/clients/jedis/commands/jedis/ClusterCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/ClusterCommandsTest.java index f0bf0bd310..a6654b47ca 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/ClusterCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/ClusterCommandsTest.java @@ -7,6 +7,9 @@ import java.util.List; import java.util.Map; + +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; @@ -211,6 +214,16 @@ public void clusterCountFailureReports() { assertEquals(0, node1.clusterCountFailureReports(node1.clusterMyId())); } + @Test + public void clusterMyId() { + MatcherAssert.assertThat(node1.clusterMyId(), Matchers.not(Matchers.isEmptyOrNullString())); + } + + @Test + public void clusterMyShardId() { + MatcherAssert.assertThat(node1.clusterMyShardId(), Matchers.not(Matchers.isEmptyOrNullString())); + } + @Test public void testClusterEpoch() { try { @@ -222,7 +235,7 @@ public void testClusterEpoch() { @Test public void ClusterBumpEpoch() { - node1.clusterBumpEpoch(); + MatcherAssert.assertThat(node1.clusterBumpEpoch(), Matchers.matchesPattern("^BUMPED|STILL [0-9]+$")); } } \ No newline at end of file