Skip to content

Commit c05da9e

Browse files
authored
Add support clusterlinks command (#2986)
* Add support clusterlinks command * Add test RedisCommandBuilderUnitTests
1 parent cf215de commit c05da9e

File tree

10 files changed

+82
-1
lines changed

10 files changed

+82
-1
lines changed

src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3189,6 +3189,11 @@ public RedisFuture<Long> zunionstore(K destination, ZStoreArgs zStoreArgs, K...
31893189
return dispatch(commandBuilder.zunionstore(destination, zStoreArgs, keys));
31903190
}
31913191

3192+
@Override
3193+
public RedisFuture<List<Map<String, Object>>> clusterLinks() {
3194+
return dispatch(commandBuilder.clusterLinks());
3195+
}
3196+
31923197
private byte[] encodeFunction(String functionCode) {
31933198
LettuceAssert.notNull(functionCode, "Function code must not be null");
31943199
LettuceAssert.notEmpty(functionCode, "Function code script must not be empty");

src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3257,6 +3257,11 @@ public Mono<Long> zunionstore(K destination, ZStoreArgs zStoreArgs, K... keys) {
32573257
return createMono(() -> commandBuilder.zunionstore(destination, zStoreArgs, keys));
32583258
}
32593259

3260+
@Override
3261+
public Mono<List<Map<String, Object>>> clusterLinks() {
3262+
return createMono(commandBuilder::clusterLinks);
3263+
}
3264+
32603265
private byte[] encodeFunction(String functionCode) {
32613266
LettuceAssert.notNull(functionCode, "Function code must not be null");
32623267
LettuceAssert.notEmpty(functionCode, "Function code script must not be empty");

src/main/java/io/lettuce/core/RedisCommandBuilder.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4433,6 +4433,11 @@ Command<K, V, Long> zunionstore(K destination, ZAggregateArgs aggregateArgs, K..
44334433
return createCommand(ZUNIONSTORE, new IntegerOutput<>(codec), args);
44344434
}
44354435

4436+
Command<K, V, List<Map<String, Object>>> clusterLinks() {
4437+
CommandArgs<K, V> args = new CommandArgs<>(codec).add(LINKS);
4438+
return createCommand(CLUSTER, (CommandOutput) new ObjectOutput<>(StringCodec.UTF8), args);
4439+
}
4440+
44364441
private boolean allElementsInstanceOf(Object[] objects, Class<?> expectedAssignableType) {
44374442

44384443
for (Object object : objects) {

src/main/java/io/lettuce/core/cluster/api/async/RedisClusterAsyncCommands.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,4 +380,11 @@ public interface RedisClusterAsyncCommands<K, V> extends BaseRedisAsyncCommands<
380380
*/
381381
RedisFuture<String> readWrite();
382382

383+
/**
384+
* Retrieves information about the TCP links between nodes in a Redis Cluster.
385+
*
386+
* @return List of maps containing attributes and values for each peer link.
387+
*/
388+
RedisFuture<List<Map<String, Object>>> clusterLinks();
389+
383390
}

src/main/java/io/lettuce/core/cluster/api/reactive/RedisClusterReactiveCommands.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import java.time.Duration;
2323
import java.util.List;
24+
import java.util.Map;
2425

2526
import io.lettuce.core.Range;
2627
import io.lettuce.core.api.reactive.*;
@@ -368,4 +369,11 @@ public interface RedisClusterReactiveCommands<K, V> extends BaseRedisReactiveCom
368369
*/
369370
Mono<String> readWrite();
370371

372+
/**
373+
* Retrieves information about the TCP links between nodes in a Redis Cluster.
374+
*
375+
* @return List of maps containing attributes and values for each peer link.
376+
*/
377+
Mono<List<Map<String, Object>>> clusterLinks();
378+
371379
}

src/main/java/io/lettuce/core/cluster/api/sync/RedisClusterCommands.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import java.time.Duration;
2323
import java.util.List;
24+
import java.util.Map;
2425

2526
import io.lettuce.core.Range;
2627
import io.lettuce.core.api.sync.*;
@@ -368,4 +369,11 @@ public interface RedisClusterCommands<K, V> extends BaseRedisCommands<K, V>, Red
368369
@Override
369370
String readWrite();
370371

372+
/**
373+
* Retrieves information about the TCP links between nodes in a Redis Cluster.
374+
*
375+
* @return List of maps containing attributes and values for each peer link.
376+
*/
377+
List<Map<String, Object>> clusterLinks();
378+
371379
}

src/main/java/io/lettuce/core/protocol/CommandKeyword.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public enum CommandKeyword implements ProtocolKeyword {
3939

4040
FAILOVER, FORGET, FIELDS, FLAGS, FLUSH, FORCE, FREQ, FLUSHSLOTS, GENPASS, GETNAME, GETUSER, GETKEYSINSLOT, GETREDIR, GROUP, GROUPS, HTSTATS, ID, IDLE, INFO,
4141

42-
IDLETIME, JUSTID, KILL, KEYSLOT, LEFT, LEN, LIMIT, LIST, LOAD, LOG, MATCH,
42+
IDLETIME, JUSTID, KILL, KEYSLOT, LEFT, LEN, LIMIT, LINKS, LIST, LOAD, LOG, MATCH,
4343

4444
MAX, MAXLEN, MEET, MIN, MINID, MOVED, NO, NOACK, NOCOMMANDS, NODE, NODES, NOMKSTREAM, NOPASS, NOSAVE, NOT, NOVALUES, NUMSUB, SHARDCHANNELS, SHARDNUMSUB, NUMPAT, NX, OFF, ON, ONE, OR, PAUSE, PREFIXES,
4545

src/test/java/io/lettuce/core/RedisCommandBuilderUnitTests.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import org.junit.jupiter.api.Test;
88

99
import java.nio.charset.StandardCharsets;
10+
import java.util.List;
11+
import java.util.Map;
1012

1113
import static org.assertj.core.api.Assertions.assertThat;
1214

@@ -168,4 +170,14 @@ void shouldCorrectlyConstructClusterMyshardid() {
168170
.isEqualTo("*2\r\n" + "$7\r\n" + "CLUSTER\r\n" + "$9\r\n" + "MYSHARDID\r\n");
169171
}
170172

173+
@Test
174+
void shouldCorrectlyConstructClusterLinks() {
175+
176+
Command<String, String, List<Map<String, Object>>> command = sut.clusterLinks();
177+
ByteBuf buf = Unpooled.directBuffer();
178+
command.encode(buf);
179+
180+
assertThat(buf.toString(StandardCharsets.UTF_8)).isEqualTo("*2\r\n$7\r\nCLUSTER\r\n$5\r\nLINKS\r\n");
181+
}
182+
171183
}

src/test/java/io/lettuce/core/cluster/ClusterCommandIntegrationTests.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import java.time.Duration;
77
import java.util.List;
8+
import java.util.Map;
89

910
import javax.inject.Inject;
1011

@@ -271,6 +272,26 @@ void clusterReplicas() {
271272
assertThat(result.size()).isGreaterThan(0);
272273
}
273274

275+
@Test
276+
void testClusterLinks() {
277+
List<Map<String, Object>> values = sync.clusterLinks();
278+
assertThat(values).isNotEmpty();
279+
for (Map<String, Object> value : values) {
280+
assertThat(value).containsKeys("direction", "node", "create-time", "events", "send-buffer-allocated",
281+
"send-buffer-used");
282+
}
283+
}
284+
285+
@Test
286+
void testClusterLinksAsync() throws Exception {
287+
RedisFuture<List<Map<String, Object>>> futureLinks = async.clusterLinks();
288+
List<Map<String, Object>> values = futureLinks.get();
289+
for (Map<String, Object> value : values) {
290+
assertThat(value).containsKeys("direction", "node", "create-time", "events", "send-buffer-allocated",
291+
"send-buffer-used");
292+
}
293+
}
294+
274295
private void prepareReadonlyTest(String key) {
275296

276297
async.set(key, value);

src/test/java/io/lettuce/core/cluster/ClusterReactiveCommandIntegrationTests.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static org.assertj.core.api.Assertions.assertThat;
44

55
import java.util.List;
6+
import java.util.Map;
67

78
import javax.inject.Inject;
89

@@ -97,4 +98,13 @@ void clusterSlaves() {
9798
assertThat(result.size()).isGreaterThan(0);
9899
}
99100

101+
@Test
102+
void testClusterLinks() {
103+
List<Map<String, Object>> values = reactive.clusterLinks().block();
104+
for (Map<String, Object> value : values) {
105+
assertThat(value).containsKeys("direction", "node", "create-time", "events", "send-buffer-allocated",
106+
"send-buffer-used");
107+
}
108+
}
109+
100110
}

0 commit comments

Comments
 (0)