Skip to content

Commit 5e71dbe

Browse files
committed
Polishing.
Reformat code, add since tags. Tweak Javadoc wording. See #2853 Original pull request: #3017
1 parent cdf9dc3 commit 5e71dbe

11 files changed

+57
-27
lines changed

src/main/java/org/springframework/data/redis/connection/ReactiveStringCommands.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ default Mono<Boolean> set(ByteBuffer key, ByteBuffer value, Expiration expiratio
195195
Flux<BooleanResponse<SetCommand>> set(Publisher<SetCommand> commands);
196196

197197
/**
198-
* Set {@literal value} for {@literal key} with {@literal expiration} and {@literal options}. Return the old
199-
* string stored at key, or nil if key did not exist. An error is returned and SET aborted if the value
200-
* stored at key is not a string.
198+
* Set {@literal value} for {@literal key} with {@literal expiration} and {@literal options}. Return the old string
199+
* stored at key, or empty if key did not exist. An error is returned and SET aborted if the value stored at key is
200+
* not a string.
201201
*
202202
* @param key must not be {@literal null}.
203203
* @param value must not be {@literal null}.
@@ -206,7 +206,7 @@ default Mono<Boolean> set(ByteBuffer key, ByteBuffer value, Expiration expiratio
206206
* @param option must not be {@literal null}.
207207
* @return
208208
* @see <a href="https://redis.io/commands/set">Redis Documentation: SET</a>
209-
* @since 3.4
209+
* @since 3.5
210210
*/
211211
@Nullable
212212
default Mono<ByteBuffer> setGet(ByteBuffer key, ByteBuffer value, Expiration expiration, SetOption option) {
@@ -219,13 +219,13 @@ default Mono<ByteBuffer> setGet(ByteBuffer key, ByteBuffer value, Expiration exp
219219
}
220220

221221
/**
222-
* Set each and every item separately by invoking {@link SetCommand}. Return the old
223-
* string stored at key, or nil if key did not exist. An error is returned and SET aborted if the value
224-
* stored at key is not a string.
222+
* Set each and every item separately by invoking {@link SetCommand}. Return the old string stored at key, or empty if
223+
* key did not exist. An error is returned and SET aborted if the value stored at key is not a string.
225224
*
226225
* @param commands must not be {@literal null}.
227226
* @return {@link Flux} of {@link ByteBufferResponse} holding the {@link SetCommand} along with the command result.
228227
* @see <a href="https://redis.io/commands/set">Redis Documentation: SET</a>
228+
* @since 3.5
229229
*/
230230
Flux<ByteBufferResponse<SetCommand>> setGet(Publisher<SetCommand> commands);
231231

src/main/java/org/springframework/data/redis/connection/RedisStringCommands.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* @author Costin Leau
3030
* @author Christoph Strobl
3131
* @author Mark Paluch
32+
* @author Marcin Grzejszczak
3233
*/
3334
public interface RedisStringCommands {
3435

@@ -123,16 +124,16 @@ enum BitOperation {
123124
Boolean set(byte[] key, byte[] value, Expiration expiration, SetOption option);
124125

125126
/**
126-
* Set {@code value} for {@code key}. Return the old string stored at key, or nil if key did not exist.
127-
* An error is returned and SET aborted if the value stored at key is not a string.
127+
* Set {@code value} for {@code key}. Return the old string stored at key, or {@literal null} if key did not exist. An
128+
* error is returned and SET aborted if the value stored at key is not a string.
128129
*
129130
* @param key must not be {@literal null}.
130131
* @param value must not be {@literal null}.
131132
* @param expiration must not be {@literal null}. Use {@link Expiration#persistent()} to not set any ttl or
132133
* {@link Expiration#keepTtl()} to keep the existing expiration.
133-
* @param option must not be {@literal null}. Use {@link SetOption#upsert()} to add non existing.
134+
* @param option must not be {@literal null}. Use {@link SetOption#upsert()} to add non-existing.
134135
* @return {@literal null} when used in pipeline / transaction.
135-
* @since 3.4
136+
* @since 3.5
136137
* @see <a href="https://redis.io/commands/set">Redis Documentation: SET</a>
137138
*/
138139
@Nullable

src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterStringCommands.java

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
* @author Mark Paluch
4343
* @author Xiaohu Zhang
4444
* @author dengliming
45+
* @author Marcin Grzejszczak
4546
* @since 2.0
4647
*/
4748
class JedisClusterStringCommands implements RedisStringCommands {

src/main/java/org/springframework/data/redis/connection/jedis/JedisStringCommands.java

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
* @author Christoph Strobl
3636
* @author Mark Paluch
3737
* @author dengliming
38+
* @author Marcin Grzejszczak
3839
* @since 2.0
3940
*/
4041
class JedisStringCommands implements RedisStringCommands {
@@ -119,6 +120,7 @@ public Boolean set(byte[] key, byte[] value, Expiration expiration, SetOption op
119120
@Override
120121
@Nullable
121122
public byte[] setGet(byte[] key, byte[] value, Expiration expiration, SetOption option) {
123+
122124
Assert.notNull(key, "Key must not be null");
123125
Assert.notNull(value, "Value must not be null");
124126
Assert.notNull(expiration, "Expiration must not be null");

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveStringCommands.java

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
* @author Jiahe Cai
4949
* @author Michele Mancioppi
5050
* @author John Blum
51+
* @author Marcin Grzejszczak
5152
* @since 2.0
5253
*/
5354
class LettuceReactiveStringCommands implements ReactiveStringCommands {
@@ -107,6 +108,7 @@ public Flux<BooleanResponse<SetCommand>> set(Publisher<SetCommand> commands) {
107108

108109
@Override
109110
public Flux<ByteBufferResponse<SetCommand>> setGet(Publisher<SetCommand> commands) {
111+
110112
return this.connection.execute(reactiveCommands -> Flux.from(commands).concatMap((command) -> {
111113

112114
Assert.notNull(command.getKey(), "Key must not be null");

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceStringCommands.java

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
* @author Mark Paluch
3737
* @author dengliming
3838
* @author John Blum
39+
* @author Marcin Grzejszczak
3940
* @since 2.0
4041
*/
4142
class LettuceStringCommands implements RedisStringCommands {
@@ -118,6 +119,7 @@ public Boolean set(byte[] key, byte[] value, Expiration expiration, SetOption op
118119
@Override
119120
@Nullable
120121
public byte[] setGet(byte[] key, byte[] value, Expiration expiration, SetOption option) {
122+
121123
Assert.notNull(key, "Key must not be null");
122124
Assert.notNull(value, "Value must not be null");
123125
Assert.notNull(expiration, "Expiration must not be null");

src/main/java/org/springframework/data/redis/core/BoundValueOperations.java

+19-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
* @author Mark Paluch
2929
* @author Jiahe Cai
3030
* @author Christoph Strobl
31+
* @author Marcin Grzejszczak
3132
*/
3233
public interface BoundValueOperations<K, V> extends BoundKeyOperations<K> {
3334

@@ -50,18 +51,32 @@ public interface BoundValueOperations<K, V> extends BoundKeyOperations<K> {
5051
void set(V value, long timeout, TimeUnit unit);
5152

5253
/**
53-
* Set the {@code value} and expiration {@code timeout} for the bound key. Return the old
54-
* string stored at key, or nil if key did not exist. An error is returned and SET aborted if the value
55-
* stored at key is not a string.
54+
* Set the {@code value} and expiration {@code timeout} for the bound key. Return the old string stored at key, or
55+
* {@literal null} if key did not exist. An error is returned and SET aborted if the value stored at key is not a
56+
* string.
5657
*
5758
* @param value must not be {@literal null}.
5859
* @param timeout
5960
* @param unit must not be {@literal null}.
61+
* @return {@literal null} when used in pipeline / transaction.
6062
* @see <a href="https://redis.io/commands/set">Redis Documentation: SET</a>
61-
* @since 3.4
63+
* @since 3.5
6264
*/
6365
V setGet(V value, long timeout, TimeUnit unit);
6466

67+
/**
68+
* Set the {@code value} and expiration {@code timeout} for the bound key. Return the old string stored at key, or
69+
* {@literal null} if key did not exist. An error is returned and SET aborted if the value stored at key is not a
70+
* string.
71+
*
72+
* @param value must not be {@literal null}.
73+
* @param duration expiration duration
74+
* @return {@literal null} when used in pipeline / transaction.
75+
* @see <a href="https://redis.io/commands/set">Redis Documentation: SET</a>
76+
* @since 3.5
77+
*/
78+
V setGet(V value, Duration duration);
79+
6580
/**
6681
* Set the {@code value} and expiration {@code timeout} for the bound key.
6782
*

src/main/java/org/springframework/data/redis/core/DefaultValueOperations.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import org.springframework.data.redis.connection.BitFieldSubCommands;
2727
import org.springframework.data.redis.connection.DefaultedRedisConnection;
28+
import org.springframework.data.redis.connection.RedisConnection;
2829
import org.springframework.data.redis.connection.RedisStringCommands.SetOption;
2930
import org.springframework.data.redis.core.types.Expiration;
3031
import org.springframework.lang.Nullable;
@@ -219,8 +220,9 @@ public V setGet(K key, V value, Duration duration) {
219220
}
220221

221222
private V doSetGet(K key, V value, Expiration duration) {
223+
222224
byte[] rawValue = rawValue(value);
223-
return execute( new ValueDeserializingRedisCallback(key) {
225+
return execute(new ValueDeserializingRedisCallback(key) {
224226

225227
@Override
226228
protected byte[] inRedis(byte[] rawKey, RedisConnection connection) {

src/main/java/org/springframework/data/redis/core/ReactiveValueOperations.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ public interface ReactiveValueOperations<K, V> {
5959
Mono<Boolean> set(K key, V value, Duration timeout);
6060

6161
/**
62-
* Set the {@code value} and expiration {@code timeout} for {@code key}. Return the old
63-
* string stored at key, or nil if key did not exist. An error is returned and SET aborted if the value
64-
* stored at key is not a string.
62+
* Set the {@code value} and expiration {@code timeout} for {@code key}. Return the old string stored at key, or empty
63+
* if key did not exist. An error is returned and SET aborted if the value stored at key is not a string.
6564
*
6665
* @param key must not be {@literal null}.
6766
* @param value
6867
* @param timeout must not be {@literal null}.
6968
* @see <a href="https://redis.io/commands/setex">Redis Documentation: SETEX</a>
69+
* @since 3.5
7070
*/
7171
Mono<V> setGet(K key, V value, Duration timeout);
7272

src/main/java/org/springframework/data/redis/core/ValueOperations.java

+10-8
Original file line numberDiff line numberDiff line change
@@ -46,29 +46,31 @@ public interface ValueOperations<K, V> {
4646
void set(K key, V value);
4747

4848
/**
49-
* Set the {@code value} and expiration {@code timeout} for {@code key}. Return the old
50-
* string stored at key, or nil if key did not exist. An error is returned and SET aborted if the value
51-
* stored at key is not a string.
49+
* Set the {@code value} and expiration {@code timeout} for {@code key}. Return the old string stored at key, or
50+
* {@literal null} if key did not exist. An error is returned and SET aborted if the value stored at key is not a
51+
* string.
5252
*
5353
* @param key must not be {@literal null}.
5454
* @param value must not be {@literal null}.
5555
* @param timeout the key expiration timeout.
5656
* @param unit must not be {@literal null}.
57+
* @return {@literal null} when used in pipeline / transaction.
5758
* @see <a href="https://redis.io/commands/set">Redis Documentation: SET</a>
58-
* @since 3.4
59+
* @since 3.5
5960
*/
6061
V setGet(K key, V value, long timeout, TimeUnit unit);
6162

6263
/**
63-
* Set the {@code value} and expiration {@code timeout} for {@code key}. Return the old
64-
* string stored at key, or nil if key did not exist. An error is returned and SET aborted if the value
65-
* stored at key is not a string.
64+
* Set the {@code value} and expiration {@code timeout} for {@code key}. Return the old string stored at key, or
65+
* {@literal null} if key did not exist. An error is returned and SET aborted if the value stored at key is not a
66+
* string.
6667
*
6768
* @param key must not be {@literal null}.
6869
* @param value must not be {@literal null}.
6970
* @param duration expiration duration
71+
* @return {@literal null} when used in pipeline / transaction.
7072
* @see <a href="https://redis.io/commands/set">Redis Documentation: SET</a>
71-
* @since 3.4
73+
* @since 3.5
7274
*/
7375
V setGet(K key, V value, Duration duration);
7476

src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveStringCommandsIntegrationTests.java

+3
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ void setKeepTTL() {
559559

560560
@ParameterizedRedisTest // GH-2853
561561
void setGetMono() {
562+
562563
nativeCommands.set(KEY_1, VALUE_1);
563564

564565
connection.stringCommands().setGet(KEY_1_BBUFFER, VALUE_2_BBUFFER, Expiration.keepTtl(), SetOption.upsert())
@@ -571,6 +572,7 @@ void setGetMono() {
571572

572573
@ParameterizedRedisTest // GH-2853
573574
void setGetFlux() {
575+
574576
nativeCommands.set(KEY_1, VALUE_1);
575577

576578
connection.stringCommands().setGet(Mono.just(SetCommand.set(KEY_1_BBUFFER).value(VALUE_2_BBUFFER).expiring(Expiration.keepTtl()).withSetOption( SetOption.upsert())))
@@ -581,4 +583,5 @@ void setGetFlux() {
581583

582584
assertThat(nativeCommands.get(KEY_1)).isEqualTo(VALUE_2);
583585
}
586+
584587
}

0 commit comments

Comments
 (0)