|
23 | 23 | import java.util.SortedSet;
|
24 | 24 | import java.util.concurrent.TimeUnit;
|
25 | 25 |
|
| 26 | +import org.springframework.data.redis.connection.RedisZSetCommands; |
26 | 27 | import org.springframework.data.redis.connection.RedisZSetCommands.Limit;
|
27 | 28 | import org.springframework.data.redis.connection.RedisZSetCommands.Range;
|
28 | 29 | import org.springframework.data.redis.core.BoundZSetOperations;
|
| 30 | +import org.springframework.data.redis.core.RedisOperations; |
29 | 31 | import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
|
30 | 32 |
|
31 | 33 | /**
|
|
41 | 43 | */
|
42 | 44 | public interface RedisZSet<E> extends RedisCollection<E>, Set<E> {
|
43 | 45 |
|
| 46 | + /** |
| 47 | + * Constructs a new {@link RedisZSet} instance with a default score of {@literal 1}. |
| 48 | + * |
| 49 | + * @param key Redis key of this set. |
| 50 | + * @param operations {@link RedisOperations} for the value type of this set. |
| 51 | + * @since 2.6 |
| 52 | + */ |
| 53 | + static <E> RedisZSet<E> create(String key, RedisOperations<String, E> operations) { |
| 54 | + return new DefaultRedisZSet<>(key, operations, 1); |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * Constructs a new {@link RedisZSet} instance. |
| 59 | + * |
| 60 | + * @param key Redis key of this set. |
| 61 | + * @param operations {@link RedisOperations} for the value type of this set. |
| 62 | + * @param defaultScore |
| 63 | + * @since 2.6 |
| 64 | + */ |
| 65 | + static <E> RedisZSet<E> create(String key, RedisOperations<String, E> operations, double defaultScore) { |
| 66 | + return new DefaultRedisZSet<>(key, operations, defaultScore); |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * Create a new {@link RedisZSet} by intersecting this sorted set and {@link RedisZSet} and store result in |
| 71 | + * destination {@code destKey}. |
| 72 | + * |
| 73 | + * @param set must not be {@literal null}. |
| 74 | + * @param destKey must not be {@literal null}. |
| 75 | + * @return a new {@link RedisZSet} pointing at {@code destKey} |
| 76 | + */ |
44 | 77 | RedisZSet<E> intersectAndStore(RedisZSet<?> set, String destKey);
|
45 | 78 |
|
| 79 | + /** |
| 80 | + * Create a new {@link RedisZSet} by intersecting this sorted set and the collection {@link RedisZSet} and store |
| 81 | + * result in destination {@code destKey}. |
| 82 | + * |
| 83 | + * @param sets must not be {@literal null}. |
| 84 | + * @param destKey must not be {@literal null}. |
| 85 | + * @return a new {@link RedisZSet} pointing at {@code destKey} |
| 86 | + */ |
46 | 87 | RedisZSet<E> intersectAndStore(Collection<? extends RedisZSet<?>> sets, String destKey);
|
47 | 88 |
|
| 89 | + /** |
| 90 | + * Create a new {@link RedisZSet} by union this sorted set and {@link RedisZSet} and store result in destination |
| 91 | + * {@code destKey}. |
| 92 | + * |
| 93 | + * @param set must not be {@literal null}. |
| 94 | + * @param destKey must not be {@literal null}. |
| 95 | + * @return a new {@link RedisZSet} pointing at {@code destKey} |
| 96 | + */ |
48 | 97 | RedisZSet<E> unionAndStore(RedisZSet<?> set, String destKey);
|
49 | 98 |
|
| 99 | + /** |
| 100 | + * Create a new {@link RedisZSet} by union this sorted set and the collection {@link RedisZSet} and store result in |
| 101 | + * destination {@code destKey}. |
| 102 | + * |
| 103 | + * @param sets must not be {@literal null}. |
| 104 | + * @param destKey must not be {@literal null}. |
| 105 | + * @return a new {@link RedisZSet} pointing at {@code destKey} |
| 106 | + */ |
50 | 107 | RedisZSet<E> unionAndStore(Collection<? extends RedisZSet<?>> sets, String destKey);
|
51 | 108 |
|
| 109 | + /** |
| 110 | + * Get elements between {@code start} and {@code end} from sorted set. |
| 111 | + * |
| 112 | + * @param start |
| 113 | + * @param end |
| 114 | + * @return |
| 115 | + */ |
52 | 116 | Set<E> range(long start, long end);
|
53 | 117 |
|
| 118 | + /** |
| 119 | + * Get elements in range from {@code start} to {@code end} from sorted set ordered from high to low. |
| 120 | + * |
| 121 | + * @param start |
| 122 | + * @param end |
| 123 | + * @return |
| 124 | + */ |
54 | 125 | Set<E> reverseRange(long start, long end);
|
55 | 126 |
|
56 | 127 | /**
|
@@ -105,29 +176,88 @@ default Set<E> reverseRangeByLex(Range range) {
|
105 | 176 | */
|
106 | 177 | Set<E> reverseRangeByLex(Range range, Limit limit);
|
107 | 178 |
|
| 179 | + /** |
| 180 | + * Get elements where score is between {@code min} and {@code max} from sorted set. |
| 181 | + * |
| 182 | + * @param min |
| 183 | + * @param max |
| 184 | + * @return |
| 185 | + */ |
108 | 186 | Set<E> rangeByScore(double min, double max);
|
109 | 187 |
|
| 188 | + /** |
| 189 | + * Get elements where score is between {@code min} and {@code max} from sorted set ordered from high to low. |
| 190 | + * |
| 191 | + * @param min |
| 192 | + * @param max |
| 193 | + * @return |
| 194 | + */ |
110 | 195 | Set<E> reverseRangeByScore(double min, double max);
|
111 | 196 |
|
| 197 | + /** |
| 198 | + * Get set of {@link RedisZSetCommands.Tuple}s between {@code start} and {@code end} from sorted set. |
| 199 | + * |
| 200 | + * @param start |
| 201 | + * @param end |
| 202 | + * @return |
| 203 | + */ |
112 | 204 | Set<TypedTuple<E>> rangeWithScores(long start, long end);
|
113 | 205 |
|
| 206 | + /** |
| 207 | + * Get set of {@link RedisZSetCommands.Tuple}s in range from {@code start} to {@code end} from sorted set ordered from |
| 208 | + * high to low. |
| 209 | + * |
| 210 | + * @param start |
| 211 | + * @param end |
| 212 | + * @return |
| 213 | + */ |
114 | 214 | Set<TypedTuple<E>> reverseRangeWithScores(long start, long end);
|
115 | 215 |
|
| 216 | + /** |
| 217 | + * Get set of {@link RedisZSetCommands.Tuple}s where score is between {@code min} and {@code max} from sorted set. |
| 218 | + * |
| 219 | + * @param min |
| 220 | + * @param max |
| 221 | + * @return |
| 222 | + */ |
116 | 223 | Set<TypedTuple<E>> rangeByScoreWithScores(double min, double max);
|
117 | 224 |
|
| 225 | + /** |
| 226 | + * Get set of {@link RedisZSetCommands.Tuple}s where score is between {@code min} and {@code max} from sorted set |
| 227 | + * ordered from high to low. |
| 228 | + * |
| 229 | + * @param min |
| 230 | + * @param max |
| 231 | + * @return |
| 232 | + */ |
118 | 233 | Set<TypedTuple<E>> reverseRangeByScoreWithScores(double min, double max);
|
119 | 234 |
|
| 235 | + /** |
| 236 | + * Remove elements in range between {@code start} and {@code end} from sorted set. |
| 237 | + * |
| 238 | + * @param start |
| 239 | + * @param end |
| 240 | + * @return {@code this} set. |
| 241 | + */ |
120 | 242 | RedisZSet<E> remove(long start, long end);
|
121 | 243 |
|
122 | 244 | /**
|
123 | 245 | * Remove all elements in range.
|
124 | 246 | *
|
125 | 247 | * @param range must not be {@literal null}.
|
126 |
| - * @return never {@literal null}. |
| 248 | + * @return {@code this} set. |
127 | 249 | * @since 2.5
|
128 | 250 | */
|
| 251 | + // TODO: Switch to RedisZSet |
129 | 252 | Set<E> removeByLex(Range range);
|
130 | 253 |
|
| 254 | + /** |
| 255 | + * Remove elements with scores between {@code min} and {@code max} from sorted set with the bound key. |
| 256 | + * |
| 257 | + * @param min |
| 258 | + * @param max |
| 259 | + * @return {@code this} set. |
| 260 | + */ |
131 | 261 | RedisZSet<E> removeByScore(double min, double max);
|
132 | 262 |
|
133 | 263 | /**
|
|
0 commit comments