Skip to content

Commit

Permalink
Polishing #1442
Browse files Browse the repository at this point in the history
Tweak Javadoc, add author tags.

Original pull request: #1461
  • Loading branch information
mp911de committed Jan 14, 2021
1 parent 19e439f commit 26e230e
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 73 deletions.
21 changes: 11 additions & 10 deletions src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
* @author Mark Paluch
* @author Tugdual Grall
* @author dengliming
* @author Andrey Shlykov
*/
@SuppressWarnings("unchecked")
public abstract class AbstractRedisAsyncCommands<K, V> implements RedisHashAsyncCommands<K, V>, RedisKeyAsyncCommands<K, V>,
Expand Down Expand Up @@ -726,16 +727,6 @@ public RedisFuture<V> getset(K key, V value) {
return dispatch(commandBuilder.getset(key, value));
}

@Override
public RedisFuture<V> setGet(K key, V value) {
return dispatch(commandBuilder.setGet(key, value));
}

@Override
public RedisFuture<V> setGet(K key, V value, SetArgs setArgs) {
return dispatch(commandBuilder.setGet(key, value, setArgs));
}

@Override
public RedisFuture<Long> hdel(K key, K... fields) {
return dispatch(commandBuilder.hdel(key, fields));
Expand Down Expand Up @@ -1329,6 +1320,16 @@ public RedisFuture<String> set(K key, V value, SetArgs setArgs) {
return dispatch(commandBuilder.set(key, value, setArgs));
}

@Override
public RedisFuture<V> setGet(K key, V value) {
return dispatch(commandBuilder.setGet(key, value));
}

@Override
public RedisFuture<V> setGet(K key, V value, SetArgs setArgs) {
return dispatch(commandBuilder.setGet(key, value, setArgs));
}

@Override
public void setAutoFlushCommands(boolean autoFlush) {
connection.setAutoFlushCommands(autoFlush);
Expand Down
21 changes: 11 additions & 10 deletions src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
* @author Nikolai Perevozchikov
* @author Tugdual Grall
* @author dengliming
* @author Andrey Shlykov
* @since 4.0
*/
public abstract class AbstractRedisReactiveCommands<K, V> implements RedisHashReactiveCommands<K, V>,
Expand Down Expand Up @@ -787,16 +788,6 @@ public Mono<V> getset(K key, V value) {
return createMono(() -> commandBuilder.getset(key, value));
}

@Override
public Mono<V> setGet(K key, V value) {
return createMono(() -> commandBuilder.setGet(key, value));
}

@Override
public Mono<V> setGet(K key, V value, SetArgs setArgs) {
return createMono(() -> commandBuilder.setGet(key, value, setArgs));
}

@Override
public Mono<Long> hdel(K key, K... fields) {
return createMono(() -> commandBuilder.hdel(key, fields));
Expand Down Expand Up @@ -1406,6 +1397,16 @@ public Mono<String> set(K key, V value, SetArgs setArgs) {
return createMono(() -> commandBuilder.set(key, value, setArgs));
}

@Override
public Mono<V> setGet(K key, V value) {
return createMono(() -> commandBuilder.setGet(key, value));
}

@Override
public Mono<V> setGet(K key, V value, SetArgs setArgs) {
return createMono(() -> commandBuilder.setGet(key, value, setArgs));
}

@Override
public void setAutoFlushCommands(boolean autoFlush) {
connection.setAutoFlushCommands(autoFlush);
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/io/lettuce/core/RedisCommandBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -1851,10 +1852,11 @@ Command<K, V, V> setGet(K key, V value) {

Command<K, V, V> setGet(K key, V value, SetArgs setArgs) {
notNullKey(key);
LettuceAssert.notNull(setArgs, "SetArgs " + MUST_NOT_BE_NULL);

CommandArgs<K, V> args = new CommandArgs<>(codec).addKey(key).addValue(value);
setArgs.build(args);
args.add("GET");
args.add(GET);

return createCommand(SET, new ValueOutput<>(codec), args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,8 @@ public interface RedisStringAsyncCommands<K, V> {
/**
* 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
*/
Expand All @@ -320,10 +319,9 @@ public interface RedisStringAsyncCommands<K, V> {
/**
* 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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,8 @@ public interface RedisStringReactiveCommands<K, V> {
/**
* 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
*/
Expand All @@ -323,10 +322,9 @@ public interface RedisStringReactiveCommands<K, V> {
/**
* 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
*/
Expand Down
12 changes: 5 additions & 7 deletions src/main/java/io/lettuce/core/api/sync/RedisStringCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,8 @@ public interface RedisStringCommands<K, V> {
/**
* 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
*/
Expand All @@ -320,10 +319,9 @@ public interface RedisStringCommands<K, V> {
/**
* 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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,8 @@ public interface NodeSelectionStringAsyncCommands<K, V> {
/**
* 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
*/
Expand All @@ -320,10 +319,9 @@ public interface NodeSelectionStringAsyncCommands<K, V> {
/**
* 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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,8 @@ public interface NodeSelectionStringCommands<K, V> {
/**
* 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
*/
Expand All @@ -320,10 +319,9 @@ public interface NodeSelectionStringCommands<K, V> {
/**
* 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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ interface RedisStringCoroutinesCommands<K : Any, V : Any> {
* @param keys the key.
* @return List<V> array-reply list of values at the specified keys.
*/
fun mget(vararg keys: K): Flow<KeyValue<K, V>>
fun mget(vararg keys: K): Flow<KeyValue<K,V>>

/**
* Set multiple keys to multiple values.
Expand Down Expand Up @@ -299,8 +299,8 @@ interface RedisStringCoroutinesCommands<K : Any, V : Any> {
/**
* 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
*/
Expand All @@ -309,9 +309,9 @@ interface RedisStringCoroutinesCommands<K : Any, V : Any> {
/**
* 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
*/
Expand Down
12 changes: 5 additions & 7 deletions src/main/templates/io/lettuce/core/api/RedisStringCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,8 @@ public interface RedisStringCommands<K, V> {
/**
* 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
*/
Expand All @@ -319,10 +318,9 @@ public interface RedisStringCommands<K, V> {
/**
* 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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 26e230e

Please sign in to comment.