From 27dbd4bb35cc431ad0222bf2d287157a2671831a Mon Sep 17 00:00:00 2001 From: Tihomir Krasimirov Mateev Date: Wed, 22 May 2024 16:01:11 +0300 Subject: [PATCH] Implement HPEXPIRE, HPEXPIREAT, HPEXPIRETIME, HTTL and HPTTL (#2857) * Fixes to the hash field expiration functions * Implemented HPEXPIRE, HPEXPIREAT, HPEXPIRETIME, HTTL, HPTTL * Format the files * FIELDS keyword was introduced as per the PRD * Extend tests to include HTTL * Repair unit tests, add new ones for the new commands * Disable failing test, becasue it is very unstable * Modify return value to list of long values, fix cluster logic * Polishing * Polishing - addressed Ali's comments * Polishing: Modified by mistake * Polishing : Addressed Marks' comments --- .../core/AbstractRedisAsyncCommands.java | 92 +++++- .../core/AbstractRedisReactiveCommands.java | 100 ++++++- .../io/lettuce/core/RedisCommandBuilder.java | 117 +++++--- .../api/async/RedisHashAsyncCommands.java | 276 ++++++++++++++--- .../reactive/RedisHashReactiveCommands.java | 278 +++++++++++++++--- .../core/api/sync/RedisHashCommands.java | 278 +++++++++++++++--- .../async/NodeSelectionHashAsyncCommands.java | 276 ++++++++++++++--- .../api/sync/NodeSelectionHashCommands.java | 276 ++++++++++++++--- .../core/output/IntegerListOutput.java | 17 +- .../lettuce/core/protocol/CommandKeyword.java | 2 +- .../io/lettuce/core/protocol/CommandType.java | 2 +- .../coroutines/RedisHashCoroutinesCommands.kt | 277 ++++++++++++++--- .../RedisHashCoroutinesCommandsImpl.kt | 109 +++++-- .../lettuce/core/api/RedisHashCommands.java | 276 ++++++++++++++--- .../core/RedisCommandBuilderUnitTests.java | 82 +++++- .../io/lettuce/core/SslIntegrationTests.java | 44 +-- .../commands/HashCommandIntegrationTests.java | 86 +++--- .../output/IntegerListOutputUnitTests.java | 103 +++++++ 18 files changed, 2252 insertions(+), 439 deletions(-) create mode 100644 src/test/java/io/lettuce/core/output/IntegerListOutputUnitTests.java diff --git a/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java b/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java index 9a37545f49..4749ad984f 100644 --- a/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java +++ b/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java @@ -799,26 +799,94 @@ public RedisFuture expire(K key, Duration seconds, ExpireArgs expireArg } @Override - public RedisFuture hexpire(K key, long seconds, K... fields) { + public RedisFuture> hexpire(K key, long seconds, K... fields) { return hexpire(key, seconds, null, fields); } @Override - public RedisFuture hexpire(K key, long seconds, ExpireArgs expireArgs, K... fields) { + public RedisFuture> hexpire(K key, long seconds, ExpireArgs expireArgs, K... fields) { return dispatch(commandBuilder.hexpire(key, seconds, expireArgs, fields)); } @Override - public RedisFuture hexpire(K key, Duration seconds, K... fields) { + public RedisFuture> hexpire(K key, Duration seconds, K... fields) { return hexpire(key, seconds, null, fields); } @Override - public RedisFuture hexpire(K key, Duration seconds, ExpireArgs expireArgs, K... fields) { + public RedisFuture> hexpire(K key, Duration seconds, ExpireArgs expireArgs, K... fields) { LettuceAssert.notNull(seconds, "Timeout must not be null"); return hexpire(key, seconds.toMillis() / 1000, expireArgs, fields); } + @Override + public RedisFuture> httl(K key, K... fields) { + return dispatch(commandBuilder.httl(key, fields)); + } + + @Override + public RedisFuture> hpexpire(K key, long milliseconds, K... fields) { + return hpexpire(key, milliseconds, null, fields); + } + + @Override + public RedisFuture> hpexpire(K key, long milliseconds, ExpireArgs expireArgs, K... fields) { + return dispatch(commandBuilder.hpexpire(key, milliseconds, expireArgs, fields)); + } + + @Override + public RedisFuture> hpexpire(K key, Duration milliseconds, K... fields) { + return hpexpire(key, milliseconds, null, fields); + } + + @Override + public RedisFuture> hpexpire(K key, Duration milliseconds, ExpireArgs expireArgs, K... fields) { + LettuceAssert.notNull(milliseconds, "Timeout must not be null"); + return hpexpire(key, milliseconds.toMillis(), expireArgs, fields); + } + + @Override + public RedisFuture> hpexpireat(K key, Date timestamp, K... fields) { + return hpexpireat(key, timestamp, null, fields); + } + + @Override + public RedisFuture> hpexpireat(K key, Date timestamp, ExpireArgs expireArgs, K... fields) { + LettuceAssert.notNull(timestamp, "Timestamp must not be null"); + return hpexpireat(key, timestamp.getTime(), expireArgs, fields); + } + + @Override + public RedisFuture> hpexpireat(K key, Instant timestamp, K... fields) { + return hpexpireat(key, timestamp, null, fields); + } + + @Override + public RedisFuture> hpexpireat(K key, Instant timestamp, ExpireArgs expireArgs, K... fields) { + LettuceAssert.notNull(timestamp, "Timestamp must not be null"); + return hpexpireat(key, timestamp.toEpochMilli(), expireArgs, fields); + } + + @Override + public RedisFuture> hpexpireat(K key, long timestamp, K... fields) { + return hpexpireat(key, timestamp, null, fields); + } + + @Override + public RedisFuture> hpexpireat(K key, long timestamp, ExpireArgs expireArgs, K... fields) { + return dispatch(commandBuilder.hpexpireat(key, timestamp, expireArgs, fields)); + } + + @Override + public RedisFuture> hpexpiretime(K key, K... fields) { + return dispatch(commandBuilder.hpexpiretime(key, fields)); + } + + @Override + public RedisFuture> hpttl(K key, K... fields) { + return dispatch(commandBuilder.hpttl(key, fields)); + } + @Override public RedisFuture expireat(K key, long timestamp) { return expireat(key, timestamp, null); @@ -852,34 +920,34 @@ public RedisFuture expireat(K key, Instant timestamp, ExpireArgs expire } @Override - public RedisFuture hexpireat(K key, long timestamp, K... fields) { + public RedisFuture> hexpireat(K key, long timestamp, K... fields) { return hexpireat(key, timestamp, null, fields); } @Override - public RedisFuture hexpireat(K key, long timestamp, ExpireArgs expireArgs, K... fields) { + public RedisFuture> hexpireat(K key, long timestamp, ExpireArgs expireArgs, K... fields) { return dispatch(commandBuilder.hexpireat(key, timestamp, expireArgs, fields)); } @Override - public RedisFuture hexpireat(K key, Date timestamp, K... fields) { + public RedisFuture> hexpireat(K key, Date timestamp, K... fields) { return hexpireat(key, timestamp, null, fields); } @Override - public RedisFuture hexpireat(K key, Date timestamp, ExpireArgs expireArgs, K... fields) { + public RedisFuture> hexpireat(K key, Date timestamp, ExpireArgs expireArgs, K... fields) { LettuceAssert.notNull(timestamp, "Timestamp must not be null"); return hexpireat(key, timestamp.getTime() / 1000, expireArgs, fields); } @Override - public RedisFuture hexpireat(K key, Instant timestamp, K... fields) { + public RedisFuture> hexpireat(K key, Instant timestamp, K... fields) { return hexpireat(key, timestamp, null, fields); } @Override - public RedisFuture hexpireat(K key, Instant timestamp, ExpireArgs expireArgs, K... fields) { + public RedisFuture> hexpireat(K key, Instant timestamp, ExpireArgs expireArgs, K... fields) { LettuceAssert.notNull(timestamp, "Timestamp must not be null"); return hexpireat(key, timestamp.toEpochMilli() / 1000, expireArgs, fields); } @@ -890,7 +958,7 @@ public RedisFuture expiretime(K key) { } @Override - public RedisFuture hexpiretime(K key, K... fields) { + public RedisFuture> hexpiretime(K key, K... fields) { return dispatch(commandBuilder.hexpiretime(key, fields)); } @@ -1553,7 +1621,7 @@ public RedisFuture persist(K key) { } @Override - public RedisFuture hpersist(K key, K... fields) { + public RedisFuture> hpersist(K key, K... fields) { return dispatch(commandBuilder.hpersist(key, fields)); } diff --git a/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java b/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java index 16ae6c5796..fa5630ed71 100644 --- a/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java +++ b/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java @@ -859,22 +859,22 @@ public Mono expire(K key, Duration seconds, ExpireArgs expireArgs) { } @Override - public Mono hexpire(K key, long seconds, K... fields) { + public Flux hexpire(K key, long seconds, K... fields) { return hexpire(key, seconds, null, fields); } @Override - public Mono hexpire(K key, long seconds, ExpireArgs expireArgs, K... fields) { - return createMono(() -> commandBuilder.hexpire(key, seconds, expireArgs, fields)); + public Flux hexpire(K key, long seconds, ExpireArgs expireArgs, K... fields) { + return createDissolvingFlux(() -> commandBuilder.hexpire(key, seconds, expireArgs, fields)); } @Override - public Mono hexpire(K key, Duration seconds, K... fields) { + public Flux hexpire(K key, Duration seconds, K... fields) { return hexpire(key, seconds, null, fields); } @Override - public Mono hexpire(K key, Duration seconds, ExpireArgs expireArgs, K... fields) { + public Flux hexpire(K key, Duration seconds, ExpireArgs expireArgs, K... fields) { LettuceAssert.notNull(seconds, "Timeout must not be null"); return hexpire(key, seconds.toMillis() / 1000, expireArgs, fields); } @@ -912,33 +912,33 @@ public Mono expireat(K key, Instant timestamp, ExpireArgs expireArgs) { } @Override - public Mono hexpireat(K key, long timestamp, K... fields) { + public Flux hexpireat(K key, long timestamp, K... fields) { return hexpireat(key, timestamp, null, fields); } @Override - public Mono hexpireat(K key, long timestamp, ExpireArgs expireArgs, K... fields) { - return createMono(() -> commandBuilder.hexpireat(key, timestamp, expireArgs, fields)); + public Flux hexpireat(K key, long timestamp, ExpireArgs expireArgs, K... fields) { + return createDissolvingFlux(() -> commandBuilder.hexpireat(key, timestamp, expireArgs, fields)); } @Override - public Mono hexpireat(K key, Date timestamp, K... fields) { + public Flux hexpireat(K key, Date timestamp, K... fields) { return hexpireat(key, timestamp, null, fields); } @Override - public Mono hexpireat(K key, Date timestamp, ExpireArgs expireArgs, K... fields) { + public Flux hexpireat(K key, Date timestamp, ExpireArgs expireArgs, K... fields) { LettuceAssert.notNull(timestamp, "Timestamp must not be null"); return hexpireat(key, timestamp.getTime() / 1000, expireArgs, fields); } @Override - public Mono hexpireat(K key, Instant timestamp, K... fields) { + public Flux hexpireat(K key, Instant timestamp, K... fields) { return hexpireat(key, timestamp, null, fields); } @Override - public Mono hexpireat(K key, Instant timestamp, ExpireArgs expireArgs, K... fields) { + public Flux hexpireat(K key, Instant timestamp, ExpireArgs expireArgs, K... fields) { LettuceAssert.notNull(timestamp, "Timestamp must not be null"); return hexpireat(key, timestamp.toEpochMilli() / 1000, expireArgs, fields); } @@ -949,8 +949,76 @@ public Mono expiretime(K key) { } @Override - public Mono hexpiretime(K key, K... fields) { - return createMono(() -> commandBuilder.hexpiretime(key, fields)); + public Flux hexpiretime(K key, K... fields) { + return createDissolvingFlux(() -> commandBuilder.hexpiretime(key, fields)); + } + + @Override + public Flux httl(K key, K... fields) { + return createDissolvingFlux(() -> commandBuilder.httl(key, fields)); + } + + @Override + public Flux hpexpire(K key, long milliseconds, K... fields) { + return hpexpire(key, milliseconds, null, fields); + } + + @Override + public Flux hpexpire(K key, long milliseconds, ExpireArgs expireArgs, K... fields) { + return createDissolvingFlux(() -> commandBuilder.hpexpire(key, milliseconds, expireArgs, fields)); + } + + @Override + public Flux hpexpire(K key, Duration milliseconds, K... fields) { + return hpexpire(key, milliseconds, null, fields); + } + + @Override + public Flux hpexpire(K key, Duration milliseconds, ExpireArgs expireArgs, K... fields) { + LettuceAssert.notNull(milliseconds, "Timeout must not be null"); + return hpexpire(key, milliseconds.toMillis(), expireArgs, fields); + } + + @Override + public Flux hpexpireat(K key, Date timestamp, K... fields) { + return hpexpireat(key, timestamp, null, fields); + } + + @Override + public Flux hpexpireat(K key, Date timestamp, ExpireArgs expireArgs, K... fields) { + LettuceAssert.notNull(timestamp, "Timestamp must not be null"); + return hpexpireat(key, timestamp.getTime(), expireArgs, fields); + } + + @Override + public Flux hpexpireat(K key, Instant timestamp, K... fields) { + return hpexpireat(key, timestamp, null, fields); + } + + @Override + public Flux hpexpireat(K key, Instant timestamp, ExpireArgs expireArgs, K... fields) { + LettuceAssert.notNull(timestamp, "Timestamp must not be null"); + return hpexpireat(key, timestamp.toEpochMilli(), expireArgs, fields); + } + + @Override + public Flux hpexpireat(K key, long timestamp, K... fields) { + return hpexpireat(key, timestamp, null, fields); + } + + @Override + public Flux hpexpireat(K key, long timestamp, ExpireArgs expireArgs, K... fields) { + return createDissolvingFlux(() -> commandBuilder.hpexpireat(key, timestamp, expireArgs, fields)); + } + + @Override + public Flux hpexpiretime(K key, K... fields) { + return createDissolvingFlux(() -> commandBuilder.hpexpiretime(key, fields)); + } + + @Override + public Flux hpttl(K key, K... fields) { + return createDissolvingFlux(() -> commandBuilder.hpttl(key, fields)); } @Override @@ -1619,8 +1687,8 @@ public Mono persist(K key) { } @Override - public Mono hpersist(K key, K... fields) { - return createMono(() -> commandBuilder.hpersist(key, fields)); + public Flux hpersist(K key, K... fields) { + return createDissolvingFlux(() -> commandBuilder.hpersist(key, fields)); } @Override diff --git a/src/main/java/io/lettuce/core/RedisCommandBuilder.java b/src/main/java/io/lettuce/core/RedisCommandBuilder.java index 8d74e0deb9..1a5e4d1645 100644 --- a/src/main/java/io/lettuce/core/RedisCommandBuilder.java +++ b/src/main/java/io/lettuce/core/RedisCommandBuilder.java @@ -978,9 +978,8 @@ Command expire(K key, long seconds, ExpireArgs expireArgs) { return createCommand(EXPIRE, new BooleanOutput<>(codec), args); } - Command hexpire(K key, long seconds, ExpireArgs expireArgs, K... fields) { - notNullKey(key); - notEmpty(fields); + Command> hexpire(K key, long seconds, ExpireArgs expireArgs, K... fields) { + keyAndFieldsProvided(key, fields); CommandArgs args = new CommandArgs<>(codec).addKey(key).add(seconds); @@ -988,15 +987,13 @@ Command hexpire(K key, long seconds, ExpireArgs expireArgs, K... expireArgs.build(args); } - args.add(fields.length); - args.addKeys(fields); + args.add(FIELDS).add(fields.length).addKeys(fields); - return createCommand(HEXPIRE, new BooleanOutput<>(codec), args); + return createCommand(HEXPIRE, new IntegerListOutput<>(codec), args); } - Command hexpireat(K key, long seconds, ExpireArgs expireArgs, K... fields) { - notNullKey(key); - notEmpty(fields); + Command> hexpireat(K key, long seconds, ExpireArgs expireArgs, K... fields) { + keyAndFieldsProvided(key, fields); CommandArgs args = new CommandArgs<>(codec).addKey(key).add(seconds); @@ -1004,10 +1001,64 @@ Command hexpireat(K key, long seconds, ExpireArgs expireArgs, K.. expireArgs.build(args); } - args.add(fields.length); - args.addKeys(fields); + args.add(FIELDS).add(fields.length).addKeys(fields); + + return createCommand(HEXPIREAT, new IntegerListOutput<>(codec), args); + } + + Command> httl(K key, K... fields) { + keyAndFieldsProvided(key, fields); + + CommandArgs args = new CommandArgs<>(codec).addKey(key); + args.add(FIELDS).add(fields.length).addKeys(fields); + + return createCommand(HTTL, new IntegerListOutput<>(codec), args); + } + + Command> hpexpire(K key, long milliseconds, ExpireArgs expireArgs, K... fields) { + keyAndFieldsProvided(key, fields); + + CommandArgs args = new CommandArgs<>(codec).addKey(key).add(milliseconds); + + if (expireArgs != null) { + expireArgs.build(args); + } + + args.add(FIELDS).add(fields.length).addKeys(fields); + + return createCommand(HPEXPIRE, new IntegerListOutput<>(codec), args); + } + + Command> hpexpireat(K key, long timestamp, ExpireArgs expireArgs, K... fields) { + keyAndFieldsProvided(key, fields); + + CommandArgs args = new CommandArgs<>(codec).addKey(key).add(timestamp); + + if (expireArgs != null) { + expireArgs.build(args); + } + + args.add(FIELDS).add(fields.length).addKeys(fields); - return createCommand(HEXPIREAT, new BooleanOutput<>(codec), args); + return createCommand(HPEXPIREAT, new IntegerListOutput<>(codec), args); + } + + Command> hpexpiretime(K key, K... fields) { + keyAndFieldsProvided(key, fields); + + CommandArgs args = new CommandArgs<>(codec).addKey(key); + args.add(FIELDS).add(fields.length).addKeys(fields); + + return createCommand(HPEXPIRETIME, new IntegerListOutput<>(codec), args); + } + + Command> hpttl(K key, K... fields) { + keyAndFieldsProvided(key, fields); + + CommandArgs args = new CommandArgs<>(codec).addKey(key); + args.add(FIELDS).add(fields.length).addKeys(fields); + + return createCommand(HPTTL, new IntegerListOutput<>(codec), args); } Command expireat(K key, long timestamp, ExpireArgs expireArgs) { @@ -1029,13 +1080,13 @@ Command expiretime(K key) { return createCommand(EXPIRETIME, new IntegerOutput<>(codec), args); } - Command hexpiretime(K key, K... fields) { + Command> hexpiretime(K key, K... fields) { notNullKey(key); CommandArgs args = new CommandArgs<>(codec).addKey(key); - args.add(fields.length); - args.addKeys(fields); - return createCommand(HEXPIRETIME, new IntegerOutput<>(codec), args); + args.add(FIELDS).add(fields.length).addKeys(fields); + + return createCommand(HEXPIRETIME, new IntegerListOutput<>(codec), args); } Command flushall() { @@ -1402,9 +1453,7 @@ Command getset(K key, V value) { } Command hdel(K key, K... fields) { - notNullKey(key); - LettuceAssert.notNull(fields, "Fields " + MUST_NOT_BE_NULL); - LettuceAssert.notEmpty(fields, "Fields " + MUST_NOT_BE_EMPTY); + keyAndFieldsProvided(key, fields); CommandArgs args = new CommandArgs<>(codec).addKey(key).addKeys(fields); return createCommand(HDEL, new IntegerOutput<>(codec), args); @@ -1496,18 +1545,15 @@ Command hlen(K key) { } Command> hmget(K key, K... fields) { - notNullKey(key); - LettuceAssert.notNull(fields, "Fields " + MUST_NOT_BE_NULL); - LettuceAssert.notEmpty(fields, "Fields " + MUST_NOT_BE_EMPTY); + keyAndFieldsProvided(key, fields); CommandArgs args = new CommandArgs<>(codec).addKey(key).addKeys(fields); return createCommand(HMGET, new ValueListOutput<>(codec), args); } Command hmget(ValueStreamingChannel channel, K key, K... fields) { - notNullKey(key); - LettuceAssert.notNull(fields, "Fields " + MUST_NOT_BE_NULL); - LettuceAssert.notEmpty(fields, "Fields " + MUST_NOT_BE_EMPTY); + keyAndFieldsProvided(key, fields); + notNull(channel); CommandArgs args = new CommandArgs<>(codec).addKey(key).addKeys(fields); @@ -1515,9 +1561,8 @@ Command hmget(ValueStreamingChannel channel, K key, K... fields) } Command hmget(KeyValueStreamingChannel channel, K key, K... fields) { - notNullKey(key); - LettuceAssert.notNull(fields, "Fields " + MUST_NOT_BE_NULL); - LettuceAssert.notEmpty(fields, "Fields " + MUST_NOT_BE_EMPTY); + keyAndFieldsProvided(key, fields); + notNull(channel); CommandArgs args = new CommandArgs<>(codec).addKey(key).addKeys(fields); @@ -1525,9 +1570,7 @@ Command hmget(KeyValueStreamingChannel channel, K key, K... fi } Command>> hmgetKeyValue(K key, K... fields) { - notNullKey(key); - LettuceAssert.notNull(fields, "Fields " + MUST_NOT_BE_NULL); - LettuceAssert.notEmpty(fields, "Fields " + MUST_NOT_BE_EMPTY); + keyAndFieldsProvided(key, fields); CommandArgs args = new CommandArgs<>(codec).addKey(key).addKeys(fields); return createCommand(HMGET, new KeyValueListOutput<>(codec, Arrays.asList(fields)), args); @@ -2084,14 +2127,13 @@ Command persist(K key) { return createCommand(PERSIST, new BooleanOutput<>(codec), key); } - Command hpersist(K key, K... fields) { + Command> hpersist(K key, K... fields) { notNullKey(key); CommandArgs args = new CommandArgs<>(codec).addKey(key); - args.add(fields.length); - args.addKeys(fields); + args.add(FIELDS).add(fields.length).addKeys(fields); - return createCommand(HPERSIST, new BooleanOutput<>(codec), args); + return createCommand(HPERSIST, new IntegerListOutput<>(codec), args); } Command pexpire(K key, long milliseconds, ExpireArgs expireArgs) { @@ -4504,6 +4546,11 @@ private static void notNullKey(Object key) { LettuceAssert.notNull(key, "Key " + MUST_NOT_BE_NULL); } + private static void keyAndFieldsProvided(Object key, Object[] fields) { + LettuceAssert.notNull(key, "Key " + MUST_NOT_BE_NULL); + LettuceAssert.notEmpty(fields, "Fields " + MUST_NOT_BE_EMPTY); + } + private static void notNullLimit(Limit limit) { LettuceAssert.notNull(limit, "Limit " + MUST_NOT_BE_NULL); } diff --git a/src/main/java/io/lettuce/core/api/async/RedisHashAsyncCommands.java b/src/main/java/io/lettuce/core/api/async/RedisHashAsyncCommands.java index 374f9e2348..209d6c469f 100644 --- a/src/main/java/io/lettuce/core/api/async/RedisHashAsyncCommands.java +++ b/src/main/java/io/lettuce/core/api/async/RedisHashAsyncCommands.java @@ -442,11 +442,13 @@ RedisFuture hscanNovalues(KeyStreamingChannel channel, K ke * @param key the key of the fields. * @param seconds the seconds type: long. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - RedisFuture hexpire(K key, long seconds, K... fields); + RedisFuture> hexpire(K key, long seconds, K... fields); /** * Set the time to live (in seconds) for one or more fields, belonging to a certain key. @@ -455,11 +457,13 @@ RedisFuture hscanNovalues(KeyStreamingChannel channel, K ke * @param seconds the seconds type: long. * @param expireArgs the expire arguments. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - RedisFuture hexpire(K key, long seconds, ExpireArgs expireArgs, K... fields); + RedisFuture> hexpire(K key, long seconds, ExpireArgs expireArgs, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key. @@ -467,11 +471,13 @@ RedisFuture hscanNovalues(KeyStreamingChannel channel, K ke * @param key the key. * @param seconds the TTL {@link Duration} * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - RedisFuture hexpire(K key, Duration seconds, K... fields); + RedisFuture> hexpire(K key, Duration seconds, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key. @@ -480,11 +486,13 @@ RedisFuture hscanNovalues(KeyStreamingChannel channel, K ke * @param seconds the TTL {@link Duration} * @param expireArgs the {@link ExpireArgs}. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - RedisFuture hexpire(K key, Duration seconds, ExpireArgs expireArgs, K... fields); + RedisFuture> hexpire(K key, Duration seconds, ExpireArgs expireArgs, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -492,11 +500,13 @@ RedisFuture hscanNovalues(KeyStreamingChannel channel, K ke * @param key the key. * @param timestamp the timestamp type: posix time. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set (see: {@code EXPIRE}). + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - RedisFuture hexpireat(K key, long timestamp, K... fields); + RedisFuture> hexpireat(K key, long timestamp, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -505,11 +515,13 @@ RedisFuture hscanNovalues(KeyStreamingChannel channel, K ke * @param timestamp the timestamp type: posix time. * @param expireArgs the expire arguments. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set (see: {@code EXPIRE}). + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - RedisFuture hexpireat(K key, long timestamp, ExpireArgs expireArgs, K... fields); + RedisFuture> hexpireat(K key, long timestamp, ExpireArgs expireArgs, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -517,11 +529,13 @@ RedisFuture hscanNovalues(KeyStreamingChannel channel, K ke * @param key the key. * @param timestamp the timestamp type: posix time. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set (see: {@code EXPIRE}). + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - RedisFuture hexpireat(K key, Date timestamp, K... fields); + RedisFuture> hexpireat(K key, Date timestamp, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -530,11 +544,13 @@ RedisFuture hscanNovalues(KeyStreamingChannel channel, K ke * @param timestamp the timestamp type: posix time. * @param expireArgs the expire arguments. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set (see: {@code EXPIRE}). + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - RedisFuture hexpireat(K key, Date timestamp, ExpireArgs expireArgs, K... fields); + RedisFuture> hexpireat(K key, Date timestamp, ExpireArgs expireArgs, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -542,11 +558,13 @@ RedisFuture hscanNovalues(KeyStreamingChannel channel, K ke * @param key the key. * @param timestamp the timestamp type: posix time. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set (see: {@code EXPIRE}). + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - RedisFuture hexpireat(K key, Instant timestamp, K... fields); + RedisFuture> hexpireat(K key, Instant timestamp, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -555,33 +573,215 @@ RedisFuture hscanNovalues(KeyStreamingChannel channel, K ke * @param timestamp the timestamp type: posix time. * @param expireArgs the expire arguments. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set (see: {@code EXPIRE}). + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - RedisFuture hexpireat(K key, Instant timestamp, ExpireArgs expireArgs, K... fields); + RedisFuture> hexpireat(K key, Instant timestamp, ExpireArgs expireArgs, K... fields); /** - * Get the time to live for one or more fields in as unix timestamp in seconds. + * Get the time to live for one or more fields in as UNIX timestamp in seconds. * * @param key the key. * @param fields one or more fields to get the TTL for. - * @return Long integer-reply in seconds, or a negative value in order to signal an error. The command returns {@code -1} if - * the key exists but has no associated expiration time. The command returns {@code -2} if the key does not exist. + * @return a list of {@link Long} values for each of the fields provided: expiration time as a UNIX timestamp in seconds; + * {@code -1} indicating the field has no expiry time set; {@code -2} indicating there is no such field * @since 7.0 */ - RedisFuture hexpiretime(K key, K... fields); + RedisFuture> hexpiretime(K key, K... fields); /** * Remove the expiration from one or more fields. * * @param key the key. * @param fields one or more fields to remove the TTL for. - * @return Boolean integer-reply specifically: + * @return a list of {@link Long} values for each of the fields provided: {@code 1} indicating expiration time is removed; + * {@code -1} field has no expiration time to be removed; {@code -2} indicating there is no such field + * @since 7.0 + */ + RedisFuture> hpersist(K key, K... fields); + + /** + * Set the time to live for one or more fields in milliseconds. * - * {@code true} if the timeout was removed. {@code false} if {@code key} does not exist or does not have an - * associated timeout. + * @param key the key. + * @param milliseconds the milliseconds type: long. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + RedisFuture> hpexpire(K key, long milliseconds, K... fields); + + /** + * Set the time to live for one or more fields in milliseconds. + * + * @param key the key. + * @param milliseconds the milliseconds type: long. + * @param expireArgs the expire arguments. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + RedisFuture> hpexpire(K key, long milliseconds, ExpireArgs expireArgs, K... fields); + + /** + * Set the time to live for one or more fields in milliseconds. + * + * @param key the key. + * @param milliseconds the milliseconds. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + RedisFuture> hpexpire(K key, Duration milliseconds, K... fields); + + /** + * Set the time to live for one or more fields in milliseconds. + * + * @param key the key. + * @param milliseconds the milliseconds. + * @param expireArgs the expire arguments. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + RedisFuture> hpexpire(K key, Duration milliseconds, ExpireArgs expireArgs, K... fields); + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + RedisFuture> hpexpireat(K key, long timestamp, K... fields); + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param expireArgs the expire arguments. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + RedisFuture> hpexpireat(K key, long timestamp, ExpireArgs expireArgs, K... fields); + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + RedisFuture> hpexpireat(K key, Date timestamp, K... fields); + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param expireArgs the expire arguments. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + RedisFuture> hpexpireat(K key, Date timestamp, ExpireArgs expireArgs, K... fields); + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + RedisFuture> hpexpireat(K key, Instant timestamp, K... fields); + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param expireArgs the expire arguments. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + RedisFuture> hpexpireat(K key, Instant timestamp, ExpireArgs expireArgs, K... fields); + + /** + * Get the time to live for one or more fields as UNIX timestamp in milliseconds. + * + * @param key the key. + * @param fields one or more fields to get the TTL for. + * @return a list of {@link Long} values for each of the fields provided: expiration time as a UNIX timestamp in + * milliseconds; {@code -1} indicating the field has no expiry time set; {@code -2} indicating there is no such + * field + * @since 7.0 + */ + RedisFuture> hpexpiretime(K key, K... fields); + + /** + * Get the time to live for one or more fields. + * + * @param key the key. + * @param fields one or more fields to get the TTL for. + * @return a list of {@link Long} values for each of the fields provided: the time to live in seconds; or a negative value + * in order to signal an error. The command returns {@code -1} if the key exists but has no associated expiration + * time. The command returns {@code -2} if the key does not exist. + * @since 7.0 + */ + RedisFuture> httl(K key, K... fields); + + /** + * Get the time to live for one or more fields in milliseconds. + * + * @param key the key. + * @param fields one or more fields to get the TTL for. + * @return a list of {@link Long} values for each of the fields provided: the time to live in milliseconds; or a negative + * value in order to signal an error. The command returns {@code -1} if the key exists but has no associated + * expiration time. The command returns {@code -2} if the key does not exist. + * @since 7.0 */ - RedisFuture hpersist(K key, K... fields); + RedisFuture> hpttl(K key, K... fields); } diff --git a/src/main/java/io/lettuce/core/api/reactive/RedisHashReactiveCommands.java b/src/main/java/io/lettuce/core/api/reactive/RedisHashReactiveCommands.java index bd90160ede..6530b775b2 100644 --- a/src/main/java/io/lettuce/core/api/reactive/RedisHashReactiveCommands.java +++ b/src/main/java/io/lettuce/core/api/reactive/RedisHashReactiveCommands.java @@ -204,8 +204,6 @@ public interface RedisHashReactiveCommands { * Return a random field along its value from the hash stored at {@code key}. * * @param key the key. - * @param count the number of fields to return. If the provided count argument is positive, return an array of distinct - * fields. * @return array-reply the key and value. * @since 6.1 */ @@ -474,11 +472,13 @@ public interface RedisHashReactiveCommands { * @param key the key of the fields. * @param seconds the seconds type: long. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Mono hexpire(K key, long seconds, K... fields); + Flux hexpire(K key, long seconds, K... fields); /** * Set the time to live (in seconds) for one or more fields, belonging to a certain key. @@ -487,11 +487,13 @@ public interface RedisHashReactiveCommands { * @param seconds the seconds type: long. * @param expireArgs the expire arguments. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Mono hexpire(K key, long seconds, ExpireArgs expireArgs, K... fields); + Flux hexpire(K key, long seconds, ExpireArgs expireArgs, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key. @@ -499,11 +501,13 @@ public interface RedisHashReactiveCommands { * @param key the key. * @param seconds the TTL {@link Duration} * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Mono hexpire(K key, Duration seconds, K... fields); + Flux hexpire(K key, Duration seconds, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key. @@ -512,11 +516,13 @@ public interface RedisHashReactiveCommands { * @param seconds the TTL {@link Duration} * @param expireArgs the {@link ExpireArgs}. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Mono hexpire(K key, Duration seconds, ExpireArgs expireArgs, K... fields); + Flux hexpire(K key, Duration seconds, ExpireArgs expireArgs, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -524,11 +530,13 @@ public interface RedisHashReactiveCommands { * @param key the key. * @param timestamp the timestamp type: posix time. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set (see: {@code EXPIRE}). + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Mono hexpireat(K key, long timestamp, K... fields); + Flux hexpireat(K key, long timestamp, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -537,11 +545,13 @@ public interface RedisHashReactiveCommands { * @param timestamp the timestamp type: posix time. * @param expireArgs the expire arguments. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set (see: {@code EXPIRE}). + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Mono hexpireat(K key, long timestamp, ExpireArgs expireArgs, K... fields); + Flux hexpireat(K key, long timestamp, ExpireArgs expireArgs, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -549,11 +559,13 @@ public interface RedisHashReactiveCommands { * @param key the key. * @param timestamp the timestamp type: posix time. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set (see: {@code EXPIRE}). + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Mono hexpireat(K key, Date timestamp, K... fields); + Flux hexpireat(K key, Date timestamp, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -562,11 +574,13 @@ public interface RedisHashReactiveCommands { * @param timestamp the timestamp type: posix time. * @param expireArgs the expire arguments. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set (see: {@code EXPIRE}). + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Mono hexpireat(K key, Date timestamp, ExpireArgs expireArgs, K... fields); + Flux hexpireat(K key, Date timestamp, ExpireArgs expireArgs, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -574,11 +588,13 @@ public interface RedisHashReactiveCommands { * @param key the key. * @param timestamp the timestamp type: posix time. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set (see: {@code EXPIRE}). + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Mono hexpireat(K key, Instant timestamp, K... fields); + Flux hexpireat(K key, Instant timestamp, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -587,33 +603,215 @@ public interface RedisHashReactiveCommands { * @param timestamp the timestamp type: posix time. * @param expireArgs the expire arguments. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set (see: {@code EXPIRE}). + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Mono hexpireat(K key, Instant timestamp, ExpireArgs expireArgs, K... fields); + Flux hexpireat(K key, Instant timestamp, ExpireArgs expireArgs, K... fields); /** - * Get the time to live for one or more fields in as unix timestamp in seconds. + * Get the time to live for one or more fields in as UNIX timestamp in seconds. * * @param key the key. * @param fields one or more fields to get the TTL for. - * @return Long integer-reply in seconds, or a negative value in order to signal an error. The command returns {@code -1} if - * the key exists but has no associated expiration time. The command returns {@code -2} if the key does not exist. + * @return a list of {@link Long} values for each of the fields provided: expiration time as a UNIX timestamp in seconds; + * {@code -1} indicating the field has no expiry time set; {@code -2} indicating there is no such field * @since 7.0 */ - Mono hexpiretime(K key, K... fields); + Flux hexpiretime(K key, K... fields); /** * Remove the expiration from one or more fields. * * @param key the key. * @param fields one or more fields to remove the TTL for. - * @return Boolean integer-reply specifically: + * @return a list of {@link Long} values for each of the fields provided: {@code 1} indicating expiration time is removed; + * {@code -1} field has no expiration time to be removed; {@code -2} indicating there is no such field + * @since 7.0 + */ + Flux hpersist(K key, K... fields); + + /** + * Set the time to live for one or more fields in milliseconds. + * + * @param key the key. + * @param milliseconds the milliseconds type: long. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + Flux hpexpire(K key, long milliseconds, K... fields); + + /** + * Set the time to live for one or more fields in milliseconds. + * + * @param key the key. + * @param milliseconds the milliseconds type: long. + * @param expireArgs the expire arguments. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + Flux hpexpire(K key, long milliseconds, ExpireArgs expireArgs, K... fields); + + /** + * Set the time to live for one or more fields in milliseconds. + * + * @param key the key. + * @param milliseconds the milliseconds. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + Flux hpexpire(K key, Duration milliseconds, K... fields); + + /** + * Set the time to live for one or more fields in milliseconds. * - * {@code true} if the timeout was removed. {@code false} if {@code key} does not exist or does not have an - * associated timeout. + * @param key the key. + * @param milliseconds the milliseconds. + * @param expireArgs the expire arguments. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + Flux hpexpire(K key, Duration milliseconds, ExpireArgs expireArgs, K... fields); + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + Flux hpexpireat(K key, long timestamp, K... fields); + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param expireArgs the expire arguments. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + Flux hpexpireat(K key, long timestamp, ExpireArgs expireArgs, K... fields); + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + Flux hpexpireat(K key, Date timestamp, K... fields); + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param expireArgs the expire arguments. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + Flux hpexpireat(K key, Date timestamp, ExpireArgs expireArgs, K... fields); + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + Flux hpexpireat(K key, Instant timestamp, K... fields); + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param expireArgs the expire arguments. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + Flux hpexpireat(K key, Instant timestamp, ExpireArgs expireArgs, K... fields); + + /** + * Get the time to live for one or more fields as UNIX timestamp in milliseconds. + * + * @param key the key. + * @param fields one or more fields to get the TTL for. + * @return a list of {@link Long} values for each of the fields provided: expiration time as a UNIX timestamp in + * milliseconds; {@code -1} indicating the field has no expiry time set; {@code -2} indicating there is no such + * field + * @since 7.0 + */ + Flux hpexpiretime(K key, K... fields); + + /** + * Get the time to live for one or more fields. + * + * @param key the key. + * @param fields one or more fields to get the TTL for. + * @return a list of {@link Long} values for each of the fields provided: the time to live in seconds; or a negative value + * in order to signal an error. The command returns {@code -1} if the key exists but has no associated expiration + * time. The command returns {@code -2} if the key does not exist. + * @since 7.0 + */ + Flux httl(K key, K... fields); + + /** + * Get the time to live for one or more fields in milliseconds. + * + * @param key the key. + * @param fields one or more fields to get the TTL for. + * @return a list of {@link Long} values for each of the fields provided: the time to live in milliseconds; or a negative + * value in order to signal an error. The command returns {@code -1} if the key exists but has no associated + * expiration time. The command returns {@code -2} if the key does not exist. + * @since 7.0 */ - Mono hpersist(K key, K... fields); + Flux hpttl(K key, K... fields); } diff --git a/src/main/java/io/lettuce/core/api/sync/RedisHashCommands.java b/src/main/java/io/lettuce/core/api/sync/RedisHashCommands.java index f27d96e0c6..6345f8593f 100644 --- a/src/main/java/io/lettuce/core/api/sync/RedisHashCommands.java +++ b/src/main/java/io/lettuce/core/api/sync/RedisHashCommands.java @@ -194,8 +194,6 @@ public interface RedisHashCommands { * Return a random field along its value from the hash stored at {@code key}. * * @param key the key. - * @param count the number of fields to return. If the provided count argument is positive, return an array of distinct - * fields. * @return array-reply the key and value. * @since 6.1 */ @@ -441,11 +439,13 @@ public interface RedisHashCommands { * @param key the key of the fields. * @param seconds the seconds type: long. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Boolean hexpire(K key, long seconds, K... fields); + List hexpire(K key, long seconds, K... fields); /** * Set the time to live (in seconds) for one or more fields, belonging to a certain key. @@ -454,11 +454,13 @@ public interface RedisHashCommands { * @param seconds the seconds type: long. * @param expireArgs the expire arguments. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Boolean hexpire(K key, long seconds, ExpireArgs expireArgs, K... fields); + List hexpire(K key, long seconds, ExpireArgs expireArgs, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key. @@ -466,11 +468,13 @@ public interface RedisHashCommands { * @param key the key. * @param seconds the TTL {@link Duration} * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Boolean hexpire(K key, Duration seconds, K... fields); + List hexpire(K key, Duration seconds, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key. @@ -479,11 +483,13 @@ public interface RedisHashCommands { * @param seconds the TTL {@link Duration} * @param expireArgs the {@link ExpireArgs}. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Boolean hexpire(K key, Duration seconds, ExpireArgs expireArgs, K... fields); + List hexpire(K key, Duration seconds, ExpireArgs expireArgs, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -491,11 +497,13 @@ public interface RedisHashCommands { * @param key the key. * @param timestamp the timestamp type: posix time. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set (see: {@code EXPIRE}). + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Boolean hexpireat(K key, long timestamp, K... fields); + List hexpireat(K key, long timestamp, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -504,11 +512,13 @@ public interface RedisHashCommands { * @param timestamp the timestamp type: posix time. * @param expireArgs the expire arguments. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set (see: {@code EXPIRE}). + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Boolean hexpireat(K key, long timestamp, ExpireArgs expireArgs, K... fields); + List hexpireat(K key, long timestamp, ExpireArgs expireArgs, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -516,11 +526,13 @@ public interface RedisHashCommands { * @param key the key. * @param timestamp the timestamp type: posix time. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set (see: {@code EXPIRE}). + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Boolean hexpireat(K key, Date timestamp, K... fields); + List hexpireat(K key, Date timestamp, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -529,11 +541,13 @@ public interface RedisHashCommands { * @param timestamp the timestamp type: posix time. * @param expireArgs the expire arguments. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set (see: {@code EXPIRE}). + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Boolean hexpireat(K key, Date timestamp, ExpireArgs expireArgs, K... fields); + List hexpireat(K key, Date timestamp, ExpireArgs expireArgs, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -541,11 +555,13 @@ public interface RedisHashCommands { * @param key the key. * @param timestamp the timestamp type: posix time. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set (see: {@code EXPIRE}). + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Boolean hexpireat(K key, Instant timestamp, K... fields); + List hexpireat(K key, Instant timestamp, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -554,33 +570,215 @@ public interface RedisHashCommands { * @param timestamp the timestamp type: posix time. * @param expireArgs the expire arguments. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set (see: {@code EXPIRE}). + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Boolean hexpireat(K key, Instant timestamp, ExpireArgs expireArgs, K... fields); + List hexpireat(K key, Instant timestamp, ExpireArgs expireArgs, K... fields); /** - * Get the time to live for one or more fields in as unix timestamp in seconds. + * Get the time to live for one or more fields in as UNIX timestamp in seconds. * * @param key the key. * @param fields one or more fields to get the TTL for. - * @return Long integer-reply in seconds, or a negative value in order to signal an error. The command returns {@code -1} if - * the key exists but has no associated expiration time. The command returns {@code -2} if the key does not exist. + * @return a list of {@link Long} values for each of the fields provided: expiration time as a UNIX timestamp in seconds; + * {@code -1} indicating the field has no expiry time set; {@code -2} indicating there is no such field * @since 7.0 */ - Long hexpiretime(K key, K... fields); + List hexpiretime(K key, K... fields); /** * Remove the expiration from one or more fields. * * @param key the key. * @param fields one or more fields to remove the TTL for. - * @return Boolean integer-reply specifically: + * @return a list of {@link Long} values for each of the fields provided: {@code 1} indicating expiration time is removed; + * {@code -1} field has no expiration time to be removed; {@code -2} indicating there is no such field + * @since 7.0 + */ + List hpersist(K key, K... fields); + + /** + * Set the time to live for one or more fields in milliseconds. + * + * @param key the key. + * @param milliseconds the milliseconds type: long. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + List hpexpire(K key, long milliseconds, K... fields); + + /** + * Set the time to live for one or more fields in milliseconds. + * + * @param key the key. + * @param milliseconds the milliseconds type: long. + * @param expireArgs the expire arguments. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + List hpexpire(K key, long milliseconds, ExpireArgs expireArgs, K... fields); + + /** + * Set the time to live for one or more fields in milliseconds. + * + * @param key the key. + * @param milliseconds the milliseconds. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + List hpexpire(K key, Duration milliseconds, K... fields); + + /** + * Set the time to live for one or more fields in milliseconds. * - * {@code true} if the timeout was removed. {@code false} if {@code key} does not exist or does not have an - * associated timeout. + * @param key the key. + * @param milliseconds the milliseconds. + * @param expireArgs the expire arguments. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + List hpexpire(K key, Duration milliseconds, ExpireArgs expireArgs, K... fields); + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + List hpexpireat(K key, long timestamp, K... fields); + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param expireArgs the expire arguments. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + List hpexpireat(K key, long timestamp, ExpireArgs expireArgs, K... fields); + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + List hpexpireat(K key, Date timestamp, K... fields); + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param expireArgs the expire arguments. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + List hpexpireat(K key, Date timestamp, ExpireArgs expireArgs, K... fields); + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + List hpexpireat(K key, Instant timestamp, K... fields); + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param expireArgs the expire arguments. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + List hpexpireat(K key, Instant timestamp, ExpireArgs expireArgs, K... fields); + + /** + * Get the time to live for one or more fields as UNIX timestamp in milliseconds. + * + * @param key the key. + * @param fields one or more fields to get the TTL for. + * @return a list of {@link Long} values for each of the fields provided: expiration time as a UNIX timestamp in + * milliseconds; {@code -1} indicating the field has no expiry time set; {@code -2} indicating there is no such + * field + * @since 7.0 + */ + List hpexpiretime(K key, K... fields); + + /** + * Get the time to live for one or more fields. + * + * @param key the key. + * @param fields one or more fields to get the TTL for. + * @return a list of {@link Long} values for each of the fields provided: the time to live in seconds; or a negative value + * in order to signal an error. The command returns {@code -1} if the key exists but has no associated expiration + * time. The command returns {@code -2} if the key does not exist. + * @since 7.0 + */ + List httl(K key, K... fields); + + /** + * Get the time to live for one or more fields in milliseconds. + * + * @param key the key. + * @param fields one or more fields to get the TTL for. + * @return a list of {@link Long} values for each of the fields provided: the time to live in milliseconds; or a negative + * value in order to signal an error. The command returns {@code -1} if the key exists but has no associated + * expiration time. The command returns {@code -2} if the key does not exist. + * @since 7.0 */ - Boolean hpersist(K key, K... fields); + List hpttl(K key, K... fields); } diff --git a/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionHashAsyncCommands.java b/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionHashAsyncCommands.java index 4b020c3663..3dbf6b2af6 100644 --- a/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionHashAsyncCommands.java +++ b/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionHashAsyncCommands.java @@ -441,11 +441,13 @@ AsyncExecutions hscanNovalues(KeyStreamingChannel channel, * @param key the key of the fields. * @param seconds the seconds type: long. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - AsyncExecutions hexpire(K key, long seconds, K... fields); + AsyncExecutions> hexpire(K key, long seconds, K... fields); /** * Set the time to live (in seconds) for one or more fields, belonging to a certain key. @@ -454,11 +456,13 @@ AsyncExecutions hscanNovalues(KeyStreamingChannel channel, * @param seconds the seconds type: long. * @param expireArgs the expire arguments. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - AsyncExecutions hexpire(K key, long seconds, ExpireArgs expireArgs, K... fields); + AsyncExecutions> hexpire(K key, long seconds, ExpireArgs expireArgs, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key. @@ -466,11 +470,13 @@ AsyncExecutions hscanNovalues(KeyStreamingChannel channel, * @param key the key. * @param seconds the TTL {@link Duration} * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - AsyncExecutions hexpire(K key, Duration seconds, K... fields); + AsyncExecutions> hexpire(K key, Duration seconds, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key. @@ -479,11 +485,13 @@ AsyncExecutions hscanNovalues(KeyStreamingChannel channel, * @param seconds the TTL {@link Duration} * @param expireArgs the {@link ExpireArgs}. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - AsyncExecutions hexpire(K key, Duration seconds, ExpireArgs expireArgs, K... fields); + AsyncExecutions> hexpire(K key, Duration seconds, ExpireArgs expireArgs, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -491,11 +499,13 @@ AsyncExecutions hscanNovalues(KeyStreamingChannel channel, * @param key the key. * @param timestamp the timestamp type: posix time. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set (see: {@code EXPIRE}). + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - AsyncExecutions hexpireat(K key, long timestamp, K... fields); + AsyncExecutions> hexpireat(K key, long timestamp, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -504,11 +514,13 @@ AsyncExecutions hscanNovalues(KeyStreamingChannel channel, * @param timestamp the timestamp type: posix time. * @param expireArgs the expire arguments. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set (see: {@code EXPIRE}). + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - AsyncExecutions hexpireat(K key, long timestamp, ExpireArgs expireArgs, K... fields); + AsyncExecutions> hexpireat(K key, long timestamp, ExpireArgs expireArgs, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -516,11 +528,13 @@ AsyncExecutions hscanNovalues(KeyStreamingChannel channel, * @param key the key. * @param timestamp the timestamp type: posix time. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set (see: {@code EXPIRE}). + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - AsyncExecutions hexpireat(K key, Date timestamp, K... fields); + AsyncExecutions> hexpireat(K key, Date timestamp, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -529,11 +543,13 @@ AsyncExecutions hscanNovalues(KeyStreamingChannel channel, * @param timestamp the timestamp type: posix time. * @param expireArgs the expire arguments. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set (see: {@code EXPIRE}). + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - AsyncExecutions hexpireat(K key, Date timestamp, ExpireArgs expireArgs, K... fields); + AsyncExecutions> hexpireat(K key, Date timestamp, ExpireArgs expireArgs, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -541,11 +557,13 @@ AsyncExecutions hscanNovalues(KeyStreamingChannel channel, * @param key the key. * @param timestamp the timestamp type: posix time. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set (see: {@code EXPIRE}). + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - AsyncExecutions hexpireat(K key, Instant timestamp, K... fields); + AsyncExecutions> hexpireat(K key, Instant timestamp, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -554,33 +572,215 @@ AsyncExecutions hscanNovalues(KeyStreamingChannel channel, * @param timestamp the timestamp type: posix time. * @param expireArgs the expire arguments. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set (see: {@code EXPIRE}). + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - AsyncExecutions hexpireat(K key, Instant timestamp, ExpireArgs expireArgs, K... fields); + AsyncExecutions> hexpireat(K key, Instant timestamp, ExpireArgs expireArgs, K... fields); /** - * Get the time to live for one or more fields in as unix timestamp in seconds. + * Get the time to live for one or more fields in as UNIX timestamp in seconds. * * @param key the key. * @param fields one or more fields to get the TTL for. - * @return Long integer-reply in seconds, or a negative value in order to signal an error. The command returns {@code -1} if - * the key exists but has no associated expiration time. The command returns {@code -2} if the key does not exist. + * @return a list of {@link Long} values for each of the fields provided: expiration time as a UNIX timestamp in seconds; + * {@code -1} indicating the field has no expiry time set; {@code -2} indicating there is no such field * @since 7.0 */ - AsyncExecutions hexpiretime(K key, K... fields); + AsyncExecutions> hexpiretime(K key, K... fields); /** * Remove the expiration from one or more fields. * * @param key the key. * @param fields one or more fields to remove the TTL for. - * @return Boolean integer-reply specifically: + * @return a list of {@link Long} values for each of the fields provided: {@code 1} indicating expiration time is removed; + * {@code -1} field has no expiration time to be removed; {@code -2} indicating there is no such field + * @since 7.0 + */ + AsyncExecutions> hpersist(K key, K... fields); + + /** + * Set the time to live for one or more fields in milliseconds. * - * {@code true} if the timeout was removed. {@code false} if {@code key} does not exist or does not have an - * associated timeout. + * @param key the key. + * @param milliseconds the milliseconds type: long. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + AsyncExecutions> hpexpire(K key, long milliseconds, K... fields); + + /** + * Set the time to live for one or more fields in milliseconds. + * + * @param key the key. + * @param milliseconds the milliseconds type: long. + * @param expireArgs the expire arguments. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + AsyncExecutions> hpexpire(K key, long milliseconds, ExpireArgs expireArgs, K... fields); + + /** + * Set the time to live for one or more fields in milliseconds. + * + * @param key the key. + * @param milliseconds the milliseconds. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + AsyncExecutions> hpexpire(K key, Duration milliseconds, K... fields); + + /** + * Set the time to live for one or more fields in milliseconds. + * + * @param key the key. + * @param milliseconds the milliseconds. + * @param expireArgs the expire arguments. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + AsyncExecutions> hpexpire(K key, Duration milliseconds, ExpireArgs expireArgs, K... fields); + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + AsyncExecutions> hpexpireat(K key, long timestamp, K... fields); + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param expireArgs the expire arguments. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + AsyncExecutions> hpexpireat(K key, long timestamp, ExpireArgs expireArgs, K... fields); + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + AsyncExecutions> hpexpireat(K key, Date timestamp, K... fields); + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param expireArgs the expire arguments. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + AsyncExecutions> hpexpireat(K key, Date timestamp, ExpireArgs expireArgs, K... fields); + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + AsyncExecutions> hpexpireat(K key, Instant timestamp, K... fields); + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param expireArgs the expire arguments. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + AsyncExecutions> hpexpireat(K key, Instant timestamp, ExpireArgs expireArgs, K... fields); + + /** + * Get the time to live for one or more fields as UNIX timestamp in milliseconds. + * + * @param key the key. + * @param fields one or more fields to get the TTL for. + * @return a list of {@link Long} values for each of the fields provided: expiration time as a UNIX timestamp in + * milliseconds; {@code -1} indicating the field has no expiry time set; {@code -2} indicating there is no such + * field + * @since 7.0 + */ + AsyncExecutions> hpexpiretime(K key, K... fields); + + /** + * Get the time to live for one or more fields. + * + * @param key the key. + * @param fields one or more fields to get the TTL for. + * @return a list of {@link Long} values for each of the fields provided: the time to live in seconds; or a negative value + * in order to signal an error. The command returns {@code -1} if the key exists but has no associated expiration + * time. The command returns {@code -2} if the key does not exist. + * @since 7.0 + */ + AsyncExecutions> httl(K key, K... fields); + + /** + * Get the time to live for one or more fields in milliseconds. + * + * @param key the key. + * @param fields one or more fields to get the TTL for. + * @return a list of {@link Long} values for each of the fields provided: the time to live in milliseconds; or a negative + * value in order to signal an error. The command returns {@code -1} if the key exists but has no associated + * expiration time. The command returns {@code -2} if the key does not exist. + * @since 7.0 */ - AsyncExecutions hpersist(K key, K... fields); + AsyncExecutions> hpttl(K key, K... fields); } diff --git a/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionHashCommands.java b/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionHashCommands.java index 9f23a2159d..ee344d1180 100644 --- a/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionHashCommands.java +++ b/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionHashCommands.java @@ -439,11 +439,13 @@ public interface NodeSelectionHashCommands { * @param key the key of the fields. * @param seconds the seconds type: long. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Executions hexpire(K key, long seconds, K... fields); + Executions> hexpire(K key, long seconds, K... fields); /** * Set the time to live (in seconds) for one or more fields, belonging to a certain key. @@ -452,11 +454,13 @@ public interface NodeSelectionHashCommands { * @param seconds the seconds type: long. * @param expireArgs the expire arguments. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Executions hexpire(K key, long seconds, ExpireArgs expireArgs, K... fields); + Executions> hexpire(K key, long seconds, ExpireArgs expireArgs, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key. @@ -464,11 +468,13 @@ public interface NodeSelectionHashCommands { * @param key the key. * @param seconds the TTL {@link Duration} * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Executions hexpire(K key, Duration seconds, K... fields); + Executions> hexpire(K key, Duration seconds, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key. @@ -477,11 +483,13 @@ public interface NodeSelectionHashCommands { * @param seconds the TTL {@link Duration} * @param expireArgs the {@link ExpireArgs}. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Executions hexpire(K key, Duration seconds, ExpireArgs expireArgs, K... fields); + Executions> hexpire(K key, Duration seconds, ExpireArgs expireArgs, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -489,11 +497,13 @@ public interface NodeSelectionHashCommands { * @param key the key. * @param timestamp the timestamp type: posix time. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set (see: {@code EXPIRE}). + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Executions hexpireat(K key, long timestamp, K... fields); + Executions> hexpireat(K key, long timestamp, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -502,11 +512,13 @@ public interface NodeSelectionHashCommands { * @param timestamp the timestamp type: posix time. * @param expireArgs the expire arguments. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set (see: {@code EXPIRE}). + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Executions hexpireat(K key, long timestamp, ExpireArgs expireArgs, K... fields); + Executions> hexpireat(K key, long timestamp, ExpireArgs expireArgs, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -514,11 +526,13 @@ public interface NodeSelectionHashCommands { * @param key the key. * @param timestamp the timestamp type: posix time. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set (see: {@code EXPIRE}). + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Executions hexpireat(K key, Date timestamp, K... fields); + Executions> hexpireat(K key, Date timestamp, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -527,11 +541,13 @@ public interface NodeSelectionHashCommands { * @param timestamp the timestamp type: posix time. * @param expireArgs the expire arguments. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set (see: {@code EXPIRE}). + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Executions hexpireat(K key, Date timestamp, ExpireArgs expireArgs, K... fields); + Executions> hexpireat(K key, Date timestamp, ExpireArgs expireArgs, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -539,11 +555,13 @@ public interface NodeSelectionHashCommands { * @param key the key. * @param timestamp the timestamp type: posix time. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set (see: {@code EXPIRE}). + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Executions hexpireat(K key, Instant timestamp, K... fields); + Executions> hexpireat(K key, Instant timestamp, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -552,33 +570,215 @@ public interface NodeSelectionHashCommands { * @param timestamp the timestamp type: posix time. * @param expireArgs the expire arguments. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set (see: {@code EXPIRE}). + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Executions hexpireat(K key, Instant timestamp, ExpireArgs expireArgs, K... fields); + Executions> hexpireat(K key, Instant timestamp, ExpireArgs expireArgs, K... fields); /** - * Get the time to live for one or more fields in as unix timestamp in seconds. + * Get the time to live for one or more fields in as UNIX timestamp in seconds. * * @param key the key. * @param fields one or more fields to get the TTL for. - * @return Long integer-reply in seconds, or a negative value in order to signal an error. The command returns {@code -1} if - * the key exists but has no associated expiration time. The command returns {@code -2} if the key does not exist. + * @return a list of {@link Long} values for each of the fields provided: expiration time as a UNIX timestamp in seconds; + * {@code -1} indicating the field has no expiry time set; {@code -2} indicating there is no such field * @since 7.0 */ - Executions hexpiretime(K key, K... fields); + Executions> hexpiretime(K key, K... fields); /** * Remove the expiration from one or more fields. * * @param key the key. * @param fields one or more fields to remove the TTL for. - * @return Boolean integer-reply specifically: + * @return a list of {@link Long} values for each of the fields provided: {@code 1} indicating expiration time is removed; + * {@code -1} field has no expiration time to be removed; {@code -2} indicating there is no such field + * @since 7.0 + */ + Executions> hpersist(K key, K... fields); + + /** + * Set the time to live for one or more fields in milliseconds. * - * {@code true} if the timeout was removed. {@code false} if {@code key} does not exist or does not have an - * associated timeout. + * @param key the key. + * @param milliseconds the milliseconds type: long. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + Executions> hpexpire(K key, long milliseconds, K... fields); + + /** + * Set the time to live for one or more fields in milliseconds. + * + * @param key the key. + * @param milliseconds the milliseconds type: long. + * @param expireArgs the expire arguments. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + Executions> hpexpire(K key, long milliseconds, ExpireArgs expireArgs, K... fields); + + /** + * Set the time to live for one or more fields in milliseconds. + * + * @param key the key. + * @param milliseconds the milliseconds. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + Executions> hpexpire(K key, Duration milliseconds, K... fields); + + /** + * Set the time to live for one or more fields in milliseconds. + * + * @param key the key. + * @param milliseconds the milliseconds. + * @param expireArgs the expire arguments. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + Executions> hpexpire(K key, Duration milliseconds, ExpireArgs expireArgs, K... fields); + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + Executions> hpexpireat(K key, long timestamp, K... fields); + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param expireArgs the expire arguments. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + Executions> hpexpireat(K key, long timestamp, ExpireArgs expireArgs, K... fields); + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + Executions> hpexpireat(K key, Date timestamp, K... fields); + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param expireArgs the expire arguments. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + Executions> hpexpireat(K key, Date timestamp, ExpireArgs expireArgs, K... fields); + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + Executions> hpexpireat(K key, Instant timestamp, K... fields); + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param expireArgs the expire arguments. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + Executions> hpexpireat(K key, Instant timestamp, ExpireArgs expireArgs, K... fields); + + /** + * Get the time to live for one or more fields as UNIX timestamp in milliseconds. + * + * @param key the key. + * @param fields one or more fields to get the TTL for. + * @return a list of {@link Long} values for each of the fields provided: expiration time as a UNIX timestamp in + * milliseconds; {@code -1} indicating the field has no expiry time set; {@code -2} indicating there is no such + * field + * @since 7.0 + */ + Executions> hpexpiretime(K key, K... fields); + + /** + * Get the time to live for one or more fields. + * + * @param key the key. + * @param fields one or more fields to get the TTL for. + * @return a list of {@link Long} values for each of the fields provided: the time to live in seconds; or a negative value + * in order to signal an error. The command returns {@code -1} if the key exists but has no associated expiration + * time. The command returns {@code -2} if the key does not exist. + * @since 7.0 + */ + Executions> httl(K key, K... fields); + + /** + * Get the time to live for one or more fields in milliseconds. + * + * @param key the key. + * @param fields one or more fields to get the TTL for. + * @return a list of {@link Long} values for each of the fields provided: the time to live in milliseconds; or a negative + * value in order to signal an error. The command returns {@code -1} if the key exists but has no associated + * expiration time. The command returns {@code -2} if the key does not exist. + * @since 7.0 */ - Executions hpersist(K key, K... fields); + Executions> hpttl(K key, K... fields); } diff --git a/src/main/java/io/lettuce/core/output/IntegerListOutput.java b/src/main/java/io/lettuce/core/output/IntegerListOutput.java index d23acd8dc6..a92a895fdc 100644 --- a/src/main/java/io/lettuce/core/output/IntegerListOutput.java +++ b/src/main/java/io/lettuce/core/output/IntegerListOutput.java @@ -1,11 +1,12 @@ package io.lettuce.core.output; -import java.util.Collections; -import java.util.List; - import io.lettuce.core.codec.RedisCodec; import io.lettuce.core.internal.LettuceAssert; +import java.nio.ByteBuffer; +import java.util.Collections; +import java.util.List; + /** * {@link List} of 64-bit integer output. * @@ -30,6 +31,16 @@ public void set(long integer) { subscriber.onNext(output, integer); } + @Override + public void set(ByteBuffer bytes) { + // nil results should produce an empty list + if (bytes == null) { + return; + } + + super.set(bytes); + } + @Override public void multi(int count) { diff --git a/src/main/java/io/lettuce/core/protocol/CommandKeyword.java b/src/main/java/io/lettuce/core/protocol/CommandKeyword.java index 1d8f7266ab..6e1af5429f 100644 --- a/src/main/java/io/lettuce/core/protocol/CommandKeyword.java +++ b/src/main/java/io/lettuce/core/protocol/CommandKeyword.java @@ -37,7 +37,7 @@ public enum CommandKeyword implements ProtocolKeyword { BY, BYLEX, BYSCORE, CACHING, CAT, CH, CHANNELS, COPY, COUNT, COUNTKEYSINSLOT, CONSUMERS, CREATE, DB, DELSLOTS, DELSLOTSRANGE, DELUSER, DESC, DRYRUN, SOFT, HARD, ENCODING, - FAILOVER, FORGET, FLUSH, FORCE, FREQ, FLUSHSLOTS, GENPASS, GETNAME, GETUSER, GETKEYSINSLOT, GETREDIR, GROUP, GROUPS, HTSTATS, ID, IDLE, INFO, + FAILOVER, FORGET, FIELDS, FLUSH, FORCE, FREQ, FLUSHSLOTS, GENPASS, GETNAME, GETUSER, GETKEYSINSLOT, GETREDIR, GROUP, GROUPS, HTSTATS, ID, IDLE, INFO, IDLETIME, JUSTID, KILL, KEYSLOT, LEFT, LEN, LIMIT, LIST, LOAD, LOG, MATCH, diff --git a/src/main/java/io/lettuce/core/protocol/CommandType.java b/src/main/java/io/lettuce/core/protocol/CommandType.java index 37ae008fb1..427ce80184 100644 --- a/src/main/java/io/lettuce/core/protocol/CommandType.java +++ b/src/main/java/io/lettuce/core/protocol/CommandType.java @@ -46,7 +46,7 @@ public enum CommandType implements ProtocolKeyword { // Keys - COPY, DEL, DUMP, EXISTS, HEXPIRE, EXPIRE, HEXPIREAT, EXPIREAT, HEXPIRETIME, EXPIRETIME, KEYS, MIGRATE, MOVE, OBJECT, HPERSIST, PERSIST, PEXPIRE, PEXPIREAT, PEXPIRETIME, PTTL, RANDOMKEY, RENAME, RENAMENX, RESTORE, TOUCH, TTL, TYPE, SCAN, UNLINK, + COPY, DEL, DUMP, EXISTS, HEXPIRE, EXPIRE, HEXPIREAT, EXPIREAT, HEXPIRETIME, EXPIRETIME, KEYS, MIGRATE, MOVE, OBJECT, HPERSIST, PERSIST, PEXPIRE, HPEXPIRE, PEXPIREAT, HPEXPIREAT, PEXPIRETIME, HPEXPIRETIME, PTTL, HPTTL, RANDOMKEY, RENAME, RENAMENX, RESTORE, TOUCH, TTL, HTTL, TYPE, SCAN, UNLINK, // String diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisHashCoroutinesCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisHashCoroutinesCommands.kt index 34a4228f49..99c330a35b 100644 --- a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisHashCoroutinesCommands.kt +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisHashCoroutinesCommands.kt @@ -1,5 +1,5 @@ /* - * Copyright 2020-Present, Redis Ltd. and Contributors + * Copyright 2017-Present, Redis Ltd. and Contributors * All rights reserved. * * Licensed under the MIT License. @@ -313,11 +313,13 @@ interface RedisHashCoroutinesCommands { * @param key the key of the fields. * @param seconds the seconds type: long. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: `true` if the timeout was set. `false` if `key` does not - * exist or the timeout could not be set. + * @return a list of [Long] values for each of the fields provided: `2` indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; `1` indicating expiration time is + * set/updated; `0` indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); `-2` indicating there is no such field * @since 7.0 */ - suspend fun hexpire(key: K, seconds: Long, vararg fields: K): Boolean? + suspend fun hexpire(key: K, seconds: Long, vararg fields: K): List /** * Set the time to live (in seconds) for one or more fields, belonging to a certain key. @@ -326,11 +328,13 @@ interface RedisHashCoroutinesCommands { * @param seconds the seconds type: long. * @param expireArgs the expire arguments. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: `true` if the timeout was set. `false` if `key` does not - * exist or the timeout could not be set. + * @return a list of [Long] values for each of the fields provided: `2` indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; `1` indicating expiration time is + * set/updated; `0` indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); `-2` indicating there is no such field * @since 7.0 */ - suspend fun hexpire(key: K, seconds: Long, expireArgs: ExpireArgs, vararg fields: K): Boolean? + suspend fun hexpire(key: K, seconds: Long, expireArgs: ExpireArgs, vararg fields: K): List /** * Set the time to live for one or more fields, belonging to a certain key. @@ -338,11 +342,13 @@ interface RedisHashCoroutinesCommands { * @param key the key. * @param seconds the TTL [Duration] * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: `true` if the timeout was set. `false` if `key` does not - * exist or the timeout could not be set. + * @return a list of [Long] values for each of the fields provided: `2` indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; `1` indicating expiration time is + * set/updated; `0` indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); `-2` indicating there is no such field * @since 7.0 */ - suspend fun hexpire(key: K, seconds: Duration, vararg fields: K): Boolean? + suspend fun hexpire(key: K, seconds: Duration, vararg fields: K): List /** * Set the time to live for one or more fields, belonging to a certain key. @@ -351,11 +357,13 @@ interface RedisHashCoroutinesCommands { * @param seconds the TTL [Duration] * @param expireArgs the [ExpireArgs]. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: `true` if the timeout was set. `false` if `key` does not - * exist or the timeout could not be set. + * @return a list of [Long] values for each of the fields provided: `2` indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; `1` indicating expiration time is + * set/updated; `0` indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); `-2` indicating there is no such field * @since 7.0 */ - suspend fun hexpire(key: K, seconds: Duration, expireArgs: ExpireArgs, vararg fields: K): Boolean? + suspend fun hexpire(key: K, seconds: Duration, expireArgs: ExpireArgs, vararg fields: K): List /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -363,11 +371,13 @@ interface RedisHashCoroutinesCommands { * @param key the key. * @param timestamp the timestamp type: posix time. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: `true` if the timeout was set. `false` if `key` does not - * exist or the timeout could not be set (see: `EXPIRE`). + * @return a list of [Long] values for each of the fields provided: `2` indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; `1` indicating expiration time is + * set/updated; `0` indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); `-2` indicating there is no such field * @since 7.0 */ - suspend fun hexpireat(key: K, timestamp: Long, vararg fields: K): Boolean? + suspend fun hexpireat(key: K, timestamp: Long, vararg fields: K): List /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -376,11 +386,13 @@ interface RedisHashCoroutinesCommands { * @param timestamp the timestamp type: posix time. * @param expireArgs the expire arguments. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: `true` if the timeout was set. `false` if `key` does not - * exist or the timeout could not be set (see: `EXPIRE`). + * @return a list of [Long] values for each of the fields provided: `2` indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; `1` indicating expiration time is + * set/updated; `0` indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); `-2` indicating there is no such field * @since 7.0 */ - suspend fun hexpireat(key: K, timestamp: Long, expireArgs: ExpireArgs, vararg fields: K): Boolean? + suspend fun hexpireat(key: K, timestamp: Long, expireArgs: ExpireArgs, vararg fields: K): List /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -388,11 +400,13 @@ interface RedisHashCoroutinesCommands { * @param key the key. * @param timestamp the timestamp type: posix time. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: `true` if the timeout was set. `false` if `key` does not - * exist or the timeout could not be set (see: `EXPIRE`). + * @return a list of [Long] values for each of the fields provided: `2` indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; `1` indicating expiration time is + * set/updated; `0` indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); `-2` indicating there is no such field * @since 7.0 */ - suspend fun hexpireat(key: K, timestamp: Date, vararg fields: K): Boolean? + suspend fun hexpireat(key: K, timestamp: Date, vararg fields: K): List /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -401,11 +415,13 @@ interface RedisHashCoroutinesCommands { * @param timestamp the timestamp type: posix time. * @param expireArgs the expire arguments. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: `true` if the timeout was set. `false` if `key` does not - * exist or the timeout could not be set (see: `EXPIRE`). + * @return a list of [Long] values for each of the fields provided: `2` indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; `1` indicating expiration time is + * set/updated; `0` indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); `-2` indicating there is no such field * @since 7.0 */ - suspend fun hexpireat(key: K, timestamp: Date, expireArgs: ExpireArgs, vararg fields: K): Boolean? + suspend fun hexpireat(key: K, timestamp: Date, expireArgs: ExpireArgs, vararg fields: K): List /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -413,11 +429,13 @@ interface RedisHashCoroutinesCommands { * @param key the key. * @param timestamp the timestamp type: posix time. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: `true` if the timeout was set. `false` if `key` does not - * exist or the timeout could not be set (see: `EXPIRE`). + * @return a list of [Long] values for each of the fields provided: `2` indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; `1` indicating expiration time is + * set/updated; `0` indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); `-2` indicating there is no such field * @since 7.0 */ - suspend fun hexpireat(key: K, timestamp: Instant, vararg fields: K): Boolean? + suspend fun hexpireat(key: K, timestamp: Instant, vararg fields: K): List /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -426,34 +444,215 @@ interface RedisHashCoroutinesCommands { * @param timestamp the timestamp type: posix time. * @param expireArgs the expire arguments. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: `true` if the timeout was set. `false` if `key` does not - * exist or the timeout could not be set (see: `EXPIRE`). + * @return a list of [Long] values for each of the fields provided: `2` indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; `1` indicating expiration time is + * set/updated; `0` indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); `-2` indicating there is no such field * @since 7.0 */ - suspend fun hexpireat(key: K, timestamp: Instant, expireArgs: ExpireArgs, vararg fields: K): Boolean? + suspend fun hexpireat(key: K, timestamp: Instant, expireArgs: ExpireArgs, vararg fields: K): List /** - * Get the time to live for one or more fields in as unix timestamp in seconds. + * Get the time to live for one or more fields in as UNIX timestamp in seconds. * * @param key the key. * @param fields one or more fields to get the TTL for. - * @return Long integer-reply in seconds, or a negative value in order to signal an error. The command returns `-1` if - * the key exists but has no associated expiration time. The command returns `-2` if the key does not exist. + * @return a list of [Long] values for each of the fields provided: expiration time as a UNIX timestamp in seconds; + * `-1` indicating the field has no expiry time set; `-2` indicating there is no such field * @since 7.0 */ - suspend fun hexpiretime(key: K, vararg fields: K): Long? + suspend fun hexpiretime(key: K, vararg fields: K): List /** * Remove the expiration from one or more fields. * * @param key the key. * @param fields one or more fields to remove the TTL for. - * @return Boolean integer-reply specifically: + * @return a list of [Long] values for each of the fields provided: `1` indicating expiration time is removed; + * `-1` field has no expiration time to be removed; `-2` indicating there is no such field + * @since 7.0 + */ + suspend fun hpersist(key: K, vararg fields: K): List + + /** + * Set the time to live for one or more fields in milliseconds. * - * `true` if the timeout was removed. `false` if `key` does not exist or does not have an - * associated timeout. + * @param key the key. + * @param milliseconds the milliseconds type: long. + * @param fields one or more fields to set the TTL for. + * @return a list of [Long] values for each of the fields provided: `2` indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; `1` indicating expiration time is + * set/updated; `0` indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); `-2` indicating there is no such field + * @since 7.0 + */ + suspend fun hpexpire(key: K, milliseconds: Long, vararg fields: K): List + + /** + * Set the time to live for one or more fields in milliseconds. + * + * @param key the key. + * @param milliseconds the milliseconds type: long. + * @param expireArgs the expire arguments. + * @param fields one or more fields to set the TTL for. + * @return a list of [Long] values for each of the fields provided: `2` indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; `1` indicating expiration time is + * set/updated; `0` indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); `-2` indicating there is no such field + * @since 7.0 + */ + suspend fun hpexpire(key: K, milliseconds: Long, expireArgs: ExpireArgs, vararg fields: K): List + + /** + * Set the time to live for one or more fields in milliseconds. + * + * @param key the key. + * @param milliseconds the milliseconds. + * @param fields one or more fields to set the TTL for. + * @return a list of [Long] values for each of the fields provided: `2` indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; `1` indicating expiration time is + * set/updated; `0` indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); `-2` indicating there is no such field + * @since 7.0 + */ + suspend fun hpexpire(key: K, milliseconds: Duration, vararg fields: K): List + + /** + * Set the time to live for one or more fields in milliseconds. + * + * @param key the key. + * @param milliseconds the milliseconds. + * @param expireArgs the expire arguments. + * @param fields one or more fields to set the TTL for. + * @return a list of [Long] values for each of the fields provided: `2` indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; `1` indicating expiration time is + * set/updated; `0` indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); `-2` indicating there is no such field + * @since 7.0 + */ + suspend fun hpexpire(key: K, milliseconds: Duration, expireArgs: ExpireArgs, vararg fields: K): List + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param fields one or more fields to set the TTL for. + * @return a list of [Long] values for each of the fields provided: `2` indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; `1` indicating expiration time is + * set/updated; `0` indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); `-2` indicating there is no such field + * @since 7.0 + */ + suspend fun hpexpireat(key: K, timestamp: Long, vararg fields: K): List + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param expireArgs the expire arguments. + * @param fields one or more fields to set the TTL for. + * @return a list of [Long] values for each of the fields provided: `2` indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; `1` indicating expiration time is + * set/updated; `0` indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); `-2` indicating there is no such field + * @since 7.0 + */ + suspend fun hpexpireat(key: K, timestamp: Long, expireArgs: ExpireArgs, vararg fields: K): List + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param fields one or more fields to set the TTL for. + * @return a list of [Long] values for each of the fields provided: `2` indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; `1` indicating expiration time is + * set/updated; `0` indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); `-2` indicating there is no such field + * @since 7.0 + */ + suspend fun hpexpireat(key: K, timestamp: Date, vararg fields: K): List + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param expireArgs the expire arguments. + * @param fields one or more fields to set the TTL for. + * @return a list of [Long] values for each of the fields provided: `2` indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; `1` indicating expiration time is + * set/updated; `0` indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); `-2` indicating there is no such field + * @since 7.0 + */ + suspend fun hpexpireat(key: K, timestamp: Date, expireArgs: ExpireArgs, vararg fields: K): List + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param fields one or more fields to set the TTL for. + * @return a list of [Long] values for each of the fields provided: `2` indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; `1` indicating expiration time is + * set/updated; `0` indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); `-2` indicating there is no such field + * @since 7.0 + */ + suspend fun hpexpireat(key: K, timestamp: Instant, vararg fields: K): List + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param expireArgs the expire arguments. + * @param fields one or more fields to set the TTL for. + * @return a list of [Long] values for each of the fields provided: `2` indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; `1` indicating expiration time is + * set/updated; `0` indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); `-2` indicating there is no such field + * @since 7.0 + */ + suspend fun hpexpireat(key: K, timestamp: Instant, expireArgs: ExpireArgs, vararg fields: K): List + + /** + * Get the time to live for one or more fields as UNIX timestamp in milliseconds. + * + * @param key the key. + * @param fields one or more fields to get the TTL for. + * @return a list of [Long] values for each of the fields provided: expiration time as a UNIX timestamp in milliseconds; + * `-1` indicating the field has no expiry time set; `-2` indicating there is no such field + * @since 7.0 + */ + suspend fun hpexpiretime(key: K, vararg fields: K): List + + /** + * Get the time to live for one or more fields. + * + * @param key the key. + * @param fields one or more fields to get the TTL for. + * @return a list of [Long] values for each of the fields provided: the time to live in seconds; or a negative value in + * order to signal an error. The command returns `-1` if the key exists but has no associated expiration time. + * The command returns `-2` if the key does not exist. + * @since 7.0 + */ + suspend fun httl(key: K, vararg fields: K): List + + /** + * Get the time to live for one or more fields in milliseconds. + * + * @param key the key. + * @param fields one or more fields to get the TTL for. + * @return a list of [Long] values for each of the fields provided: the time to live in milliseconds; or a negative + * value in order to signal an error. The command returns `-1` if the key exists but has no associated + * expiration time. The command returns `-2` if the key does not exist. + * @since 7.0 */ - suspend fun hpersist(key: K, vararg fields: K): Boolean? + suspend fun hpttl(key: K, vararg fields: K): List } diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisHashCoroutinesCommandsImpl.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisHashCoroutinesCommandsImpl.kt index 8a1d959e54..23231b5f5b 100644 --- a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisHashCoroutinesCommandsImpl.kt +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisHashCoroutinesCommandsImpl.kt @@ -116,60 +116,123 @@ internal class RedisHashCoroutinesCommandsImpl(internal val op override fun hvals(key: K): Flow = ops.hvals(key).asFlow() - override suspend fun hexpire(key: K, seconds: Long, vararg fields: K): Boolean? = - ops.hexpire(key, seconds, *fields).awaitFirstOrNull() + override suspend fun hexpire(key: K, seconds: Long, vararg fields: K): List = + ops.hexpire(key, seconds, *fields).asFlow().toList() - override suspend fun hexpire(key: K, seconds: Long, expireArgs: ExpireArgs, vararg fields: K): Boolean? = - ops.hexpire(key, seconds, expireArgs, *fields).awaitFirstOrNull() + override suspend fun hexpire(key: K, seconds: Long, expireArgs: ExpireArgs, vararg fields: K): List = + ops.hexpire(key, seconds, expireArgs, *fields).asFlow().toList() - override suspend fun hexpire(key: K, seconds: Duration, vararg fields: K): Boolean? = - ops.hexpire(key, seconds, *fields).awaitFirstOrNull() + override suspend fun hexpire(key: K, seconds: Duration, vararg fields: K): List = + ops.hexpire(key, seconds, *fields).asFlow().toList() override suspend fun hexpire( key: K, seconds: Duration, expireArgs: ExpireArgs, vararg fields: K - ): Boolean? = - ops.hexpire(key, seconds, expireArgs, *fields).awaitFirstOrNull() + ): List = + ops.hexpire(key, seconds, expireArgs, *fields).asFlow().toList() - override suspend fun hexpireat(key: K, timestamp: Date, vararg fields: K): Boolean? = - ops.hexpireat(key, timestamp, *fields).awaitFirstOrNull() + override suspend fun hexpireat(key: K, timestamp: Date, vararg fields: K): List = + ops.hexpireat(key, timestamp, *fields).asFlow().toList() override suspend fun hexpireat( key: K, timestamp: Long, expireArgs: ExpireArgs, vararg fields: K - ): Boolean? = - ops.hexpireat(key, timestamp, expireArgs, *fields).awaitFirstOrNull() + ): List = + ops.hexpireat(key, timestamp, expireArgs, *fields).asFlow().toList() - override suspend fun hexpireat(key: K, timestamp: Instant, vararg fields: K): Boolean? = - ops.hexpireat(key, timestamp, *fields).awaitFirstOrNull() + override suspend fun hexpireat(key: K, timestamp: Instant, vararg fields: K): List = + ops.hexpireat(key, timestamp, *fields).asFlow().toList() override suspend fun hexpireat( key: K, timestamp: Instant, expireArgs: ExpireArgs, vararg fields: K - ): Boolean? = - ops.hexpireat(key, timestamp, expireArgs, *fields).awaitFirstOrNull() + ): List = + ops.hexpireat(key, timestamp, expireArgs, *fields).asFlow().toList() - override suspend fun hexpireat(key: K, timestamp: Long, vararg fields: K): Boolean? = - ops.hexpireat(key, timestamp, *fields).awaitFirstOrNull() + override suspend fun hexpireat(key: K, timestamp: Long, vararg fields: K): List = + ops.hexpireat(key, timestamp, *fields).asFlow().toList() override suspend fun hexpireat( key: K, timestamp: Date, expireArgs: ExpireArgs, vararg fields: K - ): Boolean? = - ops.hexpireat(key, timestamp, expireArgs, *fields).awaitFirstOrNull() + ): List = + ops.hexpireat(key, timestamp, expireArgs, *fields).asFlow().toList() - override suspend fun hexpiretime(key: K, vararg fields: K): Long? = - ops.hexpiretime(key).awaitFirstOrNull() + override suspend fun hexpiretime(key: K, vararg fields: K): List = + ops.hexpiretime(key).asFlow().toList() - override suspend fun hpersist(key: K, vararg fields: K): Boolean? = ops.hpersist(key).awaitFirstOrNull() + override suspend fun hpersist(key: K, vararg fields: K): List = ops.hpersist(key).asFlow().toList() + override suspend fun hpexpire(key: K, milliseconds: Long, vararg fields: K): List = + ops.hpexpire(key, milliseconds, *fields).asFlow().toList() + + override suspend fun hpexpire( + key: K, + milliseconds: Long, + expireArgs: ExpireArgs, + vararg fields: K + ): List = + ops.hpexpire(key, milliseconds, expireArgs, *fields).asFlow().toList() + + override suspend fun hpexpire(key: K, milliseconds: Duration, vararg fields: K): List = + ops.hpexpire(key, milliseconds, *fields).asFlow().toList() + + override suspend fun hpexpire( + key: K, + milliseconds: Duration, + expireArgs: ExpireArgs, + vararg fields: K + ): List = + ops.hpexpire(key, milliseconds, expireArgs, *fields).asFlow().toList() + + override suspend fun hpexpireat(key: K, timestamp: Long, vararg fields: K): List = + ops.hpexpireat(key, timestamp, *fields).asFlow().toList() + + override suspend fun hpexpireat( + key: K, + timestamp: Long, + expireArgs: ExpireArgs, + vararg fields: K + ): List = + ops.hpexpireat(key, timestamp, expireArgs, *fields).asFlow().toList() + + override suspend fun hpexpireat(key: K, timestamp: Date, vararg fields: K): List = + ops.hpexpireat(key, timestamp, *fields).asFlow().toList() + + override suspend fun hpexpireat( + key: K, + timestamp: Date, + expireArgs: ExpireArgs, + vararg fields: K + ): List = + ops.hpexpireat(key, timestamp, expireArgs, *fields).asFlow().toList() + + override suspend fun hpexpireat(key: K, timestamp: Instant, vararg fields: K): List = + ops.hpexpireat(key, timestamp, *fields).asFlow().toList() + + override suspend fun hpexpireat( + key: K, + timestamp: Instant, + expireArgs: ExpireArgs, + vararg fields: K + ): List = + ops.hpexpireat(key, timestamp, expireArgs, *fields).asFlow().toList() + + override suspend fun hpexpiretime(key: K, vararg fields: K): List = + ops.hpexpiretime(key, *fields).asFlow().toList() + + override suspend fun httl(key: K, vararg fields: K): List = + ops.httl(key, *fields).asFlow().toList() + + override suspend fun hpttl(key: K, vararg fields: K): List = + ops.hpttl(key, *fields).asFlow().toList() } diff --git a/src/main/templates/io/lettuce/core/api/RedisHashCommands.java b/src/main/templates/io/lettuce/core/api/RedisHashCommands.java index 53896d05a7..4d44cc2979 100644 --- a/src/main/templates/io/lettuce/core/api/RedisHashCommands.java +++ b/src/main/templates/io/lettuce/core/api/RedisHashCommands.java @@ -434,11 +434,13 @@ public interface RedisHashCommands { * @param key the key of the fields. * @param seconds the seconds type: long. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Boolean hexpire(K key, long seconds, K... fields); + List hexpire(K key, long seconds, K... fields); /** * Set the time to live (in seconds) for one or more fields, belonging to a certain key. @@ -447,11 +449,13 @@ public interface RedisHashCommands { * @param seconds the seconds type: long. * @param expireArgs the expire arguments. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Boolean hexpire(K key, long seconds, ExpireArgs expireArgs, K... fields); + List hexpire(K key, long seconds, ExpireArgs expireArgs, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key. @@ -459,11 +463,13 @@ public interface RedisHashCommands { * @param key the key. * @param seconds the TTL {@link Duration} * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Boolean hexpire(K key, Duration seconds, K... fields); + List hexpire(K key, Duration seconds, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key. @@ -472,11 +478,13 @@ public interface RedisHashCommands { * @param seconds the TTL {@link Duration} * @param expireArgs the {@link ExpireArgs}. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Boolean hexpire(K key, Duration seconds, ExpireArgs expireArgs, K... fields); + List hexpire(K key, Duration seconds, ExpireArgs expireArgs, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -484,11 +492,13 @@ public interface RedisHashCommands { * @param key the key. * @param timestamp the timestamp type: posix time. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set (see: {@code EXPIRE}). + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Boolean hexpireat(K key, long timestamp, K... fields); + List hexpireat(K key, long timestamp, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -497,11 +507,13 @@ public interface RedisHashCommands { * @param timestamp the timestamp type: posix time. * @param expireArgs the expire arguments. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set (see: {@code EXPIRE}). + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Boolean hexpireat(K key, long timestamp, ExpireArgs expireArgs, K... fields); + List hexpireat(K key, long timestamp, ExpireArgs expireArgs, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -509,11 +521,13 @@ public interface RedisHashCommands { * @param key the key. * @param timestamp the timestamp type: posix time. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set (see: {@code EXPIRE}). + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Boolean hexpireat(K key, Date timestamp, K... fields); + List hexpireat(K key, Date timestamp, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -522,11 +536,13 @@ public interface RedisHashCommands { * @param timestamp the timestamp type: posix time. * @param expireArgs the expire arguments. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set (see: {@code EXPIRE}). + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Boolean hexpireat(K key, Date timestamp, ExpireArgs expireArgs, K... fields); + List hexpireat(K key, Date timestamp, ExpireArgs expireArgs, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -534,11 +550,13 @@ public interface RedisHashCommands { * @param key the key. * @param timestamp the timestamp type: posix time. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set (see: {@code EXPIRE}). + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Boolean hexpireat(K key, Instant timestamp, K... fields); + List hexpireat(K key, Instant timestamp, K... fields); /** * Set the time to live for one or more fields, belonging to a certain key as a UNIX timestamp. @@ -547,33 +565,215 @@ public interface RedisHashCommands { * @param timestamp the timestamp type: posix time. * @param expireArgs the expire arguments. * @param fields one or more fields to set the TTL for. - * @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not - * exist or the timeout could not be set (see: {@code EXPIRE}). + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field * @since 7.0 */ - Boolean hexpireat(K key, Instant timestamp, ExpireArgs expireArgs, K... fields); + List hexpireat(K key, Instant timestamp, ExpireArgs expireArgs, K... fields); /** - * Get the time to live for one or more fields in as unix timestamp in seconds. + * Get the time to live for one or more fields in as UNIX timestamp in seconds. * * @param key the key. * @param fields one or more fields to get the TTL for. - * @return Long integer-reply in seconds, or a negative value in order to signal an error. The command returns {@code -1} if - * the key exists but has no associated expiration time. The command returns {@code -2} if the key does not exist. + * @return a list of {@link Long} values for each of the fields provided: expiration time as a UNIX timestamp in seconds; + * {@code -1} indicating the field has no expiry time set; {@code -2} indicating there is no such field * @since 7.0 */ - Long hexpiretime(K key, K... fields); + List hexpiretime(K key, K... fields); /** * Remove the expiration from one or more fields. * * @param key the key. * @param fields one or more fields to remove the TTL for. - * @return Boolean integer-reply specifically: + * @return a list of {@link Long} values for each of the fields provided: {@code 1} indicating expiration time is removed; + * {@code -1} field has no expiration time to be removed; {@code -2} indicating there is no such field + * @since 7.0 + */ + List hpersist(K key, K... fields); + + /** + * Set the time to live for one or more fields in milliseconds. * - * {@code true} if the timeout was removed. {@code false} if {@code key} does not exist or does not have an - * associated timeout. + * @param key the key. + * @param milliseconds the milliseconds type: long. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + List hpexpire(K key, long milliseconds, K... fields); + + /** + * Set the time to live for one or more fields in milliseconds. + * + * @param key the key. + * @param milliseconds the milliseconds type: long. + * @param expireArgs the expire arguments. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + List hpexpire(K key, long milliseconds, ExpireArgs expireArgs, K... fields); + + /** + * Set the time to live for one or more fields in milliseconds. + * + * @param key the key. + * @param milliseconds the milliseconds. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + List hpexpire(K key, Duration milliseconds, K... fields); + + /** + * Set the time to live for one or more fields in milliseconds. + * + * @param key the key. + * @param milliseconds the milliseconds. + * @param expireArgs the expire arguments. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is 0; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + List hpexpire(K key, Duration milliseconds, ExpireArgs expireArgs, K... fields); + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + List hpexpireat(K key, long timestamp, K... fields); + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param expireArgs the expire arguments. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + List hpexpireat(K key, long timestamp, ExpireArgs expireArgs, K... fields); + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + List hpexpireat(K key, Date timestamp, K... fields); + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param expireArgs the expire arguments. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + List hpexpireat(K key, Date timestamp, ExpireArgs expireArgs, K... fields); + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + List hpexpireat(K key, Instant timestamp, K... fields); + + /** + * Set the time to live for one or more fields as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @param expireArgs the expire arguments. + * @param fields one or more fields to set the TTL for. + * @return a list of {@link Long} values for each of the fields provided: {@code 2} indicating the specific field is deleted + * already due to expiration, or provided expriry interval is in the past; {@code 1} indicating expiration time is + * set/updated; {@code 0} indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not + * met); {@code -2} indicating there is no such field + * @since 7.0 + */ + List hpexpireat(K key, Instant timestamp, ExpireArgs expireArgs, K... fields); + + /** + * Get the time to live for one or more fields as UNIX timestamp in milliseconds. + * + * @param key the key. + * @param fields one or more fields to get the TTL for. + * @return a list of {@link Long} values for each of the fields provided: expiration time as a UNIX timestamp in + * milliseconds; {@code -1} indicating the field has no expiry time set; {@code -2} indicating there is no such + * field + * @since 7.0 + */ + List hpexpiretime(K key, K... fields); + + /** + * Get the time to live for one or more fields. + * + * @param key the key. + * @param fields one or more fields to get the TTL for. + * @return a list of {@link Long} values for each of the fields provided: the time to live in seconds; or a negative value + * in order to signal an error. The command returns {@code -1} if the key exists but has no associated expiration + * time. The command returns {@code -2} if the key does not exist. + * @since 7.0 + */ + List httl(K key, K... fields); + + /** + * Get the time to live for one or more fields in milliseconds. + * + * @param key the key. + * @param fields one or more fields to get the TTL for. + * @return a list of {@link Long} values for each of the fields provided: the time to live in milliseconds; or a negative + * value in order to signal an error. The command returns {@code -1} if the key exists but has no associated + * expiration time. The command returns {@code -2} if the key does not exist. + * @since 7.0 */ - Boolean hpersist(K key, K... fields); + List hpttl(K key, K... fields); } diff --git a/src/test/java/io/lettuce/core/RedisCommandBuilderUnitTests.java b/src/test/java/io/lettuce/core/RedisCommandBuilderUnitTests.java index b29d81ad21..5e6eba1939 100644 --- a/src/test/java/io/lettuce/core/RedisCommandBuilderUnitTests.java +++ b/src/test/java/io/lettuce/core/RedisCommandBuilderUnitTests.java @@ -44,9 +44,9 @@ void shouldCorrectlyConstructHexpire() { ByteBuf buf = Unpooled.directBuffer(); command.encode(buf); - assertThat(buf.toString(StandardCharsets.UTF_8)).isEqualTo( - "*8\r\n" + "$7\r\n" + "HEXPIRE\r\n" + "$4\r\n" + "hKey\r\n" + "$1\r\n" + "1\r\n" + "$2\r\n" + "NX\r\n" - + "$1\r\n" + "3\r\n" + "$7\r\n" + "hField1\r\n" + "$7\r\n" + "hField2\r\n" + "$7\r\n" + "hField3\r\n"); + assertThat(buf.toString(StandardCharsets.UTF_8)).isEqualTo("*9\r\n" + "$7\r\n" + "HEXPIRE\r\n" + "$4\r\n" + "hKey\r\n" + + "$1\r\n" + "1\r\n" + "$2\r\n" + "NX\r\n" + "$6\r\n" + "FIELDS\r\n" + "$1\r\n" + "3\r\n" + "$7\r\n" + + "hField1\r\n" + "$7\r\n" + "hField2\r\n" + "$7\r\n" + "hField3\r\n"); } @Test @@ -56,9 +56,9 @@ void shouldCorrectlyConstructHexpireat() { ByteBuf buf = Unpooled.directBuffer(); command.encode(buf); - assertThat(buf.toString(StandardCharsets.UTF_8)).isEqualTo( - "*8\r\n" + "$9\r\n" + "HEXPIREAT\r\n" + "$4\r\n" + "hKey\r\n" + "$1\r\n" + "1\r\n" + "$2\r\n" + "NX\r\n" - + "$1\r\n" + "3\r\n" + "$7\r\n" + "hField1\r\n" + "$7\r\n" + "hField2\r\n" + "$7\r\n" + "hField3\r\n"); + assertThat(buf.toString(StandardCharsets.UTF_8)).isEqualTo("*9\r\n" + "$9\r\n" + "HEXPIREAT\r\n" + "$4\r\n" + "hKey\r\n" + + "$1\r\n" + "1\r\n" + "$2\r\n" + "NX\r\n" + "$6\r\n" + "FIELDS\r\n" + "$1\r\n" + "3\r\n" + "$7\r\n" + + "hField1\r\n" + "$7\r\n" + "hField2\r\n" + "$7\r\n" + "hField3\r\n"); } @Test @@ -69,8 +69,8 @@ void shouldCorrectlyConstructHexpiretime() { command.encode(buf); assertThat(buf.toString(StandardCharsets.UTF_8)) - .isEqualTo("*6\r\n" + "$11\r\n" + "HEXPIRETIME\r\n" + "$4\r\n" + "hKey\r\n" + "$1\r\n" + "3\r\n" + "$7\r\n" - + "hField1\r\n" + "$7\r\n" + "hField2\r\n" + "$7\r\n" + "hField3\r\n"); + .isEqualTo("*7\r\n" + "$11\r\n" + "HEXPIRETIME\r\n" + "$4\r\n" + "hKey\r\n" + "$6\r\n" + "FIELDS\r\n" + "$1\r\n" + + "3\r\n" + "$7\r\n" + "hField1\r\n" + "$7\r\n" + "hField2\r\n" + "$7\r\n" + "hField3\r\n"); } @Test @@ -80,8 +80,70 @@ void shouldCorrectlyConstructHpersist() { ByteBuf buf = Unpooled.directBuffer(); command.encode(buf); - assertThat(buf.toString(StandardCharsets.UTF_8)).isEqualTo("*6\r\n" + "$8\r\n" + "HPERSIST\r\n" + "$4\r\n" + "hKey\r\n" - + "$1\r\n" + "3\r\n" + "$7\r\n" + "hField1\r\n" + "$7\r\n" + "hField2\r\n" + "$7\r\n" + "hField3\r\n"); + assertThat(buf.toString(StandardCharsets.UTF_8)) + .isEqualTo("*7\r\n" + "$8\r\n" + "HPERSIST\r\n" + "$4\r\n" + "hKey\r\n" + "$6\r\n" + "FIELDS\r\n" + "$1\r\n" + + "3\r\n" + "$7\r\n" + "hField1\r\n" + "$7\r\n" + "hField2\r\n" + "$7\r\n" + "hField3\r\n"); + } + + @Test + void shouldCorrectlyConstructHpexpire() { + + Command command = sut.hpexpire(MY_KEY, 1, ExpireArgs.Builder.nx(), MY_FIELD1, MY_FIELD2, MY_FIELD3); + ByteBuf buf = Unpooled.directBuffer(); + command.encode(buf); + + assertThat(buf.toString(StandardCharsets.UTF_8)).isEqualTo("*9\r\n" + "$8\r\n" + "HPEXPIRE\r\n" + "$4\r\n" + "hKey\r\n" + + "$1\r\n" + "1\r\n" + "$2\r\n" + "NX\r\n" + "$6\r\n" + "FIELDS\r\n" + "$1\r\n" + "3\r\n" + "$7\r\n" + + "hField1\r\n" + "$7\r\n" + "hField2\r\n" + "$7\r\n" + "hField3\r\n"); + } + + @Test + void shouldCorrectlyConstructHpexpireat() { + + Command command = sut.hpexpireat(MY_KEY, 1, ExpireArgs.Builder.nx(), MY_FIELD1, MY_FIELD2, + MY_FIELD3); + ByteBuf buf = Unpooled.directBuffer(); + command.encode(buf); + + assertThat(buf.toString(StandardCharsets.UTF_8)).isEqualTo("*9\r\n" + "$10\r\n" + "HPEXPIREAT\r\n" + "$4\r\n" + + "hKey\r\n" + "$1\r\n" + "1\r\n" + "$2\r\n" + "NX\r\n" + "$6\r\n" + "FIELDS\r\n" + "$1\r\n" + "3\r\n" + + "$7\r\n" + "hField1\r\n" + "$7\r\n" + "hField2\r\n" + "$7\r\n" + "hField3\r\n"); + } + + @Test + void shouldCorrectlyConstructHpexpiretime() { + + Command command = sut.hpexpiretime(MY_KEY, MY_FIELD1, MY_FIELD2, MY_FIELD3); + ByteBuf buf = Unpooled.directBuffer(); + command.encode(buf); + + assertThat(buf.toString(StandardCharsets.UTF_8)) + .isEqualTo("*7\r\n" + "$12\r\n" + "HPEXPIRETIME\r\n" + "$4\r\n" + "hKey\r\n" + "$6\r\n" + "FIELDS\r\n" + + "$1\r\n" + "3\r\n" + "$7\r\n" + "hField1\r\n" + "$7\r\n" + "hField2\r\n" + "$7\r\n" + "hField3\r\n"); + } + + @Test + void shouldCorrectlyConstructHttl() { + + Command command = sut.httl(MY_KEY, MY_FIELD1, MY_FIELD2, MY_FIELD3); + ByteBuf buf = Unpooled.directBuffer(); + command.encode(buf); + + assertThat(buf.toString(StandardCharsets.UTF_8)) + .isEqualTo("*7\r\n" + "$4\r\n" + "HTTL\r\n" + "$4\r\n" + "hKey\r\n" + "$6\r\n" + "FIELDS\r\n" + "$1\r\n" + + "3\r\n" + "$7\r\n" + "hField1\r\n" + "$7\r\n" + "hField2\r\n" + "$7\r\n" + "hField3\r\n"); + } + + @Test + void shouldCorrectlyConstructHpttl() { + + Command command = sut.hpttl(MY_KEY, MY_FIELD1, MY_FIELD2, MY_FIELD3); + ByteBuf buf = Unpooled.directBuffer(); + command.encode(buf); + + assertThat(buf.toString(StandardCharsets.UTF_8)) + .isEqualTo("*7\r\n" + "$5\r\n" + "HPTTL\r\n" + "$4\r\n" + "hKey\r\n" + "$6\r\n" + "FIELDS\r\n" + "$1\r\n" + + "3\r\n" + "$7\r\n" + "hField1\r\n" + "$7\r\n" + "hField2\r\n" + "$7\r\n" + "hField3\r\n"); } } diff --git a/src/test/java/io/lettuce/core/SslIntegrationTests.java b/src/test/java/io/lettuce/core/SslIntegrationTests.java index cee9db988a..e9d6c1cd67 100644 --- a/src/test/java/io/lettuce/core/SslIntegrationTests.java +++ b/src/test/java/io/lettuce/core/SslIntegrationTests.java @@ -19,27 +19,6 @@ */ package io.lettuce.core; -import static io.lettuce.test.settings.TestSettings.*; -import static org.assertj.core.api.Assertions.*; -import static org.junit.jupiter.api.Assumptions.*; - -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; -import java.time.Duration; -import java.util.List; -import java.util.function.Function; -import java.util.stream.Collectors; -import java.util.stream.IntStream; - -import javax.inject.Inject; - -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - import io.lettuce.core.api.StatefulRedisConnection; import io.lettuce.core.api.sync.RedisCommands; import io.lettuce.core.codec.StringCodec; @@ -52,6 +31,26 @@ import io.lettuce.test.Wait; import io.lettuce.test.settings.TestSettings; import io.netty.handler.ssl.OpenSsl; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import javax.inject.Inject; +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; +import java.time.Duration; +import java.util.List; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +import static io.lettuce.test.settings.TestSettings.sslPort; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assumptions.assumeTrue; /** * Tests using SSL via {@link RedisClient}. @@ -382,6 +381,9 @@ void masterSlaveSslWithAllInvalidHostsWillFail() { } @Test + @Disabled + // This test is frequently failing on the pipeline and passing locally, so is considered very unstable + // The 120 seconds timeout used to stabilize it somewhat, but no longer void pubSubSsl() { RedisPubSubCommands connection = redisClient.connectPubSub(URI_NO_VERIFY).sync(); diff --git a/src/test/java/io/lettuce/core/commands/HashCommandIntegrationTests.java b/src/test/java/io/lettuce/core/commands/HashCommandIntegrationTests.java index e6431f97a7..f6148209c6 100644 --- a/src/test/java/io/lettuce/core/commands/HashCommandIntegrationTests.java +++ b/src/test/java/io/lettuce/core/commands/HashCommandIntegrationTests.java @@ -32,7 +32,6 @@ import io.lettuce.test.LettuceExtension; import io.lettuce.test.ListStreamingAdapter; import io.lettuce.test.condition.EnabledOnCommand; -import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; @@ -68,6 +67,8 @@ public class HashCommandIntegrationTests extends TestSupport { public static final String MY_FIELD = "hField"; + public static final String MY_SECOND_FIELD = "hSecondField"; + public static final String MY_VALUE = "hValue"; private final RedisCommands redis; @@ -82,13 +83,6 @@ void setUp() { this.redis.flushall(); } - @AfterEach - void tearDown() { - // resets the configuration settings to default, would not be needed once listpack is supported - assertThat(redis.configSet("hash-max-listpack-entries", "512")).isEqualTo("OK"); - assertThat(redis.configSet("set-max-listpack-value", "64")).isEqualTo("OK"); - } - @Test void hdel() { assertThat(redis.hdel(key, "one")).isEqualTo(0); @@ -562,13 +556,11 @@ void hscanNoValuesMatch() { @Test @EnabledOnCommand("HEXPIRE") void hexpire() { - // the below settings are required until the solution is able to support listpack entries - // see TODOs in https://github.com/redis/redis/pull/13172 for more details - assertThat(redis.configSet("hash-max-listpack-entries", "0")).isEqualTo("OK"); - assertThat(redis.configSet("set-max-listpack-value", "0")).isEqualTo("OK"); - assertThat(redis.hset(MY_KEY, MY_FIELD, MY_VALUE)).isTrue(); - assertThat(redis.hexpire(MY_KEY, 1, MY_FIELD)).isTrue(); + assertThat(redis.hexpire(MY_KEY, 0, MY_FIELD)).containsExactly(2L); + assertThat(redis.hset(MY_KEY, MY_FIELD, MY_VALUE)).isTrue(); + assertThat(redis.hexpire(MY_KEY, 1, MY_FIELD, MY_SECOND_FIELD)).containsExactly(1L, -2L); + assertThat(redis.hexpire("invalidKey", 1, MY_FIELD)).isEmpty(); await().until(() -> redis.hget(MY_KEY, MY_FIELD) == null); } @@ -576,16 +568,11 @@ void hexpire() { @Test @EnabledOnCommand("HEXPIRE") void hexpireExpireArgs() { - // the below settings are required until the solution is able to support listpack entries - // see TODOs in https://github.com/redis/redis/pull/13172 for more details - assertThat(redis.configSet("hash-max-listpack-entries", "0")).isEqualTo("OK"); - assertThat(redis.configSet("set-max-listpack-value", "0")).isEqualTo("OK"); - assertThat(redis.hset(MY_KEY, MY_FIELD, MY_VALUE)).isTrue(); - assertThat(redis.hexpire(MY_KEY, Duration.ofSeconds(1), ExpireArgs.Builder.nx(), MY_FIELD)).isTrue(); - assertThat(redis.hexpire(MY_KEY, Duration.ofSeconds(1), ExpireArgs.Builder.xx(), MY_FIELD)).isTrue(); - assertThat(redis.hexpire(MY_KEY, Duration.ofSeconds(10), ExpireArgs.Builder.gt(), MY_FIELD)).isTrue(); - assertThat(redis.hexpire(MY_KEY, Duration.ofSeconds(1), ExpireArgs.Builder.lt(), MY_FIELD)).isTrue(); + assertThat(redis.hexpire(MY_KEY, Duration.ofSeconds(1), ExpireArgs.Builder.nx(), MY_FIELD)).containsExactly(1L); + assertThat(redis.hexpire(MY_KEY, Duration.ofSeconds(1), ExpireArgs.Builder.xx(), MY_FIELD)).containsExactly(1L); + assertThat(redis.hexpire(MY_KEY, Duration.ofSeconds(10), ExpireArgs.Builder.gt(), MY_FIELD)).containsExactly(1L); + assertThat(redis.hexpire(MY_KEY, Duration.ofSeconds(1), ExpireArgs.Builder.lt(), MY_FIELD)).containsExactly(1L); await().until(() -> redis.hget(MY_KEY, MY_FIELD) == null); } @@ -593,13 +580,11 @@ void hexpireExpireArgs() { @Test @EnabledOnCommand("HEXPIREAT") void hexpireat() { - // the below settings are required until the solution is able to support listpack entries - // see TODOs in https://github.com/redis/redis/pull/13172 for more details - assertThat(redis.configSet("hash-max-listpack-entries", "0")).isEqualTo("OK"); - assertThat(redis.configSet("set-max-listpack-value", "0")).isEqualTo("OK"); - assertThat(redis.hset(MY_KEY, MY_FIELD, MY_VALUE)).isTrue(); - assertThat(redis.hexpireat(MY_KEY, Instant.now().plusSeconds(1), MY_FIELD)).isTrue(); + assertThat(redis.hexpireat(MY_KEY, Instant.now().minusSeconds(1), MY_FIELD)).containsExactly(2L); + assertThat(redis.hset(MY_KEY, MY_FIELD, MY_VALUE)).isTrue(); + assertThat(redis.hexpireat(MY_KEY, Instant.now().plusSeconds(1), MY_FIELD)).containsExactly(1L); + assertThat(redis.hexpireat("invalidKey", Instant.now().plusSeconds(1), MY_FIELD)).isEmpty(); await().until(() -> redis.hget(MY_KEY, MY_FIELD) == null); } @@ -607,31 +592,40 @@ void hexpireat() { @Test @EnabledOnCommand("HEXPIRETIME") void hexpiretime() { - Date expiration = new Date(System.currentTimeMillis() + 10000); - // the below settings are required until the solution is able to support listpack entries - // see TODOs in https://github.com/redis/redis/pull/13172 for more details - assertThat(redis.configSet("hash-max-listpack-entries", "0")).isEqualTo("OK"); - assertThat(redis.configSet("set-max-listpack-value", "0")).isEqualTo("OK"); + Map fields = new LinkedHashMap<>(); + fields.put(MY_FIELD, MY_VALUE); + fields.put(MY_SECOND_FIELD, MY_VALUE); - assertThat(redis.hset(MY_KEY, MY_FIELD, MY_VALUE)).isTrue(); - assertThat(redis.hexpireat(MY_KEY, expiration, MY_FIELD)).isTrue(); + Date expiration = new Date(System.currentTimeMillis() + 1000 * 5); + Date secondExpiration = new Date(System.currentTimeMillis() + 1000 * 10); + assertThat(redis.hset(MY_KEY, fields)).isEqualTo(2); + assertThat(redis.hexpireat(MY_KEY, expiration, MY_FIELD)).containsExactly(1L); + assertThat(redis.hexpireat(MY_KEY, secondExpiration, MY_SECOND_FIELD)).containsExactly(1L); - assertThat(redis.hexpiretime(MY_KEY, MY_FIELD)).isEqualTo(expiration.getTime() / 1000); + assertThat(redis.hexpiretime(MY_KEY, MY_FIELD, MY_SECOND_FIELD)).containsExactly(expiration.getTime() / 1000, + secondExpiration.getTime() / 1000); } @Test @EnabledOnCommand("HPERSIST") - void persist() { - // the below settings are required until the solution is able to support listpack entries - // see TODOs in https://github.com/redis/redis/pull/13172 for more details - assertThat(redis.configSet("hash-max-listpack-entries", "0")).isEqualTo("OK"); - assertThat(redis.configSet("set-max-listpack-value", "0")).isEqualTo("OK"); + void hpersist() { + assertThat(redis.hpersist(MY_KEY, MY_FIELD)).isEmpty(); + + assertThat(redis.hset(MY_KEY, MY_FIELD, MY_VALUE)).isTrue(); + assertThat(redis.hpersist(MY_KEY, MY_FIELD)).containsExactly(-1L); + + assertThat(redis.hexpire(MY_KEY, 1, MY_FIELD)).containsExactly(1L); - assertThat(redis.hpersist(MY_KEY, MY_FIELD)).isFalse(); + assertThat(redis.hpersist(MY_KEY, MY_FIELD)).containsExactly(1L); + } + + @Test + @EnabledOnCommand("HTTL") + void httl() { assertThat(redis.hset(MY_KEY, MY_FIELD, MY_VALUE)).isTrue(); - assertThat(redis.hpersist(MY_KEY, MY_FIELD)).isFalse(); - assertThat(redis.hexpire(MY_KEY, 1, MY_FIELD)).isTrue(); - assertThat(redis.hpersist(MY_KEY, MY_FIELD)).isTrue(); + assertThat(redis.hset(MY_KEY, MY_SECOND_FIELD, MY_VALUE)).isTrue(); + assertThat(redis.hexpire(MY_KEY, 60, MY_FIELD)).containsExactly(1L); + assertThat(redis.httl(MY_KEY, MY_FIELD, MY_SECOND_FIELD)).containsExactly(60L, -1L); } void setup100KeyValues(Map expect) { diff --git a/src/test/java/io/lettuce/core/output/IntegerListOutputUnitTests.java b/src/test/java/io/lettuce/core/output/IntegerListOutputUnitTests.java new file mode 100644 index 0000000000..4ed64548c4 --- /dev/null +++ b/src/test/java/io/lettuce/core/output/IntegerListOutputUnitTests.java @@ -0,0 +1,103 @@ +package io.lettuce.core.output; + +import io.lettuce.core.codec.StringCodec; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +import java.nio.ByteBuffer; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +/** + * @author Tihomir Mateev + */ +class IntegerListOutputUnitTests { + + static Collection parameters() { + + IntegerListOutput integerListOutput = new IntegerListOutput<>(StringCodec.UTF8); + Fixture integerList = new Fixture(integerListOutput, integerListOutput, + ByteBuffer.allocate(Long.SIZE / Byte.SIZE).putLong(1L).array(), 1L); + + IntegerListOutput nullListOutput = new IntegerListOutput<>(StringCodec.UTF8); + Fixture nullList = new Fixture(nullListOutput, nullListOutput, null, null); + + ValueListOutput valueListOutput = new ValueListOutput<>(StringCodec.UTF8); + Fixture valueList = new Fixture(valueListOutput, valueListOutput, "hello world".getBytes(), "hello world"); + + StringListOutput stringListOutput = new StringListOutput<>(StringCodec.UTF8); + Fixture stringList = new Fixture(stringListOutput, stringListOutput, "hello world".getBytes(), "hello world"); + + return Arrays.asList(integerList, nullList, valueList, stringList); + } + + @ParameterizedTest + @MethodSource("parameters") + void settingEmptySubscriberShouldFail(Fixture fixture) { + assertThatThrownBy(() -> fixture.streamingOutput.setSubscriber(null)).isInstanceOf(IllegalArgumentException.class); + } + + @ParameterizedTest + @MethodSource("parameters") + void defaultSubscriberIsSet(Fixture fixture) { + fixture.commandOutput.multi(1); + assertThat(fixture.streamingOutput.getSubscriber()).isNotNull().isInstanceOf(ListSubscriber.class); + } + + @ParameterizedTest + @MethodSource("parameters") + void setIntegerShouldFail(Fixture fixture) { + assertThatThrownBy(() -> fixture.commandOutput.set(123L)).isInstanceOf(UnsupportedOperationException.class); + } + + @ParameterizedTest + @MethodSource("parameters") + void setValueShouldConvert(Fixture fixture) { + + fixture.commandOutput.multi(1); + + if (fixture.valueBytes == null) { + fixture.commandOutput.set(null); + } else if (fixture.value instanceof Long) { + fixture.commandOutput.set((Long) fixture.value); + } else { + fixture.commandOutput.set(ByteBuffer.wrap(fixture.valueBytes)); + } + + if (fixture.valueBytes != null) { + assertThat(fixture.commandOutput.get()).contains(fixture.value); + } else { + assertThat(fixture.commandOutput.get()).isEmpty(); + } + } + + static class Fixture { + + final CommandOutput> commandOutput; + + final StreamingOutput streamingOutput; + + final byte[] valueBytes; + + final Object value; + + Fixture(CommandOutput commandOutput, StreamingOutput streamingOutput, byte[] valueBytes, Object value) { + + this.commandOutput = (CommandOutput) commandOutput; + this.streamingOutput = streamingOutput; + this.valueBytes = valueBytes; + this.value = value; + } + + @Override + public String toString() { + return commandOutput.getClass().getSimpleName() + "/" + value; + } + + } + +}