|
19 | 19 | import reactor.core.publisher.Mono; |
20 | 20 |
|
21 | 21 | import java.nio.ByteBuffer; |
| 22 | +import java.time.Duration; |
22 | 23 | import java.util.ArrayList; |
23 | 24 | import java.util.Arrays; |
24 | 25 | import java.util.Collections; |
|
30 | 31 | import org.springframework.data.redis.connection.ReactiveRedisConnection.CommandResponse; |
31 | 32 | import org.springframework.data.redis.connection.ReactiveRedisConnection.KeyCommand; |
32 | 33 | import org.springframework.data.redis.connection.ReactiveRedisConnection.NumericResponse; |
| 34 | +import org.springframework.data.redis.connection.RedisStreamCommands.XClaimOptions; |
33 | 35 | import org.springframework.data.redis.connection.RedisStreamCommands.XPendingOptions; |
34 | 36 | import org.springframework.data.redis.connection.RedisZSetCommands.Limit; |
35 | 37 | import org.springframework.data.redis.connection.stream.ByteBufferRecord; |
@@ -285,6 +287,112 @@ default Mono<RecordId> xAdd(ByteBufferRecord record) { |
285 | 287 | */ |
286 | 288 | Flux<CommandResponse<AddStreamRecord, RecordId>> xAdd(Publisher<AddStreamRecord> commands); |
287 | 289 |
|
| 290 | +/** |
| 291 | + * Change the ownership of a pending message to the given new {@literal consumer} without increasing the delivered |
| 292 | + * count. |
| 293 | + * |
| 294 | + * @param key the {@literal key} the stream is stored at. |
| 295 | + * @param group the name of the {@literal consumer group}. |
| 296 | + * @param newOwner the name of the new {@literal consumer}. |
| 297 | + * @param options must not be {@literal null}. |
| 298 | + * @return a {@link Flux} emitting {@link RecordId is} that changed user. |
| 299 | + * @see <a href="https://redis.io/commands/xclaim">Redis Documentation: XCLAIM</a> |
| 300 | + * @since 2.3 |
| 301 | + */ |
| 302 | +default Flux<RecordId> xClaimJustId(ByteBuffer key, String group, String newOwner, XClaimOptions options) { |
| 303 | + |
| 304 | +return xClaimJustId(Mono.just(new XClaimCommand(key, group, newOwner, options))).next() |
| 305 | +.flatMapMany(CommandResponse::getOutput); |
| 306 | +} |
| 307 | + |
| 308 | +/** |
| 309 | + * Change the ownership of a pending message to the given new {@literal consumer} without increasing the delivered |
| 310 | + * count. |
| 311 | + * |
| 312 | + * @param commands must not be {@literal null}. |
| 313 | + * @return a {@link Flux} emitting {@link RecordId is} that changed user. |
| 314 | + * @see <a href="https://redis.io/commands/xclaim">Redis Documentation: XCLAIM</a> |
| 315 | + * @since 2.3 |
| 316 | + */ |
| 317 | +Flux<CommandResponse<XClaimCommand, Flux<RecordId>>> xClaimJustId(Publisher<XClaimCommand> commands); |
| 318 | + |
| 319 | +/** |
| 320 | + * Change the ownership of a pending message to the given new {@literal consumer}. |
| 321 | + * |
| 322 | + * @param key the {@literal key} the stream is stored at. |
| 323 | + * @param group the name of the {@literal consumer group}. |
| 324 | + * @param newOwner the name of the new {@literal consumer}. |
| 325 | + * @param minIdleTime must not be {@literal null}. |
| 326 | + * @param recordIds must not be {@literal null}. |
| 327 | + * @return a {@link Flux} emitting {@link ByteBufferRecord} that changed user. |
| 328 | + * @see <a href="https://redis.io/commands/xclaim">Redis Documentation: XCLAIM</a> |
| 329 | + * @since 2.3 |
| 330 | + */ |
| 331 | +default Flux<ByteBufferRecord> xClaim(ByteBuffer key, String group, String newOwner, Duration minIdleTime, |
| 332 | +RecordId... recordIds) { |
| 333 | + |
| 334 | +return xClaim(key, group, newOwner, XClaimOptions.minIdle(minIdleTime).ids(recordIds)); |
| 335 | +} |
| 336 | + |
| 337 | +/** |
| 338 | + * Change the ownership of a pending message to the given new {@literal consumer}. |
| 339 | + * |
| 340 | + * @param key the {@literal key} the stream is stored at. |
| 341 | + * @param group the name of the {@literal consumer group}. |
| 342 | + * @param newOwner the name of the new {@literal consumer}. |
| 343 | + * @param options must not be {@literal null}. |
| 344 | + * @return a {@link Flux} emitting {@link ByteBufferRecord} that changed user. |
| 345 | + * @see <a href="https://redis.io/commands/xclaim">Redis Documentation: XCLAIM</a> |
| 346 | + * @since 2.3 |
| 347 | + */ |
| 348 | +default Flux<ByteBufferRecord> xClaim(ByteBuffer key, String group, String newOwner, XClaimOptions options) { |
| 349 | + |
| 350 | +return xClaim(Mono.just(new XClaimCommand(key, group, newOwner, options))).next() |
| 351 | +.flatMapMany(CommandResponse::getOutput); |
| 352 | +} |
| 353 | + |
| 354 | +/** |
| 355 | + * Change the ownership of a pending message to the given new {@literal consumer}. |
| 356 | + * |
| 357 | + * @param commands must not be {@literal null}. |
| 358 | + * @return |
| 359 | + * @see <a href="https://redis.io/commands/xclaim">Redis Documentation: XCLAIM</a> |
| 360 | + * @since 2.3 |
| 361 | + */ |
| 362 | +Flux<CommandResponse<XClaimCommand, Flux<ByteBufferRecord>>> xClaim(Publisher<XClaimCommand> commands); |
| 363 | + |
| 364 | +/** |
| 365 | + * {@code XCLAIM} command parameters. |
| 366 | + * |
| 367 | + * @see <a href="https://redis.io/commands/xclaim">Redis Documentation: XCLAIM</a> |
| 368 | + */ |
| 369 | +class XClaimCommand extends KeyCommand { |
| 370 | + |
| 371 | +private final String groupName; |
| 372 | +private final String consumerName; |
| 373 | +private final XClaimOptions options; |
| 374 | + |
| 375 | +private XClaimCommand(@Nullable ByteBuffer key, String groupName, String consumerName, XClaimOptions options) { |
| 376 | + |
| 377 | +super(key); |
| 378 | +this.groupName = groupName; |
| 379 | +this.consumerName = consumerName; |
| 380 | +this.options = options; |
| 381 | +} |
| 382 | + |
| 383 | +public XClaimOptions getOptions() { |
| 384 | +return options; |
| 385 | +} |
| 386 | + |
| 387 | +public String getConsumerName() { |
| 388 | +return consumerName; |
| 389 | +} |
| 390 | + |
| 391 | +public String getGroupName() { |
| 392 | +return groupName; |
| 393 | +} |
| 394 | +} |
| 395 | + |
288 | 396 | /** |
289 | 397 | * {@code XDEL} command parameters. |
290 | 398 | * |
|
0 commit comments