Skip to content

Commit

Permalink
Add support for CLUSTER DELSLOTSRANGE and CLUSTER ADDSLOTSRANGE c…
Browse files Browse the repository at this point in the history
…ommands #1904

Original pull request: #1983.
  • Loading branch information
dengliming authored and mp911de committed Feb 28, 2022
1 parent 24b8a7a commit d210bfd
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,11 @@ public RedisFuture<String> clusterAddSlots(int... slots) {
return dispatch(commandBuilder.clusterAddslots(slots));
}

@Override
public RedisFuture<String> clusterAddSlotsRange(Range<Integer>... ranges) {
return dispatch(commandBuilder.clusterAddSlotsRange(ranges));
}

@Override
public RedisFuture<String> clusterBumpepoch() {
return dispatch(commandBuilder.clusterBumpepoch());
Expand All @@ -371,6 +376,11 @@ public RedisFuture<String> clusterDelSlots(int... slots) {
return dispatch(commandBuilder.clusterDelslots(slots));
}

@Override
public RedisFuture<String> clusterDelSlotsRange(Range<Integer>... ranges) {
return dispatch(commandBuilder.clusterDelSlotsRange(ranges));
}

@Override
public RedisFuture<String> clusterFailover(boolean force) {
return dispatch(commandBuilder.clusterFailover(force));
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,11 @@ public Mono<String> clusterAddSlots(int... slots) {
return createMono(() -> commandBuilder.clusterAddslots(slots));
}

@Override
public Mono<String> clusterAddSlotsRange(Range<Integer>... ranges) {
return createMono(() -> commandBuilder.clusterAddSlotsRange(ranges));
}

@Override
public Mono<String> clusterBumpepoch() {
return createMono(() -> commandBuilder.clusterBumpepoch());
Expand All @@ -391,6 +396,11 @@ public Mono<String> clusterDelSlots(int... slots) {
return createMono(() -> commandBuilder.clusterDelslots(slots));
}

@Override
public Mono<String> clusterDelSlotsRange(Range<Integer>... ranges) {
return createMono(() -> commandBuilder.clusterDelSlotsRange(ranges));
}

@Override
public Mono<String> clusterFailover(boolean force) {
return createMono(() -> commandBuilder.clusterFailover(force));
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/io/lettuce/core/RedisCommandBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,18 @@ Command<K, V, String> clusterAddslots(int[] slots) {
return createCommand(CLUSTER, new StatusOutput<>(codec), args);
}

Command<K, V, String> clusterAddSlotsRange(Range<Integer>... ranges) {
notEmptyRanges(ranges);

CommandArgs<K, V> args = new CommandArgs<>(codec).add(ADDSLOTSRANGE);

for (Range<Integer> range : ranges) {
args.add(range.getLower().getValue());
args.add(range.getUpper().getValue());
}
return createCommand(CLUSTER, new StatusOutput<>(codec), args);
}

Command<K, V, String> clusterBumpepoch() {
CommandArgs<K, V> args = new CommandArgs<>(codec).add(BUMPEPOCH);
return createCommand(CLUSTER, new StatusOutput<>(codec), args);
Expand Down Expand Up @@ -506,6 +518,18 @@ Command<K, V, String> clusterDelslots(int[] slots) {
return createCommand(CLUSTER, new StatusOutput<>(codec), args);
}

Command<K, V, String> clusterDelSlotsRange(Range<Integer>... ranges) {
notEmptyRanges(ranges);

CommandArgs<K, V> args = new CommandArgs<>(codec).add(DELSLOTSRANGE);

for (Range<Integer> range : ranges) {
args.add(range.getLower().getValue());
args.add(range.getUpper().getValue());
}
return createCommand(CLUSTER, new StatusOutput<>(codec), args);
}

Command<K, V, String> clusterFailover(boolean force) {

CommandArgs<K, V> args = new CommandArgs<>(codec).add(FAILOVER);
Expand Down Expand Up @@ -3982,4 +4006,7 @@ private static void notNullRange(Range<?> range) {
LettuceAssert.notNull(range, "Range " + MUST_NOT_BE_NULL);
}

private static void notEmptyRanges(Range<?>[] ranges) {
LettuceAssert.notEmpty(ranges, "Ranges " + MUST_NOT_BE_NULL);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Map;

import io.lettuce.core.KeyValue;
import io.lettuce.core.Range;
import io.lettuce.core.RedisFuture;
import io.lettuce.core.api.async.*;

Expand Down Expand Up @@ -105,6 +106,14 @@ public interface RedisClusterAsyncCommands<K, V> extends BaseRedisAsyncCommands<
*/
RedisFuture<Long> clusterCountKeysInSlot(int slot);

/**
* Takes a list of slot ranges (specified by start and end slots) to assign to the node.
*
* @param ranges a list of slot ranges (specified by start and end slots)
* @return String simple-string-reply
*/
RedisFuture<String> clusterAddSlotsRange(Range<Integer>... ranges);

/**
* Removes slots from the cluster node.
*
Expand All @@ -113,6 +122,14 @@ public interface RedisClusterAsyncCommands<K, V> extends BaseRedisAsyncCommands<
*/
RedisFuture<String> clusterDelSlots(int... slots);

/**
* Takes a list of slot ranges (specified by start and end slots) to remove to the node.
*
* @param ranges a list of slot ranges (specified by start and end slots)
* @return String simple-string-reply
*/
RedisFuture<String> clusterDelSlotsRange(Range<Integer>... ranges);

/**
* Failover a cluster node. Turns the currently connected node into a master and the master into its replica.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.time.Duration;
import java.util.Map;

import io.lettuce.core.Range;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import io.lettuce.core.KeyValue;
Expand Down Expand Up @@ -107,6 +108,14 @@ public interface RedisClusterReactiveCommands<K, V>
*/
Mono<Long> clusterCountKeysInSlot(int slot);

/**
* Takes a list of slot ranges (specified by start and end slots) to assign to the node.
*
* @param ranges a list of slot ranges (specified by start and end slots)
* @return String simple-string-reply
*/
Mono<String> clusterAddSlotsRange(Range<Integer>... ranges);

/**
* Removes slots from the cluster node.
*
Expand All @@ -115,6 +124,14 @@ public interface RedisClusterReactiveCommands<K, V>
*/
Mono<String> clusterDelSlots(int... slots);

/**
* Takes a list of slot ranges (specified by start and end slots) to remove to the node.
*
* @param ranges a list of slot ranges (specified by start and end slots)
* @return String simple-string-reply
*/
Mono<String> clusterDelSlotsRange(Range<Integer>... ranges);

/**
* Failover a cluster node. Turns the currently connected node into a master and the master into its replica.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.time.Duration;
import java.util.List;

import io.lettuce.core.Range;
import io.lettuce.core.api.sync.*;

/**
Expand Down Expand Up @@ -104,6 +105,14 @@ public interface RedisClusterCommands<K, V>
*/
Long clusterCountKeysInSlot(int slot);

/**
* Takes a list of slot ranges (specified by start and end slots) to assign to the node.
*
* @param ranges a list of slot ranges (specified by start and end slots)
* @return String simple-string-reply
*/
String clusterAddSlotsRange(Range<Integer>... ranges);

/**
* Removes slots from the cluster node.
*
Expand All @@ -112,6 +121,14 @@ public interface RedisClusterCommands<K, V>
*/
String clusterDelSlots(int... slots);

/**
* Takes a list of slot ranges (specified by start and end slots) to remove to the node.
*
* @param ranges a list of slot ranges (specified by start and end slots)
* @return String simple-string-reply
*/
String clusterDelSlotsRange(Range<Integer>... ranges);

/**
* Failover a cluster node. Turns the currently connected node into a master and the master into its replica.
*
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/lettuce/core/protocol/CommandKeyword.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
*/
public enum CommandKeyword implements ProtocolKeyword {

ABSTTL, ADDR, ADDSLOTS, AFTER, AGGREGATE, ALLCHANNELS, ALLCOMMANDS, ALLKEYS, ALPHA, AND, ASK, ASC, ASYNC, BEFORE, BLOCK, BUMPEPOCH,
ABSTTL, ADDR, ADDSLOTS, ADDSLOTSRANGE, AFTER, AGGREGATE, ALLCHANNELS, ALLCOMMANDS, ALLKEYS, ALPHA, AND, ASK, ASC, ASYNC, BEFORE, BLOCK, BUMPEPOCH,

BY, BYLEX, BYSCORE, CACHING, CAT, CH, CHANNELS, COPY, COUNT, COUNTKEYSINSLOT, CONSUMERS, CREATE, DB, DELSLOTS, DELUSER, DESC, SOFT, HARD, ENCODING,
BY, BYLEX, BYSCORE, CACHING, CAT, CH, CHANNELS, COPY, COUNT, COUNTKEYSINSLOT, CONSUMERS, CREATE, DB, DELSLOTS, DELSLOTSRANGE, DELUSER, DESC, SOFT, HARD, ENCODING,

FAILOVER, FORGET, FLUSH, FORCE, FREQ, FLUSHSLOTS, GENPASS, GETNAME, GETUSER, GETKEYSINSLOT, GETREDIR, GROUP, GROUPS, HTSTATS, ID, IDLE,

Expand Down
10 changes: 10 additions & 0 deletions src/test/java/io/lettuce/core/cluster/RedisClusterSetupTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@ public void clusterDelSlots() {
Wait.untilEquals(11996, () -> getOwnPartition(redis1).getSlots().size()).waitOrTimeout();
}

@Test
public void clusterDelSlotsRange() {

ClusterSetup.setup2Masters(clusterHelper);

redis1.clusterDelSlotsRange(Range.create(1, 4), Range.create(5, 6));

Wait.untilEquals(11994, () -> getOwnPartition(redis1).getSlots().size()).waitOrTimeout();
}

@Test
public void clusterSetSlots() {

Expand Down

0 comments on commit d210bfd

Please sign in to comment.