@@ -477,6 +477,142 @@ default Mono<Double> zIncrBy(ByteBuffer key, Number increment, ByteBuffer value)
477
477
*/
478
478
Flux <NumericResponse <ZIncrByCommand , Double >> zIncrBy (Publisher <ZIncrByCommand > commands );
479
479
480
+ /**
481
+ * {@code ZRANDMEMBER} command parameters.
482
+ *
483
+ * @author Mark Paluch
484
+ * @since 2.6
485
+ * @see <a href="https://redis.io/commands/srandmember">Redis Documentation: ZRANDMEMBER</a>
486
+ */
487
+ class ZRandMemberCommand extends KeyCommand {
488
+
489
+ private final long count ;
490
+
491
+ private ZRandMemberCommand (@ Nullable ByteBuffer key , long count ) {
492
+
493
+ super (key );
494
+ this .count = count ;
495
+ }
496
+
497
+ /**
498
+ * Creates a new {@link ZRandMemberCommand} given the number of values to retrieve.
499
+ *
500
+ * @param nrValuesToRetrieve
501
+ * @return a new {@link ZRandMemberCommand} for a number of values to retrieve.
502
+ */
503
+ public static ZRandMemberCommand valueCount (long nrValuesToRetrieve ) {
504
+ return new ZRandMemberCommand (null , nrValuesToRetrieve );
505
+ }
506
+
507
+ /**
508
+ * Creates a new {@link ZRandMemberCommand} to retrieve one random member.
509
+ *
510
+ * @return a new {@link ZRandMemberCommand} to retrieve one random member.
511
+ */
512
+ public static ZRandMemberCommand singleValue () {
513
+ return new ZRandMemberCommand (null , 1 );
514
+ }
515
+
516
+ /**
517
+ * Applies the {@literal key}. Constructs a new command instance with all previously configured properties.
518
+ *
519
+ * @param key must not be {@literal null}.
520
+ * @return a new {@link ZRandMemberCommand} with {@literal key} applied.
521
+ */
522
+ public ZRandMemberCommand from (ByteBuffer key ) {
523
+
524
+ Assert .notNull (key , "Key must not be null!" );
525
+
526
+ return new ZRandMemberCommand (key , count );
527
+ }
528
+
529
+ /**
530
+ * @return
531
+ */
532
+ public long getCount () {
533
+ return count ;
534
+ }
535
+ }
536
+
537
+ /**
538
+ * Get random element from sorted set at {@code key}.
539
+ *
540
+ * @param key must not be {@literal null}.
541
+ * @return
542
+ * @since 2.6
543
+ * @see <a href="https://redis.io/commands/zrandmember">Redis Documentation: ZRANDMEMBER</a>
544
+ */
545
+ default Mono <ByteBuffer > zRandMember (ByteBuffer key ) {
546
+ return zRandMember (Mono .just (ZRandMemberCommand .singleValue ().from (key ))).flatMap (CommandResponse ::getOutput )
547
+ .next ();
548
+ }
549
+
550
+ /**
551
+ * Get {@code count} random elements from sorted set at {@code key}.
552
+ *
553
+ * @param key must not be {@literal null}.
554
+ * @param count if the provided {@code count} argument is positive, return a list of distinct fields, capped either at
555
+ * {@code count} or the set size. If {@code count} is negative, the behavior changes and the command is
556
+ * allowed to return the same value multiple times. In this case, the number of returned values is the
557
+ * absolute value of the specified count.
558
+ * @return
559
+ * @since 2.6
560
+ * @see <a href="https://redis.io/commands/zrandmember">Redis Documentation: ZRANDMEMBER</a>
561
+ */
562
+ default Flux <ByteBuffer > zRandMember (ByteBuffer key , long count ) {
563
+ return zRandMember (Mono .just (ZRandMemberCommand .valueCount (count ).from (key ))).flatMap (CommandResponse ::getOutput );
564
+ }
565
+
566
+ /**
567
+ * Get random elements from sorted set at {@code key}.
568
+ *
569
+ * @param commands must not be {@literal null}.
570
+ * @return
571
+ * @since 2.6
572
+ * @see <a href="https://redis.io/commands/zrandmember">Redis Documentation: ZRANDMEMBER</a>
573
+ */
574
+ Flux <CommandResponse <ZRandMemberCommand , Flux <ByteBuffer >>> zRandMember (Publisher <ZRandMemberCommand > commands );
575
+
576
+ /**
577
+ * Get random element from sorted set at {@code key}.
578
+ *
579
+ * @param key must not be {@literal null}.
580
+ * @return
581
+ * @since 2.6
582
+ * @see <a href="https://redis.io/commands/zrandmember">Redis Documentation: ZRANDMEMBER</a>
583
+ */
584
+ default Mono <Tuple > zRandMemberWithScore (ByteBuffer key ) {
585
+ return zRandMemberWithScore (Mono .just (ZRandMemberCommand .singleValue ().from (key )))
586
+ .flatMap (CommandResponse ::getOutput ).next ();
587
+ }
588
+
589
+ /**
590
+ * Get {@code count} random elements from sorted set at {@code key}.
591
+ *
592
+ * @param key must not be {@literal null}.
593
+ * @param count if the provided {@code count} argument is positive, return a list of distinct fields, capped either at
594
+ * {@code count} or the set size. If {@code count} is negative, the behavior changes and the command is
595
+ * allowed to return the same value multiple times. In this case, the number of returned values is the
596
+ * absolute value of the specified count.
597
+ * @return
598
+ * @since 2.6
599
+ * @see <a href="https://redis.io/commands/zrandmember">Redis Documentation: ZRANDMEMBER</a>
600
+ */
601
+ default Flux <Tuple > zRandMemberWithScore (ByteBuffer key , long count ) {
602
+ return zRandMemberWithScore (Mono .just (ZRandMemberCommand .valueCount (count ).from (key )))
603
+ .flatMap (CommandResponse ::getOutput );
604
+ }
605
+
606
+ /**
607
+ * Get random elements from sorted set at {@code key}.
608
+ *
609
+ * @param commands must not be {@literal null}.
610
+ * @return
611
+ * @since 2.6
612
+ * @see <a href="https://redis.io/commands/zrandmember">Redis Documentation: ZRANDMEMBER</a>
613
+ */
614
+ Flux <CommandResponse <ZRandMemberCommand , Flux <Tuple >>> zRandMemberWithScore (Publisher <ZRandMemberCommand > commands );
615
+
480
616
/**
481
617
* {@code ZRANK}/{@literal ZREVRANK} command parameters.
482
618
*
0 commit comments