@@ -51,7 +51,28 @@ public interface ReactiveListCommands {
51
51
* @author Christoph Strobl
52
52
*/
53
53
enum Direction {
54
- LEFT , RIGHT
54
+
55
+ LEFT , RIGHT ;
56
+
57
+ /**
58
+ * Alias for {@link Direction#LEFT}.
59
+ *
60
+ * @since 2.6
61
+ * @return
62
+ */
63
+ public static Direction first () {
64
+ return LEFT ;
65
+ }
66
+
67
+ /**
68
+ * Alias for {@link Direction#RIGHT}.
69
+ *
70
+ * @since 2.6
71
+ * @return
72
+ */
73
+ public static Direction last () {
74
+ return RIGHT ;
75
+ }
55
76
}
56
77
57
78
/**
@@ -635,6 +656,189 @@ default Mono<Long> lInsert(ByteBuffer key, Position position, ByteBuffer pivot,
635
656
*/
636
657
Flux <NumericResponse <LInsertCommand , Long >> lInsert (Publisher <LInsertCommand > commands );
637
658
659
+ /**
660
+ * {@code LMOVE} command parameters.
661
+ *
662
+ * @author Mark Paluch
663
+ * @since 2.6
664
+ * @see <a href="https://redis.io/commands/lmove">Redis Documentation: LMOVE</a>
665
+ */
666
+ class LMoveCommand extends KeyCommand {
667
+
668
+ private final @ Nullable ByteBuffer destinationKey ;
669
+ private final @ Nullable Direction from ;
670
+ private final @ Nullable Direction to ;
671
+
672
+ public LMoveCommand (@ Nullable ByteBuffer sourceKey , @ Nullable ByteBuffer destinationKey , @ Nullable Direction from ,
673
+ @ Nullable Direction to ) {
674
+ super (sourceKey );
675
+ this .destinationKey = destinationKey ;
676
+ this .from = from ;
677
+ this .to = to ;
678
+ }
679
+
680
+ /**
681
+ * Creates a new {@link LMoveCommand} given a {@link ByteBuffer sourceKey}.
682
+ *
683
+ * @param sourceKey must not be {@literal null}.
684
+ * @param sourceDirection must not be {@literal null}.
685
+ * @return a new {@link LMoveCommand} for {@link ByteBuffer value}.
686
+ */
687
+ public static LMoveCommand from (ByteBuffer sourceKey , Direction sourceDirection ) {
688
+
689
+ Assert .notNull (sourceKey , "Source key must not be null!" );
690
+ Assert .notNull (sourceDirection , "Direction must not be null!" );
691
+
692
+ return new LMoveCommand (sourceKey , null , sourceDirection , null );
693
+ }
694
+
695
+ /**
696
+ * Applies the {@link ByteBuffer destinationKey}. Constructs a new command instance with all previously configured
697
+ * properties.
698
+ *
699
+ * @param destinationKey must not be {@literal null}.
700
+ * @param to must not be {@literal null}.
701
+ * @return a new {@link LMoveCommand} with {@literal pivot} applied.
702
+ */
703
+ public LMoveCommand to (ByteBuffer destinationKey , Direction destinationDirection ) {
704
+
705
+ Assert .notNull (destinationKey , "Destination key must not be null!" );
706
+ Assert .notNull (destinationDirection , "Direction must not be null!" );
707
+
708
+ return new LMoveCommand (getKey (), destinationKey , from , destinationDirection );
709
+ }
710
+
711
+ /**
712
+ * Applies the {@link Duration timeout}. Constructs a new command instance with all previously configured
713
+ * properties.
714
+ *
715
+ * @param timeout must not be {@literal null}.
716
+ * @return a new {@link LMoveCommand} with {@literal pivot} applied.
717
+ */
718
+ public BLMoveCommand timeout (Duration timeout ) {
719
+
720
+ Assert .notNull (timeout , "Timeout must not be null!" );
721
+
722
+ return new BLMoveCommand (getKey (), destinationKey , from , to , timeout );
723
+ }
724
+
725
+ @ Nullable
726
+ public ByteBuffer getDestinationKey () {
727
+ return destinationKey ;
728
+ }
729
+
730
+ @ Nullable
731
+ public Direction getFrom () {
732
+ return from ;
733
+ }
734
+
735
+ @ Nullable
736
+ public Direction getTo () {
737
+ return to ;
738
+ }
739
+ }
740
+
741
+ /**
742
+ * {@code BLMOVE} command parameters.
743
+ *
744
+ * @author Mark Paluch
745
+ * @since 2.6
746
+ * @see <a href="https://redis.io/commands/blmove">Redis Documentation: BLMOVE</a>
747
+ */
748
+ class BLMoveCommand extends LMoveCommand {
749
+
750
+ private final @ Nullable Duration timeout ;
751
+
752
+ private BLMoveCommand (@ Nullable ByteBuffer sourceKey , @ Nullable ByteBuffer destinationKey , @ Nullable Direction from ,
753
+ @ Nullable Direction to , @ Nullable Duration timeout ) {
754
+ super (sourceKey , destinationKey , from , to );
755
+ this .timeout = timeout ;
756
+ }
757
+
758
+ @ Nullable
759
+ public Duration getTimeout () {
760
+ return timeout ;
761
+ }
762
+ }
763
+
764
+ /**
765
+ * Atomically returns and removes the first/last element (head/tail depending on the {@code from} argument) of the
766
+ * list stored at {@code sourceKey}, and pushes the element at the first/last element (head/tail depending on the
767
+ * {@code to} argument) of the list stored at {@code destinationKey}.
768
+ *
769
+ * @param sourceKey must not be {@literal null}.
770
+ * @param destinationKey must not be {@literal null}.
771
+ * @param from must not be {@literal null}.
772
+ * @param to must not be {@literal null}.
773
+ * @return
774
+ * @since 2.6
775
+ * @see <a href="https://redis.io/commands/lmove">Redis Documentation: LMOVE</a>
776
+ */
777
+ default Mono <ByteBuffer > lMove (ByteBuffer sourceKey , ByteBuffer destinationKey , Direction from , Direction to ) {
778
+
779
+ Assert .notNull (sourceKey , "Source key must not be null!" );
780
+ Assert .notNull (destinationKey , "Destination key must not be null!" );
781
+ Assert .notNull (from , "From direction must not be null!" );
782
+ Assert .notNull (to , "To direction must not be null!" );
783
+
784
+ return lMove (Mono .just (LMoveCommand .from (sourceKey , from ).to (destinationKey , to ))).map (CommandResponse ::getOutput )
785
+ .next ();
786
+ }
787
+
788
+ /**
789
+ * Atomically returns and removes the first/last element (head/tail depending on the {@code from} argument) of the
790
+ * list stored at {@code sourceKey}, and pushes the element at the first/last element (head/tail depending on the
791
+ * {@code to} argument) of the list stored at {@code destinationKey}.
792
+ *
793
+ * @param commands must not be {@literal null}.
794
+ * @return
795
+ * @since 2.6
796
+ * @see <a href="https://redis.io/commands/lmove">Redis Documentation: LMOVE</a>
797
+ */
798
+ Flux <ByteBufferResponse <LMoveCommand >> lMove (Publisher <? extends LMoveCommand > commands );
799
+
800
+ /**
801
+ * Atomically returns and removes the first/last element (head/tail depending on the {@code from} argument) of the
802
+ * list stored at {@code sourceKey}, and pushes the element at the first/last element (head/tail depending on the
803
+ * {@code to} argument) of the list stored at {@code destinationKey}.
804
+ *
805
+ * @param sourceKey must not be {@literal null}.
806
+ * @param destinationKey must not be {@literal null}.
807
+ * @param from must not be {@literal null}.
808
+ * @param to must not be {@literal null}.
809
+ * @param timeout
810
+ * @return
811
+ * @since 2.6
812
+ * @see <a href="https://redis.io/commands/blmove">Redis Documentation: BLMOVE</a>
813
+ */
814
+ default Mono <ByteBuffer > bLMove (ByteBuffer sourceKey , ByteBuffer destinationKey , Direction from , Direction to ,
815
+ Duration timeout ) {
816
+
817
+ Assert .notNull (sourceKey , "Source key must not be null!" );
818
+ Assert .notNull (destinationKey , "Destination key must not be null!" );
819
+ Assert .notNull (from , "From direction must not be null!" );
820
+ Assert .notNull (to , "To direction must not be null!" );
821
+ Assert .notNull (timeout , "Timeout must not be null!" );
822
+ Assert .isTrue (!timeout .isNegative (), "Timeout must not be negative!" );
823
+
824
+ return bLMove (Mono .just (BLMoveCommand .from (sourceKey , from ).to (destinationKey , to ).timeout (timeout )))
825
+ .map (CommandResponse ::getOutput ).next ();
826
+ }
827
+
828
+ /**
829
+ * Atomically returns and removes the first/last element (head/tail depending on the {@code from} argument) of the
830
+ * list stored at {@code sourceKey}, and pushes the element at the first/last element (head/tail depending on the
831
+ * {@code to} argument) of the list stored at {@code destinationKey}.
832
+ * <p/>
833
+ * <b>Blocks connection</b> until element available or {@code timeout} reached.
834
+ *
835
+ * @param commands must not be {@literal null}.
836
+ * @return
837
+ * @since 2.6
838
+ * @see <a href="https://redis.io/commands/blmove">Redis Documentation: BLMOVE</a>
839
+ */
840
+ Flux <ByteBufferResponse <BLMoveCommand >> bLMove (Publisher <BLMoveCommand > commands );
841
+
638
842
/**
639
843
* {@code LSET} command parameters.
640
844
*
0 commit comments