42
42
*
43
43
* @author Christoph Strobl
44
44
* @author Mark Paluch
45
+ * @author dengliming
45
46
* @since 2.0
46
47
*/
47
48
public interface ReactiveListCommands {
@@ -874,12 +875,14 @@ default Mono<Long> lRem(ByteBuffer key, Long count, ByteBuffer value) {
874
875
*/
875
876
class PopCommand extends KeyCommand {
876
877
878
+ private final long count ;
879
+
877
880
private final Direction direction ;
878
881
879
- private PopCommand (@ Nullable ByteBuffer key , Direction direction ) {
882
+ private PopCommand (@ Nullable ByteBuffer key , long count , Direction direction ) {
880
883
881
884
super (key );
882
-
885
+ this . count = count ;
883
886
this .direction = direction ;
884
887
}
885
888
@@ -889,7 +892,7 @@ private PopCommand(@Nullable ByteBuffer key, Direction direction) {
889
892
* @return a new {@link PopCommand} for right push ({@literal RPOP}).
890
893
*/
891
894
public static PopCommand right () {
892
- return new PopCommand (null , Direction .RIGHT );
895
+ return new PopCommand (null , 0 , Direction .RIGHT );
893
896
}
894
897
895
898
/**
@@ -898,7 +901,7 @@ public static PopCommand right() {
898
901
* @return a new {@link PopCommand} for right push ({@literal LPOP}).
899
902
*/
900
903
public static PopCommand left () {
901
- return new PopCommand (null , Direction .LEFT );
904
+ return new PopCommand (null , 0 , Direction .LEFT );
902
905
}
903
906
904
907
/**
@@ -911,7 +914,17 @@ public PopCommand from(ByteBuffer key) {
911
914
912
915
Assert .notNull (key , "Key must not be null!" );
913
916
914
- return new PopCommand (key , direction );
917
+ return new PopCommand (key , count , direction );
918
+ }
919
+
920
+ /**
921
+ * Applies the {@literal key}. Constructs a new command instance with all previously configured properties.
922
+ *
923
+ * @param count
924
+ * @return a new {@link LSetCommand} with {@literal value} applied.
925
+ */
926
+ public PopCommand count (long count ) {
927
+ return new PopCommand (getKey (), count , direction );
915
928
}
916
929
917
930
/**
@@ -920,6 +933,10 @@ public PopCommand from(ByteBuffer key) {
920
933
public Direction getDirection () {
921
934
return direction ;
922
935
}
936
+
937
+ public long getCount () {
938
+ return count ;
939
+ }
923
940
}
924
941
925
942
/**
@@ -936,6 +953,21 @@ default Mono<ByteBuffer> lPop(ByteBuffer key) {
936
953
return pop (Mono .just (PopCommand .left ().from (key ))).next ().map (ByteBufferResponse ::getOutput );
937
954
}
938
955
956
+ /**
957
+ * Removes and returns first element in list stored at {@literal key}.
958
+ *
959
+ * @param key must not be {@literal null}.
960
+ * @param count
961
+ * @return
962
+ * @see <a href="https://redis.io/commands/lpop">Redis Documentation: LPOP</a>
963
+ */
964
+ default Flux <ByteBuffer > lPop (ByteBuffer key , long count ) {
965
+
966
+ Assert .notNull (key , "Key must not be null!" );
967
+
968
+ return popList (Mono .just (PopCommand .left ().from (key ).count (count ))).flatMap (CommandResponse ::getOutput );
969
+ }
970
+
939
971
/**
940
972
* Removes and returns last element in list stored at {@literal key}.
941
973
*
@@ -950,6 +982,21 @@ default Mono<ByteBuffer> rPop(ByteBuffer key) {
950
982
return pop (Mono .just (PopCommand .right ().from (key ))).next ().map (ByteBufferResponse ::getOutput );
951
983
}
952
984
985
+ /**
986
+ * Removes and returns last element in list stored at {@literal key}.
987
+ *
988
+ * @param key must not be {@literal null}.
989
+ * @param count
990
+ * @return
991
+ * @see <a href="https://redis.io/commands/rpop">Redis Documentation: RPOP</a>
992
+ */
993
+ default Flux <ByteBuffer > rPop (ByteBuffer key , long count ) {
994
+
995
+ Assert .notNull (key , "Key must not be null!" );
996
+
997
+ return popList (Mono .just (PopCommand .right ().from (key ).count (count ))).flatMap (CommandResponse ::getOutput );
998
+ }
999
+
953
1000
/**
954
1001
* Removes and returns last element in list stored at {@link KeyCommand#getKey()}
955
1002
*
@@ -960,6 +1007,16 @@ default Mono<ByteBuffer> rPop(ByteBuffer key) {
960
1007
*/
961
1008
Flux <ByteBufferResponse <PopCommand >> pop (Publisher <PopCommand > commands );
962
1009
1010
+ /**
1011
+ * Removes and returns last element in list stored at {@link KeyCommand#getKey()}
1012
+ *
1013
+ * @param commands must not be {@literal null}.
1014
+ * @return
1015
+ * @see <a href="https://redis.io/commands/lpop">Redis Documentation: LPOP</a>
1016
+ * @see <a href="https://redis.io/commands/rpop">Redis Documentation: RPOP</a>
1017
+ */
1018
+ Flux <CommandResponse <PopCommand , Flux <ByteBuffer >>> popList (Publisher <PopCommand > commands );
1019
+
963
1020
/**
964
1021
* @author Christoph Strobl
965
1022
* @see <a href="https://redis.io/commands/blpop">Redis Documentation: BLPOP</a>
0 commit comments