From 1e25abf8ed296eadc1e7e656e275c67fe76c7bb5 Mon Sep 17 00:00:00 2001 From: dengliming Date: Fri, 14 Feb 2020 23:41:45 +0800 Subject: [PATCH] Add support for client id command #1197 Original pull request: #1230. --- .../java/io/lettuce/core/AbstractRedisAsyncCommands.java | 5 +++++ .../io/lettuce/core/AbstractRedisReactiveCommands.java | 5 +++++ src/main/java/io/lettuce/core/RedisCommandBuilder.java | 5 +++++ .../lettuce/core/api/async/RedisServerAsyncCommands.java | 7 +++++++ .../core/api/reactive/RedisServerReactiveCommands.java | 7 +++++++ .../java/io/lettuce/core/api/sync/RedisServerCommands.java | 7 +++++++ .../api/async/NodeSelectionServerAsyncCommands.java | 7 +++++++ .../core/cluster/api/sync/NodeSelectionServerCommands.java | 7 +++++++ .../templates/io/lettuce/core/api/RedisServerCommands.java | 7 +++++++ .../core/commands/ServerCommandIntegrationTests.java | 5 +++++ 10 files changed, 62 insertions(+) diff --git a/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java b/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java index bfd0c04140..116634f049 100644 --- a/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java +++ b/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java @@ -181,6 +181,11 @@ public RedisFuture clientList() { return dispatch(commandBuilder.clientList()); } + @Override + public RedisFuture clientId() { + return dispatch(commandBuilder.clientId()); + } + @Override public RedisFuture clientPause(long timeout) { return dispatch(commandBuilder.clientPause(timeout)); diff --git a/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java b/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java index 9ecac1cfd1..687477e81c 100644 --- a/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java +++ b/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java @@ -205,6 +205,11 @@ public Mono clientList() { return createMono(commandBuilder::clientList); } + @Override + public Mono clientId() { + return createMono(commandBuilder::clientId); + } + @Override public Mono clientPause(long timeout) { return createMono(() -> commandBuilder.clientPause(timeout)); diff --git a/src/main/java/io/lettuce/core/RedisCommandBuilder.java b/src/main/java/io/lettuce/core/RedisCommandBuilder.java index 46431fbb2c..6256b45fda 100644 --- a/src/main/java/io/lettuce/core/RedisCommandBuilder.java +++ b/src/main/java/io/lettuce/core/RedisCommandBuilder.java @@ -234,6 +234,11 @@ Command clientList() { return createCommand(CLIENT, new StatusOutput<>(codec), args); } + Command clientId() { + CommandArgs args = new CommandArgs<>(codec).add(ID); + return createCommand(CLIENT, new IntegerOutput<>(codec), args); + } + Command clientPause(long timeout) { CommandArgs args = new CommandArgs<>(codec).add(PAUSE).add(timeout); return createCommand(CLIENT, new StatusOutput<>(codec), args); diff --git a/src/main/java/io/lettuce/core/api/async/RedisServerAsyncCommands.java b/src/main/java/io/lettuce/core/api/async/RedisServerAsyncCommands.java index a1517f923b..7b26e6a436 100644 --- a/src/main/java/io/lettuce/core/api/async/RedisServerAsyncCommands.java +++ b/src/main/java/io/lettuce/core/api/async/RedisServerAsyncCommands.java @@ -106,6 +106,13 @@ public interface RedisServerAsyncCommands { */ RedisFuture clientList(); + /** + * Get the id of the current connection. + * + * @return Long The command just returns the ID of the current connection. Every connection ID has certain guarantees + */ + RedisFuture clientId(); + /** * Returns an array reply of details about all Redis commands. * diff --git a/src/main/java/io/lettuce/core/api/reactive/RedisServerReactiveCommands.java b/src/main/java/io/lettuce/core/api/reactive/RedisServerReactiveCommands.java index d83c9794ff..3a07478043 100644 --- a/src/main/java/io/lettuce/core/api/reactive/RedisServerReactiveCommands.java +++ b/src/main/java/io/lettuce/core/api/reactive/RedisServerReactiveCommands.java @@ -106,6 +106,13 @@ public interface RedisServerReactiveCommands { */ Mono clientList(); + /** + * Get the id of the current connection. + * + * @return Long The command just returns the ID of the current connection. Every connection ID has certain guarantees + */ + Mono clientId(); + /** * Returns an array reply of details about all Redis commands. * diff --git a/src/main/java/io/lettuce/core/api/sync/RedisServerCommands.java b/src/main/java/io/lettuce/core/api/sync/RedisServerCommands.java index fb06b490f1..8c44ff6367 100644 --- a/src/main/java/io/lettuce/core/api/sync/RedisServerCommands.java +++ b/src/main/java/io/lettuce/core/api/sync/RedisServerCommands.java @@ -105,6 +105,13 @@ public interface RedisServerCommands { */ String clientList(); + /** + * Get the id of the current connection. + * + * @return Long The command just returns the ID of the current connection. Every connection ID has certain guarantees + */ + Long clientId(); + /** * Returns an array reply of details about all Redis commands. * diff --git a/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionServerAsyncCommands.java b/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionServerAsyncCommands.java index c7ab0bb2eb..466c474760 100644 --- a/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionServerAsyncCommands.java +++ b/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionServerAsyncCommands.java @@ -105,6 +105,13 @@ public interface NodeSelectionServerAsyncCommands { */ AsyncExecutions clientList(); + /** + * Get the id of the current connection. + * + * @return Long The command just returns the ID of the current connection. Every connection ID has certain guarantees + */ + AsyncExecutions clientId(); + /** * Returns an array reply of details about all Redis commands. * diff --git a/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionServerCommands.java b/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionServerCommands.java index e111d2cab5..f988663931 100644 --- a/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionServerCommands.java +++ b/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionServerCommands.java @@ -105,6 +105,13 @@ public interface NodeSelectionServerCommands { */ Executions clientList(); + /** + * Get the id of the current connection. + * + * @return Long The command just returns the ID of the current connection. Every connection ID has certain guarantees + */ + Executions clientId(); + /** * Returns an array reply of details about all Redis commands. * diff --git a/src/main/templates/io/lettuce/core/api/RedisServerCommands.java b/src/main/templates/io/lettuce/core/api/RedisServerCommands.java index b395fc1637..2eb4e9bc7c 100644 --- a/src/main/templates/io/lettuce/core/api/RedisServerCommands.java +++ b/src/main/templates/io/lettuce/core/api/RedisServerCommands.java @@ -104,6 +104,13 @@ public interface RedisServerCommands { */ String clientList(); + /** + * Get the id of the current connection. + * + * @return Long The command just returns the ID of the current connection. Every connection ID has certain guarantees + */ + Long clientId(); + /** * Returns an array reply of details about all Redis commands. * diff --git a/src/test/java/io/lettuce/core/commands/ServerCommandIntegrationTests.java b/src/test/java/io/lettuce/core/commands/ServerCommandIntegrationTests.java index d5139b1535..e02f2cc9a1 100644 --- a/src/test/java/io/lettuce/core/commands/ServerCommandIntegrationTests.java +++ b/src/test/java/io/lettuce/core/commands/ServerCommandIntegrationTests.java @@ -167,6 +167,11 @@ void clientUnblock() throws InterruptedException { assertThat(blocked.getError()).contains("UNBLOCKED client unblocked"); } + @Test + void clientId() { + assertThat(redis.clientId()).isNotNull(); + } + @Test void commandCount() { assertThat(redis.commandCount()).isGreaterThan(100);