60
60
* @author Dengliming
61
61
* @author Mark John Moreno
62
62
* @author jinkshower
63
+ * @author Jeonggyu Choi
63
64
* @since 2.2
64
65
*/
65
66
public interface ReactiveStreamCommands {
@@ -747,6 +748,25 @@ default Mono<PendingMessages> xPending(ByteBuffer key, String groupName, Range<?
747
748
.map (CommandResponse ::getOutput );
748
749
}
749
750
751
+ /**
752
+ * Obtain detailed information about pending {@link PendingMessage messages} for a given {@link Range} within a
753
+ * {@literal consumer group} and over a given {@link Duration} of idle time.
754
+ *
755
+ * @param key the {@literal key} the stream is stored at. Must not be {@literal null}.
756
+ * @param groupName the name of the {@literal consumer group}. Must not be {@literal null}.
757
+ * @param range the range of messages ids to search within. Must not be {@literal null}.
758
+ * @param count limit the number of results. Must not be {@literal null}.
759
+ * @param idle the minimum idle time to filter pending messages. Must not be {@literal null}.
760
+ * @return pending messages for the given {@literal consumer group} or {@literal null} when used in pipeline /
761
+ * transaction.
762
+ * @see <a href="https://redis.io/commands/xpending">Redis Documentation: xpending</a>
763
+ * @since 3.5
764
+ */
765
+ default Mono <PendingMessages > xPending (ByteBuffer key , String groupName , Range <?> range , Long count , Duration idle ) {
766
+ return xPending (Mono .just (PendingRecordsCommand .pending (key , groupName ).range (range , count ).idle (idle ))).next ()
767
+ .map (CommandResponse ::getOutput );
768
+ }
769
+
750
770
/**
751
771
* Obtain detailed information about pending {@link PendingMessage messages} for a given {@link Range} and
752
772
* {@link Consumer} within a {@literal consumer group}.
@@ -763,6 +783,23 @@ default Mono<PendingMessages> xPending(ByteBuffer key, Consumer consumer, Range<
763
783
return xPending (key , consumer .getGroup (), consumer .getName (), range , count );
764
784
}
765
785
786
+ /**
787
+ * Obtain detailed information about pending {@link PendingMessage messages} for a given {@link Range} and
788
+ * {@link Consumer} within a {@literal consumer group} and over a given {@link Duration} of idle time.
789
+ *
790
+ * @param key the {@literal key} the stream is stored at. Must not be {@literal null}.
791
+ * @param consumer the name of the {@link Consumer}. Must not be {@literal null}.
792
+ * @param range the range of messages ids to search within. Must not be {@literal null}.
793
+ * @param count limit the number of results. Must not be {@literal null}.
794
+ * @param idle the minimum idle time to filter pending messages. Must not be {@literal null}.
795
+ * @return pending messages for the given {@link Consumer} or {@literal null} when used in pipeline / transaction.
796
+ * @see <a href="https://redis.io/commands/xpending">Redis Documentation: xpending</a>
797
+ * @since 3.5
798
+ */
799
+ default Mono <PendingMessages > xPending (ByteBuffer key , Consumer consumer , Range <?> range , Long count , Duration idle ) {
800
+ return xPending (key , consumer .getGroup (), consumer .getName (), range , count , idle );
801
+ }
802
+
766
803
/**
767
804
* Obtain detailed information about pending {@link PendingMessage messages} for a given {@link Range} and
768
805
* {@literal consumer} within a {@literal consumer group}.
@@ -783,6 +820,28 @@ default Mono<PendingMessages> xPending(ByteBuffer key, String groupName, String
783
820
.next ().map (CommandResponse ::getOutput );
784
821
}
785
822
823
+ /**
824
+ * Obtain detailed information about pending {@link PendingMessage messages} for a given {@link Range} and
825
+ * {@literal consumer} within a {@literal consumer group} and over a given {@link Duration} of idle time.
826
+ *
827
+ * @param key the {@literal key} the stream is stored at. Must not be {@literal null}.
828
+ * @param groupName the name of the {@literal consumer group}. Must not be {@literal null}.
829
+ * @param consumerName the name of the {@literal consumer}. Must not be {@literal null}.
830
+ * @param range the range of messages ids to search within. Must not be {@literal null}.
831
+ * @param count limit the number of results. Must not be {@literal null}.
832
+ * @param idle the minimum idle time to filter pending messages. Must not be {@literal null}.
833
+ * @return pending messages for the given {@literal consumer} in given {@literal consumer group} or {@literal null}
834
+ * when used in pipeline / transaction.
835
+ * @see <a href="https://redis.io/commands/xpending">Redis Documentation: xpending</a>
836
+ * @since 3.5
837
+ */
838
+ default Mono <PendingMessages > xPending (ByteBuffer key , String groupName , String consumerName , Range <?> range ,
839
+ Long count , Duration idle ) {
840
+ return xPending (
841
+ Mono .just (PendingRecordsCommand .pending (key , groupName ).consumer (consumerName ).range (range , count ).idle (idle )))
842
+ .next ().map (CommandResponse ::getOutput );
843
+ }
844
+
786
845
/**
787
846
* Obtain detailed information about pending {@link PendingMessage messages} applying given {@link XPendingOptions
788
847
* options}.
@@ -798,6 +857,7 @@ default Mono<PendingMessages> xPending(ByteBuffer key, String groupName, String
798
857
* Value Object holding parameters for obtaining pending messages.
799
858
*
800
859
* @author Christoph Strobl
860
+ * @author Jeonggyu Choi
801
861
* @since 2.3
802
862
*/
803
863
class PendingRecordsCommand extends KeyCommand {
@@ -806,16 +866,18 @@ class PendingRecordsCommand extends KeyCommand {
806
866
private final @ Nullable String consumerName ;
807
867
private final Range <?> range ;
808
868
private final @ Nullable Long count ;
869
+ private final @ Nullable Duration idle ;
809
870
810
871
private PendingRecordsCommand (ByteBuffer key , String groupName , @ Nullable String consumerName , Range <?> range ,
811
- @ Nullable Long count ) {
872
+ @ Nullable Long count , @ Nullable Duration idle ) {
812
873
813
874
super (key );
814
875
815
876
this .groupName = groupName ;
816
877
this .consumerName = consumerName ;
817
878
this .range = range ;
818
879
this .count = count ;
880
+ this .idle = idle ;
819
881
}
820
882
821
883
/**
@@ -826,7 +888,7 @@ private PendingRecordsCommand(ByteBuffer key, String groupName, @Nullable String
826
888
* @return new instance of {@link PendingRecordsCommand}.
827
889
*/
828
890
static PendingRecordsCommand pending (ByteBuffer key , String groupName ) {
829
- return new PendingRecordsCommand (key , groupName , null , Range .unbounded (), null );
891
+ return new PendingRecordsCommand (key , groupName , null , Range .unbounded (), null , null );
830
892
}
831
893
832
894
/**
@@ -841,7 +903,7 @@ public PendingRecordsCommand range(Range<?> range, Long count) {
841
903
Assert .notNull (range , "Range must not be null" );
842
904
Assert .isTrue (count > -1 , "Count must not be negative" );
843
905
844
- return new PendingRecordsCommand (getKey (), groupName , consumerName , range , count );
906
+ return new PendingRecordsCommand (getKey (), groupName , consumerName , range , count , null );
845
907
}
846
908
847
909
/**
@@ -851,7 +913,20 @@ public PendingRecordsCommand range(Range<?> range, Long count) {
851
913
* @return new instance of {@link PendingRecordsCommand}.
852
914
*/
853
915
public PendingRecordsCommand consumer (String consumerName ) {
854
- return new PendingRecordsCommand (getKey (), groupName , consumerName , range , count );
916
+ return new PendingRecordsCommand (getKey (), groupName , consumerName , range , count , idle );
917
+ }
918
+
919
+ /**
920
+ * Append given idle time.
921
+ *
922
+ * @param idle must not be {@literal null}.
923
+ * @return new instance of {@link PendingRecordsCommand}.
924
+ */
925
+ public PendingRecordsCommand idle (Duration idle ) {
926
+
927
+ Assert .notNull (idle , "Idle must not be null" );
928
+
929
+ return new PendingRecordsCommand (getKey (), groupName , consumerName , range , count , idle );
855
930
}
856
931
857
932
public String getGroupName () {
@@ -881,6 +956,14 @@ public Long getCount() {
881
956
return count ;
882
957
}
883
958
959
+ /**
960
+ * @return can be {@literal null}.
961
+ */
962
+ @ Nullable
963
+ public Duration getIdle () {
964
+ return idle ;
965
+ }
966
+
884
967
/**
885
968
* @return {@literal true} if a consumer name is present.
886
969
*/
@@ -894,6 +977,13 @@ public boolean hasConsumer() {
894
977
public boolean isLimited () {
895
978
return count != null ;
896
979
}
980
+
981
+ /**
982
+ * @return {@literal true} if idle is set.
983
+ */
984
+ public boolean hasIdle () {
985
+ return idle != null ;
986
+ }
897
987
}
898
988
899
989
/**
0 commit comments