From 26e230edf7bb849d76ae0138de1615976ecffe3f Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Thu, 14 Jan 2021 09:33:28 +0100 Subject: [PATCH] Polishing #1442 Tweak Javadoc, add author tags. Original pull request: #1461 --- .../core/AbstractRedisAsyncCommands.java | 21 ++++++++++--------- .../core/AbstractRedisReactiveCommands.java | 21 ++++++++++--------- .../io/lettuce/core/RedisCommandBuilder.java | 4 +++- .../api/async/RedisStringAsyncCommands.java | 12 +++++------ .../reactive/RedisStringReactiveCommands.java | 12 +++++------ .../core/api/sync/RedisStringCommands.java | 12 +++++------ .../NodeSelectionStringAsyncCommands.java | 12 +++++------ .../api/sync/NodeSelectionStringCommands.java | 12 +++++------ .../RedisStringCoroutinesCommands.kt | 12 +++++------ .../lettuce/core/api/RedisStringCommands.java | 12 +++++------ .../StringCommandIntegrationTests.java | 21 +++++++++++++++---- 11 files changed, 78 insertions(+), 73 deletions(-) diff --git a/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java b/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java index b93a999dd2..ffd0895ee1 100644 --- a/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java +++ b/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java @@ -53,6 +53,7 @@ * @author Mark Paluch * @author Tugdual Grall * @author dengliming + * @author Andrey Shlykov */ @SuppressWarnings("unchecked") public abstract class AbstractRedisAsyncCommands implements RedisHashAsyncCommands, RedisKeyAsyncCommands, @@ -726,16 +727,6 @@ public RedisFuture getset(K key, V value) { return dispatch(commandBuilder.getset(key, value)); } - @Override - public RedisFuture setGet(K key, V value) { - return dispatch(commandBuilder.setGet(key, value)); - } - - @Override - public RedisFuture setGet(K key, V value, SetArgs setArgs) { - return dispatch(commandBuilder.setGet(key, value, setArgs)); - } - @Override public RedisFuture hdel(K key, K... fields) { return dispatch(commandBuilder.hdel(key, fields)); @@ -1329,6 +1320,16 @@ public RedisFuture set(K key, V value, SetArgs setArgs) { return dispatch(commandBuilder.set(key, value, setArgs)); } + @Override + public RedisFuture setGet(K key, V value) { + return dispatch(commandBuilder.setGet(key, value)); + } + + @Override + public RedisFuture setGet(K key, V value, SetArgs setArgs) { + return dispatch(commandBuilder.setGet(key, value, setArgs)); + } + @Override public void setAutoFlushCommands(boolean autoFlush) { connection.setAutoFlushCommands(autoFlush); diff --git a/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java b/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java index 9948dfb2ad..f62bafad56 100644 --- a/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java +++ b/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java @@ -61,6 +61,7 @@ * @author Nikolai Perevozchikov * @author Tugdual Grall * @author dengliming + * @author Andrey Shlykov * @since 4.0 */ public abstract class AbstractRedisReactiveCommands implements RedisHashReactiveCommands, @@ -787,16 +788,6 @@ public Mono getset(K key, V value) { return createMono(() -> commandBuilder.getset(key, value)); } - @Override - public Mono setGet(K key, V value) { - return createMono(() -> commandBuilder.setGet(key, value)); - } - - @Override - public Mono setGet(K key, V value, SetArgs setArgs) { - return createMono(() -> commandBuilder.setGet(key, value, setArgs)); - } - @Override public Mono hdel(K key, K... fields) { return createMono(() -> commandBuilder.hdel(key, fields)); @@ -1406,6 +1397,16 @@ public Mono set(K key, V value, SetArgs setArgs) { return createMono(() -> commandBuilder.set(key, value, setArgs)); } + @Override + public Mono setGet(K key, V value) { + return createMono(() -> commandBuilder.setGet(key, value)); + } + + @Override + public Mono setGet(K key, V value, SetArgs setArgs) { + return createMono(() -> commandBuilder.setGet(key, value, setArgs)); + } + @Override public void setAutoFlushCommands(boolean autoFlush) { connection.setAutoFlushCommands(autoFlush); diff --git a/src/main/java/io/lettuce/core/RedisCommandBuilder.java b/src/main/java/io/lettuce/core/RedisCommandBuilder.java index b24aa91238..fb7e0c1376 100644 --- a/src/main/java/io/lettuce/core/RedisCommandBuilder.java +++ b/src/main/java/io/lettuce/core/RedisCommandBuilder.java @@ -38,6 +38,7 @@ import io.lettuce.core.protocol.BaseRedisCommandBuilder; import io.lettuce.core.protocol.Command; import io.lettuce.core.protocol.CommandArgs; +import io.lettuce.core.protocol.CommandKeyword; import io.lettuce.core.protocol.CommandType; import io.lettuce.core.protocol.RedisCommand; @@ -1851,10 +1852,11 @@ Command setGet(K key, V value) { Command setGet(K key, V value, SetArgs setArgs) { notNullKey(key); + LettuceAssert.notNull(setArgs, "SetArgs " + MUST_NOT_BE_NULL); CommandArgs args = new CommandArgs<>(codec).addKey(key).addValue(value); setArgs.build(args); - args.add("GET"); + args.add(GET); return createCommand(SET, new ValueOutput<>(codec), args); } diff --git a/src/main/java/io/lettuce/core/api/async/RedisStringAsyncCommands.java b/src/main/java/io/lettuce/core/api/async/RedisStringAsyncCommands.java index 2aca3ac029..d0528c3cfe 100644 --- a/src/main/java/io/lettuce/core/api/async/RedisStringAsyncCommands.java +++ b/src/main/java/io/lettuce/core/api/async/RedisStringAsyncCommands.java @@ -309,9 +309,8 @@ public interface RedisStringAsyncCommands { /** * Set the string value of a key and return its old value. * - * @param key the key - * @param value the value - * + * @param key the key. + * @param value the value. * @return V bulk-string-reply the old value stored at {@code key}, or {@code null} when {@code key} did not exist. * @since 6.2 */ @@ -320,10 +319,9 @@ public interface RedisStringAsyncCommands { /** * Set the string value of a key and return its old value. * - * @param key the key - * @param value the value - * @param setArgs the command arguments - * + * @param key the key. + * @param value the value. + * @param setArgs the command arguments. * @return V bulk-string-reply the old value stored at {@code key}, or {@code null} when {@code key} did not exist. * @since 6.2 */ diff --git a/src/main/java/io/lettuce/core/api/reactive/RedisStringReactiveCommands.java b/src/main/java/io/lettuce/core/api/reactive/RedisStringReactiveCommands.java index 24488a12bc..2c8db52a2b 100644 --- a/src/main/java/io/lettuce/core/api/reactive/RedisStringReactiveCommands.java +++ b/src/main/java/io/lettuce/core/api/reactive/RedisStringReactiveCommands.java @@ -312,9 +312,8 @@ public interface RedisStringReactiveCommands { /** * Set the string value of a key and return its old value. * - * @param key the key - * @param value the value - * + * @param key the key. + * @param value the value. * @return V bulk-string-reply the old value stored at {@code key}, or {@code null} when {@code key} did not exist. * @since 6.2 */ @@ -323,10 +322,9 @@ public interface RedisStringReactiveCommands { /** * Set the string value of a key and return its old value. * - * @param key the key - * @param value the value - * @param setArgs the command arguments - * + * @param key the key. + * @param value the value. + * @param setArgs the command arguments. * @return V bulk-string-reply the old value stored at {@code key}, or {@code null} when {@code key} did not exist. * @since 6.2 */ diff --git a/src/main/java/io/lettuce/core/api/sync/RedisStringCommands.java b/src/main/java/io/lettuce/core/api/sync/RedisStringCommands.java index 77bcf90ede..71871b885f 100644 --- a/src/main/java/io/lettuce/core/api/sync/RedisStringCommands.java +++ b/src/main/java/io/lettuce/core/api/sync/RedisStringCommands.java @@ -309,9 +309,8 @@ public interface RedisStringCommands { /** * Set the string value of a key and return its old value. * - * @param key the key - * @param value the value - * + * @param key the key. + * @param value the value. * @return V bulk-string-reply the old value stored at {@code key}, or {@code null} when {@code key} did not exist. * @since 6.2 */ @@ -320,10 +319,9 @@ public interface RedisStringCommands { /** * Set the string value of a key and return its old value. * - * @param key the key - * @param value the value - * @param setArgs the command arguments - * + * @param key the key. + * @param value the value. + * @param setArgs the command arguments. * @return V bulk-string-reply the old value stored at {@code key}, or {@code null} when {@code key} did not exist. * @since 6.2 */ diff --git a/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionStringAsyncCommands.java b/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionStringAsyncCommands.java index c5e261dc9a..24fa588532 100644 --- a/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionStringAsyncCommands.java +++ b/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionStringAsyncCommands.java @@ -309,9 +309,8 @@ public interface NodeSelectionStringAsyncCommands { /** * Set the string value of a key and return its old value. * - * @param key the key - * @param value the value - * + * @param key the key. + * @param value the value. * @return V bulk-string-reply the old value stored at {@code key}, or {@code null} when {@code key} did not exist. * @since 6.2 */ @@ -320,10 +319,9 @@ public interface NodeSelectionStringAsyncCommands { /** * Set the string value of a key and return its old value. * - * @param key the key - * @param value the value - * @param setArgs the command arguments - * + * @param key the key. + * @param value the value. + * @param setArgs the command arguments. * @return V bulk-string-reply the old value stored at {@code key}, or {@code null} when {@code key} did not exist. * @since 6.2 */ diff --git a/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionStringCommands.java b/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionStringCommands.java index 394553d36f..2efca005a2 100644 --- a/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionStringCommands.java +++ b/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionStringCommands.java @@ -309,9 +309,8 @@ public interface NodeSelectionStringCommands { /** * Set the string value of a key and return its old value. * - * @param key the key - * @param value the value - * + * @param key the key. + * @param value the value. * @return V bulk-string-reply the old value stored at {@code key}, or {@code null} when {@code key} did not exist. * @since 6.2 */ @@ -320,10 +319,9 @@ public interface NodeSelectionStringCommands { /** * Set the string value of a key and return its old value. * - * @param key the key - * @param value the value - * @param setArgs the command arguments - * + * @param key the key. + * @param value the value. + * @param setArgs the command arguments. * @return V bulk-string-reply the old value stored at {@code key}, or {@code null} when {@code key} did not exist. * @since 6.2 */ diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisStringCoroutinesCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisStringCoroutinesCommands.kt index 2a5fd37845..8909f649fd 100644 --- a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisStringCoroutinesCommands.kt +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisStringCoroutinesCommands.kt @@ -257,7 +257,7 @@ interface RedisStringCoroutinesCommands { * @param keys the key. * @return List array-reply list of values at the specified keys. */ - fun mget(vararg keys: K): Flow> + fun mget(vararg keys: K): Flow> /** * Set multiple keys to multiple values. @@ -299,8 +299,8 @@ interface RedisStringCoroutinesCommands { /** * Set the string value of a key and return its old value. * - * @param key the key - * @param value the value + * @param key the key. + * @param value the value. * @return V bulk-string-reply the old value stored at `key`, or `null` when `key` did not exist. * @since 6.2 */ @@ -309,9 +309,9 @@ interface RedisStringCoroutinesCommands { /** * Set the string value of a key and return its old value. * - * @param key the key - * @param value the value - * @param setArgs the command arguments + * @param key the key. + * @param value the value. + * @param setArgs the command arguments. * @return V bulk-string-reply the old value stored at `key`, or `null` when `key` did not exist. * @since 6.2 */ diff --git a/src/main/templates/io/lettuce/core/api/RedisStringCommands.java b/src/main/templates/io/lettuce/core/api/RedisStringCommands.java index 0df617d772..ef40ccbf68 100644 --- a/src/main/templates/io/lettuce/core/api/RedisStringCommands.java +++ b/src/main/templates/io/lettuce/core/api/RedisStringCommands.java @@ -308,9 +308,8 @@ public interface RedisStringCommands { /** * Set the string value of a key and return its old value. * - * @param key the key - * @param value the value - * + * @param key the key. + * @param value the value. * @return V bulk-string-reply the old value stored at {@code key}, or {@code null} when {@code key} did not exist. * @since 6.2 */ @@ -319,10 +318,9 @@ public interface RedisStringCommands { /** * Set the string value of a key and return its old value. * - * @param key the key - * @param value the value - * @param setArgs the command arguments - * + * @param key the key. + * @param value the value. + * @param setArgs the command arguments. * @return V bulk-string-reply the old value stored at {@code key}, or {@code null} when {@code key} did not exist. * @since 6.2 */ diff --git a/src/test/java/io/lettuce/core/commands/StringCommandIntegrationTests.java b/src/test/java/io/lettuce/core/commands/StringCommandIntegrationTests.java index 068f75cbfb..076598cdc6 100644 --- a/src/test/java/io/lettuce/core/commands/StringCommandIntegrationTests.java +++ b/src/test/java/io/lettuce/core/commands/StringCommandIntegrationTests.java @@ -16,9 +16,8 @@ package io.lettuce.core.commands; import static io.lettuce.core.SetArgs.Builder.*; -import static io.lettuce.core.StringMatchResult.Position; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static io.lettuce.core.StringMatchResult.*; +import static org.assertj.core.api.Assertions.*; import java.util.LinkedHashMap; import java.util.List; @@ -31,7 +30,12 @@ import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.extension.ExtendWith; -import io.lettuce.core.*; +import io.lettuce.core.KeyValue; +import io.lettuce.core.RedisException; +import io.lettuce.core.SetArgs; +import io.lettuce.core.StrAlgoArgs; +import io.lettuce.core.StringMatchResult; +import io.lettuce.core.TestSupport; import io.lettuce.core.api.sync.RedisCommands; import io.lettuce.test.KeyValueStreamingAdapter; import io.lettuce.test.LettuceExtension; @@ -200,6 +204,15 @@ void setGet() { assertThat(redis.get(key)).isEqualTo("value2"); } + @Test + @EnabledOnCommand("ZMSCORE") // Redis 6.2 + void setGetWithArgs() { + assertThat(redis.setGet(key, value)).isNull(); + assertThat(redis.setGet(key, "value2", SetArgs.Builder.ex(100))).isEqualTo(value); + assertThat(redis.get(key)).isEqualTo("value2"); + assertThat(redis.ttl(key)).isGreaterThanOrEqualTo(10); + } + @Test void setbit() { assertThat(redis.setbit(key, 0, 1)).isEqualTo(0);