Skip to content

Commit

Permalink
Add support clusterlinks command
Browse files Browse the repository at this point in the history
  • Loading branch information
thachlp committed Sep 13, 2024
1 parent bfbb85f commit b5de5b5
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 1 deletion.
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 @@ -3189,6 +3189,11 @@ public RedisFuture<Long> zunionstore(K destination, ZStoreArgs zStoreArgs, K...
return dispatch(commandBuilder.zunionstore(destination, zStoreArgs, keys));
}

@Override
public RedisFuture<List<Map<String, Object>>> clusterLinks() {
return dispatch(commandBuilder.clusterLinks());
}

private byte[] encodeFunction(String functionCode) {
LettuceAssert.notNull(functionCode, "Function code must not be null");
LettuceAssert.notEmpty(functionCode, "Function code script must not be empty");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3257,6 +3257,11 @@ public Mono<Long> zunionstore(K destination, ZStoreArgs zStoreArgs, K... keys) {
return createMono(() -> commandBuilder.zunionstore(destination, zStoreArgs, keys));
}

@Override
public Mono<List<Map<String, Object>>> clusterLinks() {
return createMono(commandBuilder::clusterLinks);
}

private byte[] encodeFunction(String functionCode) {
LettuceAssert.notNull(functionCode, "Function code must not be null");
LettuceAssert.notEmpty(functionCode, "Function code script must not be empty");
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/io/lettuce/core/RedisCommandBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -4433,6 +4433,11 @@ Command<K, V, Long> zunionstore(K destination, ZAggregateArgs aggregateArgs, K..
return createCommand(ZUNIONSTORE, new IntegerOutput<>(codec), args);
}

Command<K, V, List<Map<String, Object>>> clusterLinks() {
CommandArgs<K, V> args = new CommandArgs<>(codec).add(LINKS);
return createCommand(CLUSTER, (CommandOutput) new ObjectOutput<>(StringCodec.UTF8), args);
}

private boolean allElementsInstanceOf(Object[] objects, Class<?> expectedAssignableType) {

for (Object object : objects) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,4 +380,11 @@ public interface RedisClusterAsyncCommands<K, V> extends BaseRedisAsyncCommands<
*/
RedisFuture<String> readWrite();

/**
* Retrieves information about the TCP links between nodes in a Redis Cluster.
*
* @return List of maps containing attributes and values for each peer link.
*/
RedisFuture<List<Map<String, Object>>> clusterLinks();

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.time.Duration;
import java.util.List;
import java.util.Map;

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

/**
* Retrieves information about the TCP links between nodes in a Redis Cluster.
*
* @return List of maps containing attributes and values for each peer link.
*/
Mono<List<Map<String, Object>>> clusterLinks();

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.time.Duration;
import java.util.List;
import java.util.Map;

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

/**
* Retrieves information about the TCP links between nodes in a Redis Cluster.
*
* @return List of maps containing attributes and values for each peer link.
*/
List<Map<String, Object>> clusterLinks();

}
2 changes: 1 addition & 1 deletion src/main/java/io/lettuce/core/protocol/CommandKeyword.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public enum CommandKeyword implements ProtocolKeyword {

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

IDLETIME, JUSTID, KILL, KEYSLOT, LEFT, LEN, LIMIT, LIST, LOAD, LOG, MATCH,
IDLETIME, JUSTID, KILL, KEYSLOT, LEFT, LEN, LIMIT, LINKS, LIST, LOAD, LOG, MATCH,

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,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.time.Duration;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

Expand Down Expand Up @@ -271,6 +272,26 @@ void clusterReplicas() {
assertThat(result.size()).isGreaterThan(0);
}

@Test
void testClusterLinks() {
List<Map<String, Object>> values = sync.clusterLinks();
assertThat(values).isNotEmpty();
for (Map<String, Object> value : values) {
assertThat(value).containsKeys("direction", "node", "create-time", "events", "send-buffer-allocated",
"send-buffer-used");
}
}

@Test
void testClusterLinksAsync() throws Exception {
RedisFuture<List<Map<String, Object>>> futureLinks = async.clusterLinks();
List<Map<String, Object>> values = futureLinks.get();
for (Map<String, Object> value : values) {
assertThat(value).containsKeys("direction", "node", "create-time", "events", "send-buffer-allocated",
"send-buffer-used");
}
}

private void prepareReadonlyTest(String key) {

async.set(key, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.assertj.core.api.Assertions.assertThat;

import java.util.List;
import java.util.Map;

import javax.inject.Inject;

Expand Down Expand Up @@ -97,4 +98,13 @@ void clusterSlaves() {
assertThat(result.size()).isGreaterThan(0);
}

@Test
void testClusterLinks() {
List<Map<String, Object>> values = reactive.clusterLinks().block();
for (Map<String, Object> value : values) {
assertThat(value).containsKeys("direction", "node", "create-time", "events", "send-buffer-allocated",
"send-buffer-used");
}
}

}

0 comments on commit b5de5b5

Please sign in to comment.