Skip to content

Commit ff53ba9

Browse files
committed
Document conditional set return values.
Closes #3414
1 parent 751fd2a commit ff53ba9

6 files changed

Lines changed: 54 additions & 23 deletions

File tree

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ default Mono<Boolean> set(ByteBuffer key, ByteBuffer value) {
172172
* @param expiration must not be {@literal null}. Use {@link Expiration#persistent()} for no expiration time or
173173
* {@link Expiration#keepTtl()} to keep the existing.
174174
* @param option must not be {@literal null}.
175-
* @return
175+
* @return {@literal true} if the value was set, {@literal false} if {@literal option} was not met.
176176
* @see <a href="https://redis.io/commands/set">Redis Documentation: SET</a>
177177
*/
178178
default Mono<Boolean> set(ByteBuffer key, ByteBuffer value, Expiration expiration, SetOption option) {
@@ -188,7 +188,8 @@ default Mono<Boolean> set(ByteBuffer key, ByteBuffer value, Expiration expiratio
188188
* Set each and every item separately by invoking {@link SetCommand}.
189189
*
190190
* @param commands must not be {@literal null}.
191-
* @return {@link Flux} of {@link BooleanResponse} holding the {@link SetCommand} along with the command result.
191+
* @return {@link Flux} of {@link BooleanResponse} holding the {@link SetCommand} along with {@literal true} if the
192+
* value was set, {@literal false} if the command's condition was not met.
192193
* @see <a href="https://redis.io/commands/set">Redis Documentation: SET</a>
193194
*/
194195
Flux<BooleanResponse<SetCommand>> set(Publisher<SetCommand> commands);
@@ -412,7 +413,7 @@ default Mono<List<ByteBuffer>> mGet(List<ByteBuffer> keys) {
412413
*
413414
* @param key must not be {@literal null}.
414415
* @param value must not be {@literal null}.
415-
* @return
416+
* @return {@literal true} if the value was set, {@literal false} if {@literal key} already exists.
416417
* @see <a href="https://redis.io/commands/setnx">Redis Documentation: SETNX</a>
417418
*/
418419
default Mono<Boolean> setNX(ByteBuffer key, ByteBuffer value) {
@@ -427,7 +428,8 @@ default Mono<Boolean> setNX(ByteBuffer key, ByteBuffer value) {
427428
* Set {@literal key value} pairs, only if {@literal key} does not exist.
428429
*
429430
* @param values must not be {@literal null}.
430-
* @return
431+
* @return {@link Flux} of {@link BooleanResponse} holding the {@link SetCommand} along with {@literal true} if the
432+
* value was set, {@literal false} if {@literal key} already exists.
431433
* @see <a href="https://redis.io/commands/setnx">Redis Documentation: SETNX</a>
432434
*/
433435
Flux<BooleanResponse<SetCommand>> setNX(Publisher<SetCommand> values);
@@ -556,7 +558,8 @@ default Mono<Boolean> mSet(Map<ByteBuffer, ByteBuffer> keyValuePairs) {
556558
* provided key does not exist.
557559
*
558560
* @param keyValuePairs must not be {@literal null}.
559-
* @return
561+
* @return {@literal true} if all keys were set, {@literal false} if at least one key already exists, in which case
562+
* no key is set.
560563
* @see <a href="https://redis.io/commands/msetnx">Redis Documentation: MSETNX</a>
561564
*/
562565
default Mono<Boolean> mSetNX(Map<ByteBuffer, ByteBuffer> keyValuePairs) {
@@ -571,7 +574,8 @@ default Mono<Boolean> mSetNX(Map<ByteBuffer, ByteBuffer> keyValuePairs) {
571574
* does not exist.
572575
*
573576
* @param source must not be {@literal null}.
574-
* @return
577+
* @return {@link Flux} of {@link BooleanResponse} holding the {@link MSetCommand} along with {@literal true} if all
578+
* keys were set, {@literal false} if at least one key already exists, in which case no key is set.
575579
* @see <a href="https://redis.io/commands/msetnx">Redis Documentation: MSETNX</a>
576580
*/
577581
Flux<BooleanResponse<MSetCommand>> mSetNX(Publisher<MSetCommand> source);

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ enum BitOperation {
114114
* @param expiration must not be {@literal null}. Use {@link Expiration#persistent()} to not set any ttl or
115115
* {@link Expiration#keepTtl()} to keep the existing expiration.
116116
* @param option must not be {@literal null}. Use {@link SetOption#upsert()} to add non existing.
117-
* @return {@literal null} when used in pipeline / transaction.
117+
* @return {@literal true} if the value was set, {@literal false} if {@code option} was not met. {@literal null}
118+
* when used in pipeline / transaction.
118119
* @since 1.7
119120
* @see <a href="https://redis.io/commands/set">Redis Documentation: SET</a>
120121
*/
@@ -141,7 +142,8 @@ byte[] setGet(byte @NonNull [] key, byte @NonNull [] value, @NonNull Expiration
141142
*
142143
* @param key must not be {@literal null}.
143144
* @param value must not be {@literal null}.
144-
* @return {@literal null} when used in pipeline / transaction.
145+
* @return {@literal true} if the value was set, {@literal false} if {@code key} already exists. {@literal null}
146+
* when used in pipeline / transaction.
145147
* @see <a href="https://redis.io/commands/setnx">Redis Documentation: SETNX</a>
146148
*/
147149
Boolean setNX(byte @NonNull [] key, byte @NonNull [] value);
@@ -183,7 +185,8 @@ byte[] setGet(byte @NonNull [] key, byte @NonNull [] value, @NonNull Expiration
183185
* not exist.
184186
*
185187
* @param tuple must not be {@literal null}.
186-
* @return {@literal null} when used in pipeline / transaction.
188+
* @return {@literal true} if all keys were set, {@literal false} if at least one key already exists, in which case
189+
* no key is set. {@literal null} when used in pipeline / transaction.
187190
* @see <a href="https://redis.io/commands/msetnx">Redis Documentation: MSETNX</a>
188191
*/
189192
Boolean mSetNX(@NonNull Map<byte @NonNull [], byte @NonNull []> tuple);

‎src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,8 @@ default Boolean pExpireAt(@NonNull String key, long unixTimeInMillis) {
526526
* @param expiration can be {@literal null}. Defaulted to {@link Expiration#persistent()}. Use
527527
* {@link Expiration#keepTtl()} to keep the existing expiration.
528528
* @param option can be {@literal null}. Defaulted to {@link SetOption#UPSERT}.
529+
* @return {@literal true} if the value was set, {@literal false} if {@code option} was not met. {@literal null}
530+
* when used in pipeline / transaction.
529531
* @since 1.7
530532
* @see <a href="https://redis.io/commands/set">Redis Documentation: SET</a>
531533
* @see RedisStringCommands#set(byte[], byte[], Expiration, SetOption)
@@ -537,7 +539,8 @@ default Boolean pExpireAt(@NonNull String key, long unixTimeInMillis) {
537539
*
538540
* @param key must not be {@literal null}.
539541
* @param value must not be {@literal null}.
540-
* @return
542+
* @return {@literal true} if the value was set, {@literal false} if {@code key} already exists. {@literal null}
543+
* when used in pipeline / transaction.
541544
* @see <a href="https://redis.io/commands/setnx">Redis Documentation: SETNX</a>
542545
* @see RedisStringCommands#setNX(byte[], byte[])
543546
*/
@@ -580,6 +583,8 @@ default Boolean pExpireAt(@NonNull String key, long unixTimeInMillis) {
580583
* not exist.
581584
*
582585
* @param tuple must not be {@literal null}.
586+
* @return {@literal true} if all keys were set, {@literal false} if at least one key already exists, in which case
587+
* no key is set. {@literal null} when used in pipeline / transaction.
583588
* @see <a href="https://redis.io/commands/msetnx">Redis Documentation: MSETNX</a>
584589
* @see RedisStringCommands#mSetNX(Map)
585590
*/

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ default void set(@NonNull V value, @NonNull Duration timeout) {
104104
* Set the bound key to hold the string {@code value} if the bound key is absent.
105105
*
106106
* @param value must not be {@literal null}.
107-
* @return {@literal null} when used in pipeline / transaction.
107+
* @return {@literal true} if the value was set, {@literal false} if the bound key already exists. {@literal null}
108+
* when used in pipeline / transaction.
108109
* @see <a href="https://redis.io/commands/setnx">Redis Documentation: SETNX</a>
109110
*/
110111
Boolean setIfAbsent(@NonNull V value);
@@ -115,7 +116,8 @@ default void set(@NonNull V value, @NonNull Duration timeout) {
115116
* @param value must not be {@literal null}.
116117
* @param timeout
117118
* @param unit must not be {@literal null}.
118-
* @return {@literal null} when used in pipeline / transaction.
119+
* @return {@literal true} if the value was set, {@literal false} if the bound key already exists. {@literal null}
120+
* when used in pipeline / transaction.
119121
* @since 2.1
120122
* @see <a href="https://redis.io/commands/set">Redis Documentation: SET</a>
121123
*/
@@ -126,7 +128,8 @@ default void set(@NonNull V value, @NonNull Duration timeout) {
126128
*
127129
* @param value must not be {@literal null}.
128130
* @param timeout must not be {@literal null}.
129-
* @return {@literal null} when used in pipeline / transaction.
131+
* @return {@literal true} if the value was set, {@literal false} if the bound key already exists. {@literal null}
132+
* when used in pipeline / transaction.
130133
* @throws IllegalArgumentException if either {@code value} or {@code timeout} is not present.
131134
* @see <a href="https://redis.io/commands/set">Redis Documentation: SET</a>
132135
* @since 2.1
@@ -146,7 +149,8 @@ default Boolean setIfAbsent(@NonNull V value, @NonNull Duration timeout) {
146149
* Set the bound key to hold the string {@code value} if the bound key is present.
147150
*
148151
* @param value must not be {@literal null}.
149-
* @return command result indicating if the key has been set.
152+
* @return {@literal true} if the value was set, {@literal false} if the bound key does not exist. {@literal null}
153+
* when used in pipeline / transaction.
150154
* @throws IllegalArgumentException if {@code value} is not present.
151155
* @see <a href="https://redis.io/commands/set">Redis Documentation: SET</a>
152156
* @since 2.1
@@ -159,7 +163,8 @@ default Boolean setIfAbsent(@NonNull V value, @NonNull Duration timeout) {
159163
* @param value must not be {@literal null}.
160164
* @param timeout the key expiration timeout.
161165
* @param unit must not be {@literal null}.
162-
* @return command result indicating if the key has been set.
166+
* @return {@literal true} if the value was set, {@literal false} if the bound key does not exist. {@literal null}
167+
* when used in pipeline / transaction.
163168
* @throws IllegalArgumentException if either {@code value} or {@code timeout} is not present.
164169
* @see <a href="https://redis.io/commands/set">Redis Documentation: SET</a>
165170
* @since 2.1
@@ -171,7 +176,8 @@ default Boolean setIfAbsent(@NonNull V value, @NonNull Duration timeout) {
171176
*
172177
* @param value must not be {@literal null}.
173178
* @param timeout must not be {@literal null}.
174-
* @return {@literal null} when used in pipeline / transaction.
179+
* @return {@literal true} if the value was set, {@literal false} if the bound key does not exist. {@literal null}
180+
* when used in pipeline / transaction.
175181
* @throws IllegalArgumentException if either {@code value} or {@code timeout} is not present.
176182
* @see <a href="https://redis.io/commands/set">Redis Documentation: SET</a>
177183
* @since 2.1

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public interface ReactiveValueOperations<K, V> {
7676
*
7777
* @param key must not be {@literal null}.
7878
* @param value
79+
* @return {@literal true} if the value was set, {@literal false} if {@code key} already exists.
7980
* @see <a href="https://redis.io/commands/set">Redis Documentation: SET</a>
8081
*/
8182
Mono<Boolean> setIfAbsent(K key, V value);
@@ -86,6 +87,7 @@ public interface ReactiveValueOperations<K, V> {
8687
* @param key must not be {@literal null}.
8788
* @param value
8889
* @param timeout must not be {@literal null}.
90+
* @return {@literal true} if the value was set, {@literal false} if {@code key} already exists.
8991
* @since 2.1
9092
* @see <a href="https://redis.io/commands/set">Redis Documentation: SET</a>
9193
*/
@@ -96,6 +98,7 @@ public interface ReactiveValueOperations<K, V> {
9698
*
9799
* @param key must not be {@literal null}.
98100
* @param value
101+
* @return {@literal true} if the value was set, {@literal false} if {@code key} does not exist.
99102
* @see <a href="https://redis.io/commands/set">Redis Documentation: SET</a>
100103
*/
101104
Mono<Boolean> setIfPresent(K key, V value);
@@ -106,6 +109,7 @@ public interface ReactiveValueOperations<K, V> {
106109
* @param key must not be {@literal null}.
107110
* @param value
108111
* @param timeout must not be {@literal null}.
112+
* @return {@literal true} if the value was set, {@literal false} if {@code key} does not exist.
109113
* @since 2.1
110114
* @see <a href="https://redis.io/commands/set">Redis Documentation: SET</a>
111115
*/
@@ -124,6 +128,8 @@ public interface ReactiveValueOperations<K, V> {
124128
* not exist.
125129
*
126130
* @param map must not be {@literal null}.
131+
* @return {@literal true} if all keys were set, {@literal false} if at least one key already exists, in which case
132+
* no key is set.
127133
* @see <a href="https://redis.io/commands/msetnx">Redis Documentation: MSETNX</a>
128134
*/
129135
Mono<Boolean> multiSetIfAbsent(Map<? extends K, ? extends V> map);

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ default void set(@NonNull K key, @NonNull V value, @NonNull Duration timeout) {
118118
*
119119
* @param key must not be {@literal null}.
120120
* @param value must not be {@literal null}.
121-
* @return {@literal null} when used in pipeline / transaction.
121+
* @return {@literal true} if the value was set, {@literal false} if {@code key} already exists. {@literal null}
122+
* when used in pipeline / transaction.
122123
* @see <a href="https://redis.io/commands/set">Redis Documentation: SET</a>
123124
*/
124125
Boolean setIfAbsent(@NonNull K key, @NonNull V value);
@@ -130,7 +131,8 @@ default void set(@NonNull K key, @NonNull V value, @NonNull Duration timeout) {
130131
* @param value must not be {@literal null}.
131132
* @param timeout the key expiration timeout.
132133
* @param unit must not be {@literal null}.
133-
* @return {@literal null} when used in pipeline / transaction.
134+
* @return {@literal true} if the value was set, {@literal false} if {@code key} already exists. {@literal null}
135+
* when used in pipeline / transaction.
134136
* @since 2.1
135137
* @see <a href="https://redis.io/commands/set">Redis Documentation: SET</a>
136138
*/
@@ -142,7 +144,8 @@ default void set(@NonNull K key, @NonNull V value, @NonNull Duration timeout) {
142144
* @param key must not be {@literal null}.
143145
* @param value must not be {@literal null}.
144146
* @param timeout must not be {@literal null}.
145-
* @return {@literal null} when used in pipeline / transaction.
147+
* @return {@literal true} if the value was set, {@literal false} if {@code key} already exists. {@literal null}
148+
* when used in pipeline / transaction.
146149
* @throws IllegalArgumentException if either {@code key}, {@code value} or {@code timeout} is not present.
147150
* @see <a href="https://redis.io/commands/set">Redis Documentation: SET</a>
148151
* @since 2.1
@@ -163,7 +166,8 @@ default Boolean setIfAbsent(@NonNull K key, @NonNull V value, @NonNull Duration
163166
*
164167
* @param key must not be {@literal null}.
165168
* @param value must not be {@literal null}.
166-
* @return command result indicating if the key has been set.
169+
* @return {@literal true} if the value was set, {@literal false} if {@code key} does not exist. {@literal null}
170+
* when used in pipeline / transaction.
167171
* @throws IllegalArgumentException if either {@code key} or {@code value} is not present.
168172
* @see <a href="https://redis.io/commands/set">Redis Documentation: SET</a>
169173
* @since 2.1
@@ -177,7 +181,8 @@ default Boolean setIfAbsent(@NonNull K key, @NonNull V value, @NonNull Duration
177181
* @param value must not be {@literal null}.
178182
* @param timeout the key expiration timeout.
179183
* @param unit must not be {@literal null}.
180-
* @return command result indicating if the key has been set.
184+
* @return {@literal true} if the value was set, {@literal false} if {@code key} does not exist. {@literal null}
185+
* when used in pipeline / transaction.
181186
* @throws IllegalArgumentException if either {@code key}, {@code value} or {@code timeout} is not present.
182187
* @see <a href="https://redis.io/commands/set">Redis Documentation: SET</a>
183188
* @since 2.1
@@ -190,7 +195,8 @@ default Boolean setIfAbsent(@NonNull K key, @NonNull V value, @NonNull Duration
190195
* @param key must not be {@literal null}.
191196
* @param value must not be {@literal null}.
192197
* @param timeout must not be {@literal null}.
193-
* @return {@literal null} when used in pipeline / transaction.
198+
* @return {@literal true} if the value was set, {@literal false} if {@code key} does not exist. {@literal null}
199+
* when used in pipeline / transaction.
194200
* @throws IllegalArgumentException if either {@code key}, {@code value} or {@code timeout} is not present.
195201
* @see <a href="https://redis.io/commands/set">Redis Documentation: SET</a>
196202
* @since 2.1
@@ -219,7 +225,8 @@ default Boolean setIfPresent(@NonNull K key, @NonNull V value, @NonNull Duration
219225
* not exist.
220226
*
221227
* @param map must not be {@literal null}.
222-
* @return {@literal null} when used in pipeline / transaction.
228+
* @return {@literal true} if all keys were set, {@literal false} if at least one key already exists, in which case
229+
* no key is set. {@literal null} when used in pipeline / transaction.
223230
* @see <a href="https://redis.io/commands/msetnx">Redis Documentation: MSETNX</a>
224231
*/
225232
Boolean multiSetIfAbsent(Map<? extends @NonNull K, ? extends @NonNull V> map);

0 commit comments

Comments
 (0)