Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support clusterlinks command #2986

Merged
merged 2 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {
tishun marked this conversation as resolved.
Show resolved Hide resolved
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
12 changes: 12 additions & 0 deletions src/test/java/io/lettuce/core/RedisCommandBuilderUnitTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.junit.jupiter.api.Test;

import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;

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

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

@Test
void shouldCorrectlyConstructClusterLinks() {

Command<String, String, List<Map<String, Object>>> command = sut.clusterLinks();
ByteBuf buf = Unpooled.directBuffer();
command.encode(buf);

assertThat(buf.toString(StandardCharsets.UTF_8)).isEqualTo("*2\r\n$7\r\nCLUSTER\r\n$5\r\nLINKS\r\n");
}

}
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");
}
}

}
Loading