Skip to content

Commit 1da7591

Browse files
authored
Add CLUSTER MYSHARDID command (#3423)
and update CLUSTER BUMPEPOCH command and other tests
1 parent c0554f6 commit 1da7591

File tree

5 files changed

+28
-5
lines changed

5 files changed

+28
-5
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@
8080
</dependency>
8181
<dependency>
8282
<groupId>org.hamcrest</groupId>
83-
<artifactId>hamcrest-library</artifactId>
84-
<version>1.3</version>
83+
<artifactId>hamcrest</artifactId>
84+
<version>2.2</version>
8585
<scope>test</scope>
8686
</dependency>
8787
<dependency>

src/main/java/redis/clients/jedis/Jedis.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8827,7 +8827,7 @@ public String clusterSetConfigEpoch(long configEpoch) {
88278827
public String clusterBumpEpoch() {
88288828
checkIsInMultiOrPipeline();
88298829
connection.sendCommand(CLUSTER, ClusterKeyword.BUMPEPOCH);
8830-
return connection.getStatusCodeReply();
8830+
return connection.getBulkReply();
88318831
}
88328832

88338833
@Override
@@ -8880,6 +8880,13 @@ public String clusterMyId() {
88808880
return connection.getBulkReply();
88818881
}
88828882

8883+
@Override
8884+
public String clusterMyShardId() {
8885+
checkIsInMultiOrPipeline();
8886+
connection.sendCommand(CLUSTER, ClusterKeyword.MYSHARDID);
8887+
return connection.getBulkReply();
8888+
}
8889+
88838890
@Override
88848891
public List<Map<String, Object>> clusterLinks() {
88858892
checkIsInMultiOrPipeline();

src/main/java/redis/clients/jedis/Protocol.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,8 @@ public static enum ClusterKeyword implements Rawable {
319319

320320
MEET, RESET, INFO, FAILOVER, SLOTS, NODES, REPLICAS, SLAVES, MYID, ADDSLOTS, DELSLOTS,
321321
GETKEYSINSLOT, SETSLOT, NODE, MIGRATING, IMPORTING, STABLE, FORGET, FLUSHSLOTS, KEYSLOT,
322-
COUNTKEYSINSLOT, SAVECONFIG, REPLICATE, LINKS, ADDSLOTSRANGE, DELSLOTSRANGE, BUMPEPOCH;
322+
COUNTKEYSINSLOT, SAVECONFIG, REPLICATE, LINKS, ADDSLOTSRANGE, DELSLOTSRANGE, BUMPEPOCH,
323+
MYSHARDID;
323324

324325
private final byte[] raw;
325326

src/main/java/redis/clients/jedis/commands/ClusterCommands.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ public interface ClusterCommands {
9393

9494
String clusterMyId();
9595

96+
String clusterMyShardId();
97+
9698
/**
9799
* return the information of all such peer links as an array, where each array element is a map that contains
98100
* attributes and their values for an individual link.

src/test/java/redis/clients/jedis/commands/jedis/ClusterCommandsTest.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
import java.util.List;
99
import java.util.Map;
10+
11+
import org.hamcrest.MatcherAssert;
12+
import org.hamcrest.Matchers;
1013
import org.junit.After;
1114
import org.junit.AfterClass;
1215
import org.junit.Before;
@@ -211,6 +214,16 @@ public void clusterCountFailureReports() {
211214
assertEquals(0, node1.clusterCountFailureReports(node1.clusterMyId()));
212215
}
213216

217+
@Test
218+
public void clusterMyId() {
219+
MatcherAssert.assertThat(node1.clusterMyId(), Matchers.not(Matchers.isEmptyOrNullString()));
220+
}
221+
222+
@Test
223+
public void clusterMyShardId() {
224+
MatcherAssert.assertThat(node1.clusterMyShardId(), Matchers.not(Matchers.isEmptyOrNullString()));
225+
}
226+
214227
@Test
215228
public void testClusterEpoch() {
216229
try {
@@ -222,7 +235,7 @@ public void testClusterEpoch() {
222235

223236
@Test
224237
public void ClusterBumpEpoch() {
225-
node1.clusterBumpEpoch();
238+
MatcherAssert.assertThat(node1.clusterBumpEpoch(), Matchers.matchesPattern("^BUMPED|STILL [0-9]+$"));
226239
}
227240

228241
}

0 commit comments

Comments
 (0)