15
15
*/
16
16
package org .springframework .data .redis .connection ;
17
17
18
+ import java .time .Duration ;
18
19
import java .util .List ;
19
20
import java .util .Map ;
20
21
import java .util .Set ;
@@ -253,37 +254,73 @@ public interface RedisHashCommands {
253
254
Long hStrLen (byte [] key , byte [] field );
254
255
255
256
/**
256
- * Set time to live for given {@code field } in seconds.
257
+ * Set time to live for given {@code fields } in seconds.
257
258
*
258
259
* @param key must not be {@literal null}.
259
- * @param seconds the amount of time after which the key will be expired in seconds, must not be {@literal null}.
260
+ * @param seconds the amount of time after which the fields will be expired in seconds, must not be {@literal null}.
260
261
* @param fields must not be {@literal null}.
261
262
* @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted
262
263
* already due to expiration, or provided expiry interval is 0; {@code 1} indicating expiration time is set/updated;
263
264
* {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not met);
264
265
* {@code -2} indicating there is no such field; {@literal null} when used in pipeline / transaction.
265
266
* @see <a href="https://redis.io/docs/latest/commands/hexpire/">Redis Documentation: HEXPIRE</a>
266
- * @since 3.4
267
+ * @since 3.5
267
268
*/
268
269
@ Nullable
269
270
List <Long > hExpire (byte [] key , long seconds , byte []... fields );
270
271
271
272
/**
272
- * Set time to live for given {@code field} in milliseconds .
273
+ * Set time to live for given {@code fields} .
273
274
*
274
275
* @param key must not be {@literal null}.
275
- * @param millis the amount of time after which the key will be expired in milliseconds, must not be {@literal null}.
276
+ * @param ttl the amount of time after which the fields will be expired in {@link Duration#toSeconds() seconds} precision, must not be {@literal null}.
277
+ * @param fields must not be {@literal null}.
278
+ * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted
279
+ * already due to expiration, or provided expiry interval is 0; {@code 1} indicating expiration time is set/updated;
280
+ * {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not met);
281
+ * {@code -2} indicating there is no such field; {@literal null} when used in pipeline / transaction.
282
+ * @see <a href="https://redis.io/docs/latest/commands/hexpire/">Redis Documentation: HEXPIRE</a>
283
+ * @since 3.5
284
+ */
285
+ @ Nullable
286
+ default List <Long > hExpire (byte [] key , Duration ttl , byte []... fields ) {
287
+ return hExpire (key , ttl .toSeconds (), fields );
288
+ }
289
+
290
+ /**
291
+ * Set time to live for given {@code fields} in milliseconds.
292
+ *
293
+ * @param key must not be {@literal null}.
294
+ * @param millis the amount of time after which the fields will be expired in milliseconds, must not be {@literal null}.
276
295
* @param fields must not be {@literal null}.
277
296
* @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted
278
297
* already due to expiration, or provided expiry interval is 0; {@code 1} indicating expiration time is set/updated;
279
298
* {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not met);
280
299
* {@code -2} indicating there is no such field; {@literal null} when used in pipeline / transaction.
281
300
* @see <a href="https://redis.io/docs/latest/commands/hpexpire/">Redis Documentation: HPEXPIRE</a>
282
- * @since 3.4
301
+ * @since 3.5
283
302
*/
284
303
@ Nullable
285
304
List <Long > hpExpire (byte [] key , long millis , byte []... fields );
286
305
306
+ /**
307
+ * Set time to live for given {@code fields} in milliseconds.
308
+ *
309
+ * @param key must not be {@literal null}.
310
+ * @param ttl the amount of time after which the fields will be expired in {@link Duration#toMillis() milliseconds} precision, must not be {@literal null}.
311
+ * @param fields must not be {@literal null}.
312
+ * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted
313
+ * already due to expiration, or provided expiry interval is 0; {@code 1} indicating expiration time is set/updated;
314
+ * {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not met);
315
+ * {@code -2} indicating there is no such field; {@literal null} when used in pipeline / transaction.
316
+ * @see <a href="https://redis.io/docs/latest/commands/hpexpire/">Redis Documentation: HPEXPIRE</a>
317
+ * @since 3.5
318
+ */
319
+ @ Nullable
320
+ default List <Long > hpExpire (byte [] key , Duration ttl , byte []... fields ) {
321
+ return hpExpire (key , ttl .toMillis (), fields );
322
+ }
323
+
287
324
/**
288
325
* Set the expiration for given {@code field} as a {@literal UNIX} timestamp.
289
326
*
@@ -295,7 +332,7 @@ public interface RedisHashCommands {
295
332
* set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not
296
333
* met); {@code -2} indicating there is no such field; {@literal null} when used in pipeline / transaction.
297
334
* @see <a href="https://redis.io/docs/latest/commands/hexpireat/">Redis Documentation: HEXPIREAT</a>
298
- * @since 3.4
335
+ * @since 3.5
299
336
*/
300
337
@ Nullable
301
338
List <Long > hExpireAt (byte [] key , long unixTime , byte []... fields );
@@ -311,7 +348,7 @@ public interface RedisHashCommands {
311
348
* set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not
312
349
* met); {@code -2} indicating there is no such field; {@literal null} when used in pipeline / transaction.
313
350
* @see <a href="https://redis.io/docs/latest/commands/hpexpireat/">Redis Documentation: HPEXPIREAT</a>
314
- * @since 3.4
351
+ * @since 3.5
315
352
*/
316
353
@ Nullable
317
354
List <Long > hpExpireAt (byte [] key , long unixTimeInMillis , byte []... fields );
@@ -325,27 +362,27 @@ public interface RedisHashCommands {
325
362
* {@code -1} field has no expiration time to be removed; {@code -2} indicating there is no such field;
326
363
* {@literal null} when used in pipeline / transaction.{@literal null} when used in pipeline / transaction.
327
364
* @see <a href="https://redis.io/docs/latest/commands/hpersist/">Redis Documentation: HPERSIST</a>
328
- * @since 3.4
365
+ * @since 3.5
329
366
*/
330
367
@ Nullable
331
368
List <Long > hPersist (byte [] key , byte []... fields );
332
369
333
370
/**
334
- * Get the time to live for {@code field } in seconds.
371
+ * Get the time to live for {@code fields } in seconds.
335
372
*
336
373
* @param key must not be {@literal null}.
337
374
* @param fields must not be {@literal null}.
338
375
* @return a list of {@link Long} values for each of the fields provided: the time to live in seconds; or a negative value
339
- * to signal an error. The command returns {@code -1} if the key exists but has no associated expiration time.
340
- * The command returns {@code -2} if the key does not exist; {@literal null} when used in pipeline / transaction.
376
+ * to signal an error. The command returns {@code -1} if the field exists but has no associated expiration time.
377
+ * The command returns {@code -2} if the field does not exist; {@literal null} when used in pipeline / transaction.
341
378
* @see <a href="https://redis.io/docs/latest/commands/hexpire/">Redis Documentation: HTTL</a>
342
- * @since 3.4
379
+ * @since 3.5
343
380
*/
344
381
@ Nullable
345
382
List <Long > hTtl (byte [] key , byte []... fields );
346
383
347
384
/**
348
- * Get the time to live for {@code field } in and convert it to the given {@link TimeUnit}.
385
+ * Get the time to live for {@code fields } in and convert it to the given {@link TimeUnit}.
349
386
*
350
387
* @param key must not be {@literal null}.
351
388
* @param timeUnit must not be {@literal null}.
@@ -354,8 +391,24 @@ public interface RedisHashCommands {
354
391
* to signal an error. The command returns {@code -1} if the key exists but has no associated expiration time.
355
392
* The command returns {@code -2} if the key does not exist; {@literal null} when used in pipeline / transaction.
356
393
* @see <a href="https://redis.io/docs/latest/commands/hexpire/">Redis Documentation: HTTL</a>
357
- * @since 3.4
394
+ * @since 3.5
358
395
*/
359
396
@ Nullable
397
+ // TODO: this is complete nonsense as it would jeopardize negative values
398
+ // TODO: this should be a List<Map.Entry<byte, Expiration>>
360
399
List <Long > hTtl (byte [] key , TimeUnit timeUnit , byte []... fields );
400
+
401
+ /**
402
+ * Get the time to live for {@code fields} in milliseconds.
403
+ *
404
+ * @param key must not be {@literal null}.
405
+ * @param fields must not be {@literal null}.
406
+ * @return a list of {@link Long} values for each of the fields provided: the time to live in seconds; or a negative value
407
+ * to signal an error. The command returns {@code -1} if the key exists but has no associated expiration time.
408
+ * The command returns {@code -2} if the key does not exist; {@literal null} when used in pipeline / transaction.
409
+ * @see <a href="https://redis.io/docs/latest/commands/hexpire/">Redis Documentation: HTTL</a>
410
+ * @since 3.5
411
+ */
412
+ @ Nullable
413
+ List <Long > hpTtl (byte [] key , byte []... fields );
361
414
}
0 commit comments