|
28 | 28 |
|
29 | 29 | import org.reactivestreams.Publisher; |
30 | 30 | import org.springframework.data.redis.connection.BitFieldSubCommands; |
| 31 | +import org.springframework.data.redis.connection.ReactiveNumberCommands; |
31 | 32 | import org.springframework.data.redis.connection.ReactiveStringCommands; |
32 | 33 | import org.springframework.data.redis.connection.RedisStringCommands.SetOption; |
33 | 34 | import org.springframework.data.redis.core.types.Expiration; |
@@ -200,39 +201,39 @@ public Mono<Long> increment(K key) { |
200 | 201 |
|
201 | 202 | Assert.notNull(key, "Key must not be null"); |
202 | 203 |
|
203 | | - return template.doCreateMono(connection -> connection.numberCommands().incr(rawKey(key))); |
| 204 | + return createNumericMono(numberCommands -> numberCommands.incr(rawKey(key))); |
204 | 205 | } |
205 | 206 |
|
206 | 207 | @Override |
207 | 208 | public Mono<Long> increment(K key, long delta) { |
208 | 209 |
|
209 | 210 | Assert.notNull(key, "Key must not be null"); |
210 | 211 |
|
211 | | - return template.doCreateMono(connection -> connection.numberCommands().incrBy(rawKey(key), delta)); |
| 212 | + return createNumericMono(numberCommands -> numberCommands.incrBy(rawKey(key), delta)); |
212 | 213 | } |
213 | 214 |
|
214 | 215 | @Override |
215 | 216 | public Mono<Double> increment(K key, double delta) { |
216 | 217 |
|
217 | 218 | Assert.notNull(key, "Key must not be null"); |
218 | 219 |
|
219 | | - return template.doCreateMono(connection -> connection.numberCommands().incrBy(rawKey(key), delta)); |
| 220 | + return createNumericMono(numberCommands -> numberCommands.incrBy(rawKey(key), delta)); |
220 | 221 | } |
221 | 222 |
|
222 | 223 | @Override |
223 | 224 | public Mono<Long> decrement(K key) { |
224 | 225 |
|
225 | 226 | Assert.notNull(key, "Key must not be null"); |
226 | 227 |
|
227 | | - return template.doCreateMono(connection -> connection.numberCommands().decr(rawKey(key))); |
| 228 | + return createNumericMono(numberCommands -> numberCommands.decr(rawKey(key))); |
228 | 229 | } |
229 | 230 |
|
230 | 231 | @Override |
231 | 232 | public Mono<Long> decrement(K key, long delta) { |
232 | 233 |
|
233 | 234 | Assert.notNull(key, "Key must not be null"); |
234 | 235 |
|
235 | | - return template.doCreateMono(connection -> connection.numberCommands().decrBy(rawKey(key), delta)); |
| 236 | + return createNumericMono(numberCommands -> numberCommands.decrBy(rawKey(key), delta)); |
236 | 237 | } |
237 | 238 |
|
238 | 239 | @Override |
@@ -303,6 +304,13 @@ public Mono<Boolean> delete(K key) { |
303 | 304 | return template.doCreateMono(connection -> connection.keyCommands().del(rawKey(key))).map(l -> l != 0); |
304 | 305 | } |
305 | 306 |
|
| 307 | + private <T> Mono<T> createNumericMono(Function<ReactiveNumberCommands, Publisher<T>> function) { |
| 308 | + |
| 309 | + Assert.notNull(function, "Function must not be null"); |
| 310 | + |
| 311 | + return template.doCreateMono(connection -> function.apply(connection.numberCommands())); |
| 312 | + } |
| 313 | + |
306 | 314 | private <T> Mono<T> createMono(Function<ReactiveStringCommands, Publisher<T>> function) { |
307 | 315 |
|
308 | 316 | Assert.notNull(function, "Function must not be null"); |
|
0 commit comments