|
15 | 15 | */
|
16 | 16 | package org.springframework.data.redis.core;
|
17 | 17 |
|
18 |
| -import java.time.Duration; |
19 |
| -import java.time.Instant; |
| 18 | +import java.util.Arrays; |
20 | 19 | import java.util.Collection;
|
21 | 20 | import java.util.List;
|
22 | 21 | import java.util.Map;
|
23 | 22 | import java.util.Set;
|
24 |
| -import java.util.concurrent.TimeUnit; |
25 | 23 |
|
26 |
| -import org.springframework.data.redis.connection.Hash.FieldExpirationOptions; |
27 |
| -import org.springframework.data.redis.core.types.Expiration; |
28 |
| -import org.springframework.data.redis.core.types.Expirations; |
29 | 24 | import org.springframework.lang.Nullable;
|
30 | 25 |
|
31 | 26 | /**
|
@@ -160,88 +155,6 @@ public interface BoundHashOperations<H, HK, HV> extends BoundKeyOperations<H> {
|
160 | 155 | @Nullable
|
161 | 156 | Long lengthOfValue(HK hashKey);
|
162 | 157 |
|
163 |
| - default ExpireChanges<HK> expire(Expiration expiration, Collection<HK> hashKeys) { |
164 |
| - return expire(expiration, FieldExpirationOptions.none(), hashKeys); |
165 |
| - } |
166 |
| - |
167 |
| - ExpireChanges<HK> expire(Expiration expiration, FieldExpirationOptions options, Collection<HK> hashKeys); |
168 |
| - |
169 |
| - /** |
170 |
| - * Set time to live for given {@code hashKey} . |
171 |
| - * |
172 |
| - * @param timeout the amount of time after which the key will be expired, must not be {@literal null}. |
173 |
| - * @param hashKeys must not be {@literal null}. |
174 |
| - * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is |
175 |
| - * deleted already due to expiration, or provided expiry interval is 0; {@code 1} indicating expiration time |
176 |
| - * is set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition |
177 |
| - * is not met); {@code -2} indicating there is no such field; {@literal null} when used in pipeline / |
178 |
| - * transaction. |
179 |
| - * @throws IllegalArgumentException if the timeout is {@literal null}. |
180 |
| - * @see <a href="https://redis.io/docs/latest/commands/hexpire/">Redis Documentation: HEXPIRE</a> |
181 |
| - * @since 3.5 |
182 |
| - */ |
183 |
| - @Nullable |
184 |
| - ExpireChanges<HK> expire(Duration timeout, Collection<HK> hashKeys); |
185 |
| - |
186 |
| - /** |
187 |
| - * Set the expiration for given {@code hashKey} as a {@literal date} timestamp. |
188 |
| - * |
189 |
| - * @param expireAt must not be {@literal null}. |
190 |
| - * @param hashKeys must not be {@literal null}. |
191 |
| - * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is |
192 |
| - * deleted already due to expiration, or provided expiry interval is in the past; {@code 1} indicating |
193 |
| - * expiration time is set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | |
194 |
| - * GT | LT condition is not met); {@code -2} indicating there is no such field; {@literal null} when used in |
195 |
| - * pipeline / transaction. |
196 |
| - * @throws IllegalArgumentException if the instant is {@literal null} or too large to represent as a {@code Date}. |
197 |
| - * @see <a href="https://redis.io/docs/latest/commands/hexpireat/">Redis Documentation: HEXPIRE</a> |
198 |
| - * @since 3.5 |
199 |
| - */ |
200 |
| - @Nullable |
201 |
| - ExpireChanges<HK> expireAt(Instant expireAt, Collection<HK> hashKeys); |
202 |
| - |
203 |
| - /** |
204 |
| - * Remove the expiration from given {@code hashKey} . |
205 |
| - * |
206 |
| - * @param hashKeys must not be {@literal null}. |
207 |
| - * @return a list of {@link Long} values for each of the fields provided: {@code 1} indicating expiration time is |
208 |
| - * removed; {@code -1} field has no expiration time to be removed; {@code -2} indicating there is no such |
209 |
| - * field; {@literal null} when used in pipeline / transaction. |
210 |
| - * @see <a href="https://redis.io/docs/latest/commands/hpersist/">Redis Documentation: HPERSIST</a> |
211 |
| - * @since 3.5 |
212 |
| - */ |
213 |
| - @Nullable |
214 |
| - ExpireChanges<HK> persist(Collection<HK> hashKeys); |
215 |
| - |
216 |
| - /** |
217 |
| - * Get the time to live for {@code hashKey} in seconds. |
218 |
| - * |
219 |
| - * @param hashKeys must not be {@literal null}. |
220 |
| - * @return a list of {@link Long} values for each of the fields provided: the time to live in seconds; or a negative |
221 |
| - * value to signal an error. The command returns {@code -1} if the key exists but has no associated expiration |
222 |
| - * time. The command returns {@code -2} if the key does not exist; {@literal null} when used in pipeline / |
223 |
| - * transaction. |
224 |
| - * @see <a href="https://redis.io/docs/latest/commands/httl/">Redis Documentation: HTTL</a> |
225 |
| - * @since 3.5 |
226 |
| - */ |
227 |
| - @Nullable |
228 |
| - Expirations<HK> getTimeToLive(Collection<HK> hashKeys); |
229 |
| - |
230 |
| - /** |
231 |
| - * Get the time to live for {@code hashKey} and convert it to the given {@link TimeUnit}. |
232 |
| - * |
233 |
| - * @param timeUnit must not be {@literal null}. |
234 |
| - * @param hashKeys must not be {@literal null}. |
235 |
| - * @return a list of {@link Long} values for each of the fields provided: the time to live in seconds; or a negative |
236 |
| - * value to signal an error. The command returns {@code -1} if the key exists but has no associated expiration |
237 |
| - * time. The command returns {@code -2} if the key does not exist; {@literal null} when used in pipeline / |
238 |
| - * transaction. |
239 |
| - * @see <a href="https://redis.io/docs/latest/commands/httl/">Redis Documentation: HTTL</a> |
240 |
| - * @since 3.5 |
241 |
| - */ |
242 |
| - @Nullable |
243 |
| - Expirations<HK> getTimeToLive(TimeUnit timeUnit, Collection<HK> hashKeys); |
244 |
| - |
245 | 158 | /**
|
246 | 159 | * Get size of hash at the bound key.
|
247 | 160 | *
|
@@ -302,8 +215,45 @@ default ExpireChanges<HK> expire(Expiration expiration, Collection<HK> hashKeys)
|
302 | 215 | */
|
303 | 216 | Cursor<Map.Entry<HK, HV>> scan(ScanOptions options);
|
304 | 217 |
|
| 218 | + /** |
| 219 | + * Returns a bound operations object to perform operations on the hash field expiration for all hash fields at the |
| 220 | + * bound {@code key}. Operations on the expiration object obtain keys at the time of invoking any expiration |
| 221 | + * operation. |
| 222 | + * |
| 223 | + * @return the bound operations object to perform operations on the hash field expiration. |
| 224 | + * @since 3.5 |
| 225 | + */ |
| 226 | + default BoundHashFieldExpirationOperations<HK> expiration() { |
| 227 | + return new DefaultBoundHashFieldExpirationOperations<>(getOperations().opsForHash(), getKey(), this::keys); |
| 228 | + } |
| 229 | + |
| 230 | + /** |
| 231 | + * Returns a bound operations object to perform operations on the hash field expiration for all hash fields at the |
| 232 | + * bound {@code key} for the given hash fields. |
| 233 | + * |
| 234 | + * @param hashFields collection of hash fields to operate on. |
| 235 | + * @return the bound operations object to perform operations on the hash field expiration. |
| 236 | + * @since 3.5 |
| 237 | + */ |
| 238 | + default BoundHashFieldExpirationOperations<HK> expiration(HK... hashFields) { |
| 239 | + return expiration(Arrays.asList(hashFields)); |
| 240 | + } |
| 241 | + |
| 242 | + /** |
| 243 | + * Returns a bound operations object to perform operations on the hash field expiration for all hash fields at the |
| 244 | + * bound {@code key} for the given hash fields. |
| 245 | + * |
| 246 | + * @param hashFields collection of hash fields to operate on. |
| 247 | + * @return the bound operations object to perform operations on the hash field expiration. |
| 248 | + * @since 3.5 |
| 249 | + */ |
| 250 | + default BoundHashFieldExpirationOperations<HK> expiration(Collection<HK> hashFields) { |
| 251 | + return new DefaultBoundHashFieldExpirationOperations<>(getOperations().opsForHash(), getKey(), () -> hashFields); |
| 252 | + } |
| 253 | + |
305 | 254 | /**
|
306 | 255 | * @return never {@literal null}.
|
307 | 256 | */
|
308 | 257 | RedisOperations<H, ?> getOperations();
|
| 258 | + |
309 | 259 | }
|
0 commit comments