Skip to content

Commit 2a4cf7a

Browse files
Reintroduce and deprecate methods using ZSetCommand.Range.
Provide a smoother upgrade experience. Fix some javadoc along the way. See: #2288 Original Pull Request: #2292
1 parent 21c147d commit 2a4cf7a

File tree

4 files changed

+289
-14
lines changed

4 files changed

+289
-14
lines changed

src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1536,7 +1536,7 @@ default Long lPos(String key, String element) {
15361536
* @return {@literal null} when used in pipeline / transaction.
15371537
* @since 2.4
15381538
* @see <a href="https://redis.io/commands/zlexcount">Redis Documentation: ZLEXCOUNT</a>
1539-
* @see RedisZSetCommands#zLexCount(byte[], Range)
1539+
* @see RedisZSetCommands#zLexCount(byte[], org.springframework.data.domain.Range)
15401540
*/
15411541
@Nullable
15421542
Long zLexCount(String key, org.springframework.data.domain.Range<String> range);
@@ -1926,7 +1926,7 @@ default Set<StringTuple> zUnionWithScores(Aggregate aggregate, int[] weights, St
19261926
* @return
19271927
* @since 1.6
19281928
* @see <a href="https://redis.io/commands/zrangebylex">Redis Documentation: ZRANGEBYLEX</a>
1929-
* @see RedisZSetCommands#zRangeByLex(byte[], Range)
1929+
* @see RedisZSetCommands#zRangeByLex(byte[], org.springframework.data.domain.Range)
19301930
*/
19311931
Set<String> zRangeByLex(String key, org.springframework.data.domain.Range<String> range);
19321932

@@ -1940,7 +1940,7 @@ default Set<StringTuple> zUnionWithScores(Aggregate aggregate, int[] weights, St
19401940
* @return
19411941
* @since 1.6
19421942
* @see <a href="https://redis.io/commands/zrangebylex">Redis Documentation: ZRANGEBYLEX</a>
1943-
* @see RedisZSetCommands#zRangeByLex(byte[], Range, Limit)
1943+
* @see RedisZSetCommands#zRangeByLex(byte[], org.springframework.data.domain.Range, org.springframework.data.redis.connection.Limit)
19441944
*/
19451945
Set<String> zRangeByLex(String key, org.springframework.data.domain.Range<String> range,
19461946
org.springframework.data.redis.connection.Limit limit);
@@ -1966,7 +1966,7 @@ default Set<String> zRevRangeByLex(String key) {
19661966
* @return
19671967
* @since 2.4
19681968
* @see <a href="https://redis.io/commands/zrevrangebylex">Redis Documentation: ZREVRANGEBYLEX</a>
1969-
* @see RedisZSetCommands#zRevRangeByLex(byte[], Range)
1969+
* @see RedisZSetCommands#zRevRangeByLex(byte[], org.springframework.data.domain.Range)
19701970
*/
19711971
default Set<String> zRevRangeByLex(String key, org.springframework.data.domain.Range<String> range) {
19721972
return zRevRangeByLex(key, range, org.springframework.data.redis.connection.Limit.unlimited());
@@ -1982,7 +1982,7 @@ default Set<String> zRevRangeByLex(String key, org.springframework.data.domain.R
19821982
* @return
19831983
* @since 2.4
19841984
* @see <a href="https://redis.io/commands/zrevrangebylex">Redis Documentation: ZREVRANGEBYLEX</a>
1985-
* @see RedisZSetCommands#zRevRangeByLex(byte[], Range, Limit)
1985+
* @see RedisZSetCommands#zRevRangeByLex(byte[], org.springframework.data.domain.Range, org.springframework.data.redis.connection.Limit)
19861986
*/
19871987
Set<String> zRevRangeByLex(String key, org.springframework.data.domain.Range<String> range,
19881988
org.springframework.data.redis.connection.Limit limit);

src/main/java/org/springframework/data/redis/core/BoundZSetOperations.java

+99
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,22 @@ public interface BoundZSetOperations<K, V> extends BoundKeyOperations<K> {
301301
* @return {@literal null} when used in pipeline / transaction.
302302
* @since 2.4
303303
* @see <a href="https://redis.io/commands/zlexcount">Redis Documentation: ZLEXCOUNT</a>
304+
* @deprecated since 3.0. Please use {@link #lexCount(Range)} instead.
305+
*/
306+
@Nullable
307+
@Deprecated(since = "3.0", forRemoval = true)
308+
default Long lexCount(org.springframework.data.redis.connection.RedisZSetCommands.Range range) {
309+
return lexCount(range.toRange());
310+
}
311+
312+
/**
313+
* Count number of elements within sorted set with value between {@code Range#min} and {@code Range#max} applying
314+
* lexicographical ordering.
315+
*
316+
* @param range must not be {@literal null}.
317+
* @return {@literal null} when used in pipeline / transaction.
318+
* @since 3.0
319+
* @see <a href="https://redis.io/commands/zlexcount">Redis Documentation: ZLEXCOUNT</a>
304320
*/
305321
@Nullable
306322
Long lexCount(Range<String> range);
@@ -470,6 +486,21 @@ default TypedTuple<V> popMax(Duration timeout) {
470486
* @return {@literal null} when used in pipeline / transaction.
471487
* @since 2.5
472488
* @see <a href="https://redis.io/commands/zremrangebylex">Redis Documentation: ZREMRANGEBYLEX</a>
489+
* @deprecated since 3.0. Please use {@link #removeRangeByLex(Range)}.
490+
*/
491+
@Nullable
492+
@Deprecated(since = "3.0", forRemoval = true)
493+
default Long removeRangeByLex(org.springframework.data.redis.connection.RedisZSetCommands.Range range) {
494+
return removeRangeByLex(range.toRange());
495+
}
496+
497+
/**
498+
* Remove elements in {@link Range} from sorted set with the bound key.
499+
*
500+
* @param range must not be {@literal null}.
501+
* @return {@literal null} when used in pipeline / transaction.
502+
* @since 3.0
503+
* @see <a href="https://redis.io/commands/zremrangebylex">Redis Documentation: ZREMRANGEBYLEX</a>
473504
*/
474505
@Nullable
475506
Long removeRangeByLex(Range<String> range);
@@ -812,6 +843,22 @@ default Set<TypedTuple<V>> unionWithScores(Collection<K> otherKeys, Aggregate ag
812843
* @return {@literal null} when used in pipeline / transaction.
813844
* @since 1.7
814845
* @see <a href="https://redis.io/commands/zrangebylex">Redis Documentation: ZRANGEBYLEX</a>
846+
* @deprecated since 3.0. Please use {@link #rangeByLex(Range)} instead.
847+
*/
848+
@Nullable
849+
@Deprecated(since = "3.0", forRemoval = true)
850+
default Set<V> rangeByLex(org.springframework.data.redis.connection.RedisZSetCommands.Range range) {
851+
return rangeByLex(range.toRange());
852+
}
853+
854+
/**
855+
* Get all elements with lexicographical ordering with a value between {@link Range#getLowerBound()} and
856+
* {@link Range#getUpperBound()}.
857+
*
858+
* @param range must not be {@literal null}.
859+
* @return {@literal null} when used in pipeline / transaction.
860+
* @since 3.0
861+
* @see <a href="https://redis.io/commands/zrangebylex">Redis Documentation: ZRANGEBYLEX</a>
815862
*/
816863
@Nullable
817864
default Set<V> rangeByLex(Range<String> range) {
@@ -828,6 +875,24 @@ default Set<V> rangeByLex(Range<String> range) {
828875
* @return {@literal null} when used in pipeline / transaction.
829876
* @since 1.7
830877
* @see <a href="https://redis.io/commands/zrangebylex">Redis Documentation: ZRANGEBYLEX</a>
878+
* @deprecated since 3.0. Please use {@link #rangeByLex(Range, Limit)} instead.
879+
*/
880+
@Nullable
881+
@Deprecated(since = "3.0", forRemoval = true)
882+
default Set<V> rangeByLex(org.springframework.data.redis.connection.RedisZSetCommands.Range range, Limit limit) {
883+
return rangeByLex(range.toRange(), limit);
884+
}
885+
886+
/**
887+
* Get all elements {@literal n} elements, where {@literal n = } {@link Limit#getCount()}, starting at
888+
* {@link Limit#getOffset()} with lexicographical ordering having a value between {@link Range#getLowerBound()} and
889+
* {@link Range#getUpperBound()}.
890+
*
891+
* @param range must not be {@literal null}.
892+
* @param limit can be {@literal null}.
893+
* @return {@literal null} when used in pipeline / transaction.
894+
* @since 3.0
895+
* @see <a href="https://redis.io/commands/zrangebylex">Redis Documentation: ZRANGEBYLEX</a>
831896
*/
832897
@Nullable
833898
Set<V> rangeByLex(Range<String> range, Limit limit);
@@ -840,6 +905,22 @@ default Set<V> rangeByLex(Range<String> range) {
840905
* @return {@literal null} when used in pipeline / transaction.
841906
* @since 2.4
842907
* @see <a href="https://redis.io/commands/zrevrangebylex">Redis Documentation: ZREVRANGEBYLEX</a>
908+
* @deprecated since 3.0. Please use {@link #reverseRangeByLex(Range)} instead.
909+
*/
910+
@Nullable
911+
@Deprecated(since = "3.0", forRemoval = true)
912+
default Set<V> reverseRangeByLex(org.springframework.data.redis.connection.RedisZSetCommands.Range range) {
913+
return reverseRangeByLex(range);
914+
}
915+
916+
/**
917+
* Get all elements with reverse lexicographical ordering with a value between {@link Range#getLowerBound()} and
918+
* {@link Range#getUpperBound()}.
919+
*
920+
* @param range must not be {@literal null}.
921+
* @return {@literal null} when used in pipeline / transaction.
922+
* @since 3.0
923+
* @see <a href="https://redis.io/commands/zrevrangebylex">Redis Documentation: ZREVRANGEBYLEX</a>
843924
*/
844925
@Nullable
845926
default Set<V> reverseRangeByLex(Range<String> range) {
@@ -856,6 +937,24 @@ default Set<V> reverseRangeByLex(Range<String> range) {
856937
* @return {@literal null} when used in pipeline / transaction.
857938
* @since 2.4
858939
* @see <a href="https://redis.io/commands/zrevrangebylex">Redis Documentation: ZREVRANGEBYLEX</a>
940+
* @deprecated since 3.0. Please use {@link #reverseRangeByLex(Range, Limit)} instead.
941+
*/
942+
@Nullable
943+
@Deprecated(since = "3.0", forRemoval = true)
944+
default Set<V> reverseRangeByLex(org.springframework.data.redis.connection.RedisZSetCommands.Range range, Limit limit) {
945+
return reverseRangeByLex(range.toRange(), limit);
946+
}
947+
948+
/**
949+
* Get all elements {@literal n} elements, where {@literal n = } {@link Limit#getCount()}, starting at
950+
* {@link Limit#getOffset()} with reverse lexicographical ordering having a value between
951+
* {@link Range#getLowerBound()} and {@link Range#getUpperBound()}.
952+
*
953+
* @param range must not be {@literal null}.
954+
* @param limit can be {@literal null}.
955+
* @return {@literal null} when used in pipeline / transaction.
956+
* @since 3.0
957+
* @see <a href="https://redis.io/commands/zrevrangebylex">Redis Documentation: ZREVRANGEBYLEX</a>
859958
*/
860959
@Nullable
861960
Set<V> reverseRangeByLex(Range<String> range, Limit limit);

src/main/java/org/springframework/data/redis/core/ZSetOperations.java

+120-9
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,23 @@ static <V> TypedTuple<V> of(V value, @Nullable Double score) {
410410
* @return {@literal null} when used in pipeline / transaction.
411411
* @since 2.4
412412
* @see <a href="https://redis.io/commands/zlexcount">Redis Documentation: ZLEXCOUNT</a>
413+
* @deprecated since 3.0. Please use #lexCount(Range) instead.
414+
*/
415+
@Nullable
416+
@Deprecated(since = "3.0", forRemoval = true)
417+
default Long lexCount(K key, org.springframework.data.redis.connection.RedisZSetCommands.Range range) {
418+
return lexCount(key, range.toRange());
419+
}
420+
421+
/**
422+
* Count number of elements within sorted set with value between {@link Range#getLowerBound()} and
423+
* {@link Range#getUpperBound()} applying lexicographical ordering.
424+
*
425+
* @param key must not be {@literal null}.
426+
* @param range must not be {@literal null}.
427+
* @return {@literal null} when used in pipeline / transaction.
428+
* @since 3.0
429+
* @see <a href="https://redis.io/commands/zlexcount">Redis Documentation: ZLEXCOUNT</a>
413430
*/
414431
@Nullable
415432
Long lexCount(K key, Range<String> range);
@@ -593,9 +610,25 @@ default TypedTuple<V> popMax(K key, Duration timeout) {
593610
* @return {@literal null} when used in pipeline / transaction.
594611
* @since 2.5
595612
* @see <a href="https://redis.io/commands/zremrangebylex">Redis Documentation: ZREMRANGEBYLEX</a>
613+
* @deprecated since 3.0. Please use {@link #removeRangeByLex(Object, Range)} instead;
614+
*/
615+
@Nullable
616+
@Deprecated(since = "3.0", forRemoval = true)
617+
default Long removeRangeByLex(K key, org.springframework.data.redis.connection.RedisZSetCommands.Range range) {
618+
return removeRangeByLex(key, range.toRange());
619+
}
620+
621+
/**
622+
* Remove elements in {@link Range} from sorted set with {@literal key}.
623+
*
624+
* @param key must not be {@literal null}.
625+
* @param range must not be {@literal null}.
626+
* @return {@literal null} when used in pipeline / transaction.
627+
* @since 3.0
628+
* @see <a href="https://redis.io/commands/zremrangebylex">Redis Documentation: ZREMRANGEBYLEX</a>
596629
*/
597630
@Nullable
598-
Long removeRangeByLex(K key, org.springframework.data.domain.Range<String> range);
631+
Long removeRangeByLex(K key, Range<String> range);
599632

600633
/**
601634
* Remove elements with scores between {@code min} and {@code max} from sorted set with {@code key}.
@@ -961,53 +994,131 @@ default Long unionAndStore(K key, Collection<K> otherKeys, K destKey, Aggregate
961994

962995
/**
963996
* Get all elements with lexicographical ordering from {@literal ZSET} at {@code key} with a value between
964-
* {@link Range#getMin()} and {@link Range#getMax()}.
997+
* {@link org.springframework.data.redis.connection.RedisZSetCommands.Range#getMin()} and
998+
* {@link org.springframework.data.redis.connection.RedisZSetCommands.Range#getMax()}.
965999
*
9661000
* @param key must not be {@literal null}.
9671001
* @param range must not be {@literal null}.
9681002
* @return {@literal null} when used in pipeline / transaction.
9691003
* @since 1.7
9701004
* @see <a href="https://redis.io/commands/zrangebylex">Redis Documentation: ZRANGEBYLEX</a>
1005+
* @deprecated since 3.0. Please use {@link #rangeByLex(Object, Range)} instead.
1006+
*/
1007+
@Nullable
1008+
@Deprecated(since = "3.0", forRemoval = true)
1009+
default Set<V> rangeByLex(K key, org.springframework.data.redis.connection.RedisZSetCommands.Range range) {
1010+
return rangeByLex(key, range.toRange());
1011+
}
1012+
1013+
/**
1014+
* Get all elements with lexicographical ordering from {@literal ZSET} at {@code key} with a value between
1015+
* {@link Range#getLowerBound()} and {@link Range#getUpperBound()}.
1016+
*
1017+
* @param key must not be {@literal null}.
1018+
* @param range must not be {@literal null}.
1019+
* @return {@literal null} when used in pipeline / transaction.
1020+
* @since 3.0
1021+
* @see <a href="https://redis.io/commands/zrangebylex">Redis Documentation: ZRANGEBYLEX</a>
9711022
*/
9721023
@Nullable
973-
default Set<V> rangeByLex(K key, org.springframework.data.domain.Range<String> range) {
1024+
default Set<V> rangeByLex(K key, Range<String> range) {
9741025
return rangeByLex(key, range, Limit.unlimited());
9751026
}
9761027

9771028
/**
9781029
* Get all elements {@literal n} elements, where {@literal n = } {@link Limit#getCount()}, starting at
9791030
* {@link Limit#getOffset()} with lexicographical ordering from {@literal ZSET} at {@code key} with a value between
980-
* {@link Range#getMin()} and {@link Range#getMax()}.
1031+
* {@link org.springframework.data.redis.connection.RedisZSetCommands.Range#getMin()} and
1032+
* {@link org.springframework.data.redis.connection.RedisZSetCommands.Range#getMax()}.
9811033
*
9821034
* @param key must not be {@literal null}
9831035
* @param range must not be {@literal null}.
9841036
* @param limit can be {@literal null}.
9851037
* @return {@literal null} when used in pipeline / transaction.
9861038
* @since 1.7
9871039
* @see <a href="https://redis.io/commands/zrangebylex">Redis Documentation: ZRANGEBYLEX</a>
1040+
* @deprecated since 3.0. Please use {@link #rangeByLex(Object, Range, Limit)} instead.
1041+
*/
1042+
@Nullable
1043+
@Deprecated(since = "3.0", forRemoval = true)
1044+
default Set<V> rangeByLex(K key, org.springframework.data.redis.connection.RedisZSetCommands.Range range,
1045+
Limit limit) {
1046+
return rangeByLex(key, range.toRange(), limit);
1047+
}
1048+
1049+
/**
1050+
* Get all elements {@literal n} elements, where {@literal n = } {@link Limit#getCount()}, starting at
1051+
* {@link Limit#getOffset()} with lexicographical ordering from {@literal ZSET} at {@code key} with a value between
1052+
* {@link Range#getLowerBound()} and {@link Range#getUpperBound()}.
1053+
*
1054+
* @param key must not be {@literal null}
1055+
* @param range must not be {@literal null}.
1056+
* @param limit can be {@literal null}.
1057+
* @return {@literal null} when used in pipeline / transaction.
1058+
* @since 3.0
1059+
* @see <a href="https://redis.io/commands/zrangebylex">Redis Documentation: ZRANGEBYLEX</a>
9881060
*/
9891061
@Nullable
990-
Set<V> rangeByLex(K key, org.springframework.data.domain.Range<String> range, Limit limit);
1062+
Set<V> rangeByLex(K key, Range<String> range, Limit limit);
9911063

9921064
/**
9931065
* Get all elements with reverse lexicographical ordering from {@literal ZSET} at {@code key} with a value between
994-
* {@link Range#getMin()} and {@link Range#getMax()}.
1066+
* {@link org.springframework.data.redis.connection.RedisZSetCommands.Range#getMin()} and
1067+
* {@link org.springframework.data.redis.connection.RedisZSetCommands.Range#getMax()}.
9951068
*
9961069
* @param key must not be {@literal null}.
9971070
* @param range must not be {@literal null}.
9981071
* @return {@literal null} when used in pipeline / transaction.
9991072
* @since 2.4
10001073
* @see <a href="https://redis.io/commands/zrevrangebylex">Redis Documentation: ZREVRANGEBYLEX</a>
1074+
* @deprecated since 3.0. Please use {@link #reverseRangeByLex(Object, Range)}
1075+
*/
1076+
@Nullable
1077+
@Deprecated(since = "3.0", forRemoval = true)
1078+
default Set<V> reverseRangeByLex(K key, org.springframework.data.redis.connection.RedisZSetCommands.Range range) {
1079+
return reverseRangeByLex(key, range.toRange());
1080+
}
1081+
1082+
/**
1083+
* Get all elements with reverse lexicographical ordering from {@literal ZSET} at {@code key} with a value between
1084+
* {@link Range#getLowerBound()} and {@link Range#getUpperBound()}.
1085+
*
1086+
* @param key must not be {@literal null}.
1087+
* @param range must not be {@literal null}.
1088+
* @return {@literal null} when used in pipeline / transaction.
1089+
* @since 3.0
1090+
* @see <a href="https://redis.io/commands/zrevrangebylex">Redis Documentation: ZREVRANGEBYLEX</a>
10011091
*/
10021092
@Nullable
1003-
default Set<V> reverseRangeByLex(K key, org.springframework.data.domain.Range<String> range) {
1093+
default Set<V> reverseRangeByLex(K key, Range<String> range) {
10041094
return reverseRangeByLex(key, range, Limit.unlimited());
10051095
}
10061096

10071097
/**
10081098
* Get all elements {@literal n} elements, where {@literal n = } {@link Limit#getCount()}, starting at
10091099
* {@link Limit#getOffset()} with reverse lexicographical ordering from {@literal ZSET} at {@code key} with a value
1010-
* between {@link Range#getMin()} and {@link Range#getMax()}.
1100+
* between {@link org.springframework.data.redis.connection.RedisZSetCommands.Range#getMin()} and
1101+
* {@link org.springframework.data.redis.connection.RedisZSetCommands.Range#getMax()}.
1102+
*
1103+
* @param key must not be {@literal null}
1104+
* @param range must not be {@literal null}.
1105+
* @param limit can be {@literal null}.
1106+
* @return {@literal null} when used in pipeline / transaction.
1107+
* @since 2.4
1108+
* @see <a href="https://redis.io/commands/zrevrangebylex">Redis Documentation: ZREVRANGEBYLEX</a>
1109+
* @deprecated since 3.0. Please use {@link #reverseRangeByLex(Object, Range, Limit)} instead.
1110+
*/
1111+
@Nullable
1112+
@Deprecated(since = "3.0", forRemoval = true)
1113+
default Set<V> reverseRangeByLex(K key, org.springframework.data.redis.connection.RedisZSetCommands.Range range,
1114+
Limit limit) {
1115+
return reverseRangeByLex(key, range.toRange(), limit);
1116+
}
1117+
1118+
/**
1119+
* Get all elements {@literal n} elements, where {@literal n = } {@link Limit#getCount()}, starting at
1120+
* {@link Limit#getOffset()} with reverse lexicographical ordering from {@literal ZSET} at {@code key} with a value
1121+
* between {@link Range#getLowerBound()} and {@link Range#getUpperBound()}.
10111122
*
10121123
* @param key must not be {@literal null}
10131124
* @param range must not be {@literal null}.
@@ -1017,7 +1128,7 @@ default Set<V> reverseRangeByLex(K key, org.springframework.data.domain.Range<St
10171128
* @see <a href="https://redis.io/commands/zrevrangebylex">Redis Documentation: ZREVRANGEBYLEX</a>
10181129
*/
10191130
@Nullable
1020-
Set<V> reverseRangeByLex(K key, org.springframework.data.domain.Range<String> range, Limit limit);
1131+
Set<V> reverseRangeByLex(K key, Range<String> range, Limit limit);
10211132

10221133
/**
10231134
* @return never {@literal null}.

0 commit comments

Comments
 (0)