Polishing.

Reformat code, add since tags. Tweak Javadoc wording.

See #2853
Original pull request: #3017
This commit is contained in:
Mark Paluch
2025-02-24 09:47:21 +01:00
parent cdf9dc360c
commit 5e71dbeb60
11 changed files with 57 additions and 27 deletions

View File

@@ -195,9 +195,9 @@ public interface ReactiveStringCommands {
Flux<BooleanResponse<SetCommand>> set(Publisher<SetCommand> commands);
/**
* Set {@literal value} for {@literal key} with {@literal expiration} and {@literal options}. Return the old
* string stored at key, or nil if key did not exist. An error is returned and SET aborted if the value
* stored at key is not a string.
* Set {@literal value} for {@literal key} with {@literal expiration} and {@literal options}. Return the old string
* stored at key, or empty if key did not exist. An error is returned and SET aborted if the value stored at key is
* not a string.
*
* @param key must not be {@literal null}.
* @param value must not be {@literal null}.
@@ -206,7 +206,7 @@ public interface ReactiveStringCommands {
* @param option must not be {@literal null}.
* @return
* @see <a href="https://redis.io/commands/set">Redis Documentation: SET</a>
* @since 3.4
* @since 3.5
*/
@Nullable
default Mono<ByteBuffer> setGet(ByteBuffer key, ByteBuffer value, Expiration expiration, SetOption option) {
@@ -219,13 +219,13 @@ public interface ReactiveStringCommands {
}
/**
* Set each and every item separately by invoking {@link SetCommand}. Return the old
* string stored at key, or nil if key did not exist. An error is returned and SET aborted if the value
* stored at key is not a string.
* Set each and every item separately by invoking {@link SetCommand}. Return the old string stored at key, or empty if
* key did not exist. An error is returned and SET aborted if the value stored at key is not a string.
*
* @param commands must not be {@literal null}.
* @return {@link Flux} of {@link ByteBufferResponse} holding the {@link SetCommand} along with the command result.
* @see <a href="https://redis.io/commands/set">Redis Documentation: SET</a>
* @since 3.5
*/
Flux<ByteBufferResponse<SetCommand>> setGet(Publisher<SetCommand> commands);

View File

@@ -29,6 +29,7 @@ import org.springframework.lang.Nullable;
* @author Costin Leau
* @author Christoph Strobl
* @author Mark Paluch
* @author Marcin Grzejszczak
*/
public interface RedisStringCommands {
@@ -123,16 +124,16 @@ public interface RedisStringCommands {
Boolean set(byte[] key, byte[] value, Expiration expiration, SetOption option);
/**
* Set {@code value} for {@code key}. Return the old string stored at key, or nil if key did not exist.
* An error is returned and SET aborted if the value stored at key is not a string.
* Set {@code value} for {@code key}. Return the old string stored at key, or {@literal null} if key did not exist. An
* error is returned and SET aborted if the value stored at key is not a string.
*
* @param key must not be {@literal null}.
* @param value must not be {@literal null}.
* @param expiration must not be {@literal null}. Use {@link Expiration#persistent()} to not set any ttl or
* {@link Expiration#keepTtl()} to keep the existing expiration.
* @param option must not be {@literal null}. Use {@link SetOption#upsert()} to add non existing.
* @param option must not be {@literal null}. Use {@link SetOption#upsert()} to add non-existing.
* @return {@literal null} when used in pipeline / transaction.
* @since 3.4
* @since 3.5
* @see <a href="https://redis.io/commands/set">Redis Documentation: SET</a>
*/
@Nullable

View File

@@ -42,6 +42,7 @@ import org.springframework.util.Assert;
* @author Mark Paluch
* @author Xiaohu Zhang
* @author dengliming
* @author Marcin Grzejszczak
* @since 2.0
*/
class JedisClusterStringCommands implements RedisStringCommands {

View File

@@ -35,6 +35,7 @@ import org.springframework.util.Assert;
* @author Christoph Strobl
* @author Mark Paluch
* @author dengliming
* @author Marcin Grzejszczak
* @since 2.0
*/
class JedisStringCommands implements RedisStringCommands {
@@ -119,6 +120,7 @@ class JedisStringCommands implements RedisStringCommands {
@Override
@Nullable
public byte[] setGet(byte[] key, byte[] value, Expiration expiration, SetOption option) {
Assert.notNull(key, "Key must not be null");
Assert.notNull(value, "Value must not be null");
Assert.notNull(expiration, "Expiration must not be null");

View File

@@ -48,6 +48,7 @@ import org.springframework.util.Assert;
* @author Jiahe Cai
* @author Michele Mancioppi
* @author John Blum
* @author Marcin Grzejszczak
* @since 2.0
*/
class LettuceReactiveStringCommands implements ReactiveStringCommands {
@@ -107,6 +108,7 @@ class LettuceReactiveStringCommands implements ReactiveStringCommands {
@Override
public Flux<ByteBufferResponse<SetCommand>> setGet(Publisher<SetCommand> commands) {
return this.connection.execute(reactiveCommands -> Flux.from(commands).concatMap((command) -> {
Assert.notNull(command.getKey(), "Key must not be null");

View File

@@ -36,6 +36,7 @@ import org.springframework.util.Assert;
* @author Mark Paluch
* @author dengliming
* @author John Blum
* @author Marcin Grzejszczak
* @since 2.0
*/
class LettuceStringCommands implements RedisStringCommands {
@@ -118,6 +119,7 @@ class LettuceStringCommands implements RedisStringCommands {
@Override
@Nullable
public byte[] setGet(byte[] key, byte[] value, Expiration expiration, SetOption option) {
Assert.notNull(key, "Key must not be null");
Assert.notNull(value, "Value must not be null");
Assert.notNull(expiration, "Expiration must not be null");

View File

@@ -28,6 +28,7 @@ import org.springframework.util.Assert;
* @author Mark Paluch
* @author Jiahe Cai
* @author Christoph Strobl
* @author Marcin Grzejszczak
*/
public interface BoundValueOperations<K, V> extends BoundKeyOperations<K> {
@@ -50,18 +51,32 @@ public interface BoundValueOperations<K, V> extends BoundKeyOperations<K> {
void set(V value, long timeout, TimeUnit unit);
/**
* Set the {@code value} and expiration {@code timeout} for the bound key. Return the old
* string stored at key, or nil if key did not exist. An error is returned and SET aborted if the value
* stored at key is not a string.
* Set the {@code value} and expiration {@code timeout} for the bound key. Return the old string stored at key, or
* {@literal null} if key did not exist. An error is returned and SET aborted if the value stored at key is not a
* string.
*
* @param value must not be {@literal null}.
* @param timeout
* @param unit must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="https://redis.io/commands/set">Redis Documentation: SET</a>
* @since 3.4
* @since 3.5
*/
V setGet(V value, long timeout, TimeUnit unit);
/**
* Set the {@code value} and expiration {@code timeout} for the bound key. Return the old string stored at key, or
* {@literal null} if key did not exist. An error is returned and SET aborted if the value stored at key is not a
* string.
*
* @param value must not be {@literal null}.
* @param duration expiration duration
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="https://redis.io/commands/set">Redis Documentation: SET</a>
* @since 3.5
*/
V setGet(V value, Duration duration);
/**
* Set the {@code value} and expiration {@code timeout} for the bound key.
*

View File

@@ -25,6 +25,7 @@ import java.util.concurrent.TimeUnit;
import org.springframework.data.redis.connection.BitFieldSubCommands;
import org.springframework.data.redis.connection.DefaultedRedisConnection;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisStringCommands.SetOption;
import org.springframework.data.redis.core.types.Expiration;
import org.springframework.lang.Nullable;
@@ -219,8 +220,9 @@ class DefaultValueOperations<K, V> extends AbstractOperations<K, V> implements V
}
private V doSetGet(K key, V value, Expiration duration) {
byte[] rawValue = rawValue(value);
return execute( new ValueDeserializingRedisCallback(key) {
return execute(new ValueDeserializingRedisCallback(key) {
@Override
protected byte[] inRedis(byte[] rawKey, RedisConnection connection) {

View File

@@ -59,14 +59,14 @@ public interface ReactiveValueOperations<K, V> {
Mono<Boolean> set(K key, V value, Duration timeout);
/**
* Set the {@code value} and expiration {@code timeout} for {@code key}. Return the old
* string stored at key, or nil if key did not exist. An error is returned and SET aborted if the value
* stored at key is not a string.
* Set the {@code value} and expiration {@code timeout} for {@code key}. Return the old string stored at key, or empty
* if key did not exist. An error is returned and SET aborted if the value stored at key is not a string.
*
* @param key must not be {@literal null}.
* @param value
* @param timeout must not be {@literal null}.
* @see <a href="https://redis.io/commands/setex">Redis Documentation: SETEX</a>
* @since 3.5
*/
Mono<V> setGet(K key, V value, Duration timeout);

View File

@@ -46,29 +46,31 @@ public interface ValueOperations<K, V> {
void set(K key, V value);
/**
* Set the {@code value} and expiration {@code timeout} for {@code key}. Return the old
* string stored at key, or nil if key did not exist. An error is returned and SET aborted if the value
* stored at key is not a string.
* Set the {@code value} and expiration {@code timeout} for {@code key}. Return the old string stored at key, or
* {@literal null} if key did not exist. An error is returned and SET aborted if the value stored at key is not a
* string.
*
* @param key must not be {@literal null}.
* @param value must not be {@literal null}.
* @param timeout the key expiration timeout.
* @param unit must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="https://redis.io/commands/set">Redis Documentation: SET</a>
* @since 3.4
* @since 3.5
*/
V setGet(K key, V value, long timeout, TimeUnit unit);
/**
* Set the {@code value} and expiration {@code timeout} for {@code key}. Return the old
* string stored at key, or nil if key did not exist. An error is returned and SET aborted if the value
* stored at key is not a string.
* Set the {@code value} and expiration {@code timeout} for {@code key}. Return the old string stored at key, or
* {@literal null} if key did not exist. An error is returned and SET aborted if the value stored at key is not a
* string.
*
* @param key must not be {@literal null}.
* @param value must not be {@literal null}.
* @param duration expiration duration
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="https://redis.io/commands/set">Redis Documentation: SET</a>
* @since 3.4
* @since 3.5
*/
V setGet(K key, V value, Duration duration);

View File

@@ -559,6 +559,7 @@ public class LettuceReactiveStringCommandsIntegrationTests extends LettuceReacti
@ParameterizedRedisTest // GH-2853
void setGetMono() {
nativeCommands.set(KEY_1, VALUE_1);
connection.stringCommands().setGet(KEY_1_BBUFFER, VALUE_2_BBUFFER, Expiration.keepTtl(), SetOption.upsert())
@@ -571,6 +572,7 @@ public class LettuceReactiveStringCommandsIntegrationTests extends LettuceReacti
@ParameterizedRedisTest // GH-2853
void setGetFlux() {
nativeCommands.set(KEY_1, VALUE_1);
connection.stringCommands().setGet(Mono.just(SetCommand.set(KEY_1_BBUFFER).value(VALUE_2_BBUFFER).expiring(Expiration.keepTtl()).withSetOption( SetOption.upsert())))
@@ -581,4 +583,5 @@ public class LettuceReactiveStringCommandsIntegrationTests extends LettuceReacti
assertThat(nativeCommands.get(KEY_1)).isEqualTo(VALUE_2);
}
}