diff --git a/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java b/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java index f2c6c625ce..03d0e69f28 100644 --- a/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java +++ b/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java @@ -794,6 +794,27 @@ public RedisFuture expire(K key, Duration seconds, ExpireArgs expireArg return expire(key, seconds.toMillis() / 1000, expireArgs); } + @Override + public RedisFuture hexpire(K key, long seconds, List fields) { + return hexpire(key, seconds, null, fields); + } + + @Override + public RedisFuture hexpire(K key, long seconds, ExpireArgs expireArgs, List fields) { + return dispatch(commandBuilder.hexpire(key, seconds, expireArgs, fields)); + } + + @Override + public RedisFuture hexpire(K key, Duration seconds, List fields) { + return hexpire(key, seconds, null, fields); + } + + @Override + public RedisFuture hexpire(K key, Duration seconds, ExpireArgs expireArgs, List fields) { + LettuceAssert.notNull(seconds, "Timeout must not be null"); + return hexpire(key, seconds.toMillis() / 1000, expireArgs, fields); + } + @Override public RedisFuture expireat(K key, long timestamp) { return expireat(key, timestamp, null); diff --git a/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java b/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java index 47b473495e..567401bc97 100644 --- a/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java +++ b/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java @@ -854,6 +854,27 @@ public Mono expire(K key, Duration seconds, ExpireArgs expireArgs) { return expire(key, seconds.toMillis() / 1000, expireArgs); } + @Override + public Mono hexpire(K key, long seconds, List fields) { + return hexpire(key, seconds, null, fields); + } + + @Override + public Mono hexpire(K key, long seconds, ExpireArgs expireArgs, List fields) { + return createMono(() -> commandBuilder.hexpire(key, seconds, expireArgs, fields)); + } + + @Override + public Mono hexpire(K key, Duration seconds, List fields) { + return hexpire(key, seconds, null, fields); + } + + @Override + public Mono hexpire(K key, Duration seconds, ExpireArgs expireArgs, List fields) { + LettuceAssert.notNull(seconds, "Timeout must not be null"); + return hexpire(key, seconds.toMillis() / 1000, expireArgs, fields); + } + @Override public Mono expireat(K key, long timestamp) { return expireat(key, timestamp, null); diff --git a/src/main/java/io/lettuce/core/RedisCommandBuilder.java b/src/main/java/io/lettuce/core/RedisCommandBuilder.java index 3d3d2be0be..9b82a026e8 100644 --- a/src/main/java/io/lettuce/core/RedisCommandBuilder.java +++ b/src/main/java/io/lettuce/core/RedisCommandBuilder.java @@ -978,6 +978,23 @@ Command expire(K key, long seconds, ExpireArgs expireArgs) { return createCommand(EXPIRE, new BooleanOutput<>(codec), args); } + Command hexpire(K key, long seconds, ExpireArgs expireArgs, List fields) { + notNullKey(key); + notEmpty(fields == null ? new Object[]{} : fields.toArray()); + + CommandArgs args = new CommandArgs<>(codec).addKey(key).add(seconds); + + if (expireArgs != null) { + expireArgs.build(args); + } + + args.add(fields.size()); + + fields.forEach(args::addValue); + + return createCommand(HEXPIRE, new BooleanOutput<>(codec), args); + } + Command expireat(K key, long timestamp, ExpireArgs expireArgs) { notNullKey(key); diff --git a/src/main/java/io/lettuce/core/api/async/RedisKeyAsyncCommands.java b/src/main/java/io/lettuce/core/api/async/RedisKeyAsyncCommands.java index cceffb8a71..5a6078d5b6 100644 --- a/src/main/java/io/lettuce/core/api/async/RedisKeyAsyncCommands.java +++ b/src/main/java/io/lettuce/core/api/async/RedisKeyAsyncCommands.java @@ -137,6 +137,56 @@ public interface RedisKeyAsyncCommands { */ RedisFuture expire(K key, Duration seconds, ExpireArgs expireArgs); + /** + * Set the time to live (in seconds) for a {@link List} of fields, belonging to a certain key. + * + * @param key the key of the fields. + * @param seconds the seconds type: long. + * @param fields a {@link List} of 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. + * @since 7.0 + */ + RedisFuture hexpire(K key, long seconds, List fields); + + /** + * Set the time to live (in seconds) for a {@link List} of fields, belonging to a certain key. + * + * @param key the key of the fields. + * @param seconds the seconds type: long. + * @param expireArgs the expire arguments. + * @param fields a {@link List} of 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. + * @since 7.0 + */ + RedisFuture hexpire(K key, long seconds, ExpireArgs expireArgs, List fields); + + /** + * Set the time to live for a {@link List} of fields, belonging to a certain key. + * + * @param key the key. + * @param seconds the TTL {@link Duration} + * @param fields a {@link List} of 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. + * @since 7.0 + */ + RedisFuture hexpire(K key, Duration seconds, List fields); + + /** + * Set the time to live for a {@link List} of fields, belonging to a certain key. + * + * @param key the key. + * @param seconds the TTL {@link Duration} + * @param expireArgs the {@link ExpireArgs}. + * @param fields a {@link List} of 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. + * @since 7.0 + */ + RedisFuture hexpire(K key, Duration seconds, ExpireArgs expireArgs, List fields); + /** * Set the expiration for a key as a UNIX timestamp. * diff --git a/src/main/java/io/lettuce/core/api/reactive/RedisKeyReactiveCommands.java b/src/main/java/io/lettuce/core/api/reactive/RedisKeyReactiveCommands.java index 1fbfdda1a8..b3f1ef89f8 100644 --- a/src/main/java/io/lettuce/core/api/reactive/RedisKeyReactiveCommands.java +++ b/src/main/java/io/lettuce/core/api/reactive/RedisKeyReactiveCommands.java @@ -22,6 +22,7 @@ import java.time.Duration; import java.time.Instant; import java.util.Date; +import java.util.List; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -147,6 +148,56 @@ public interface RedisKeyReactiveCommands { */ Mono expire(K key, Duration seconds, ExpireArgs expireArgs); + /** + * Set the time to live (in seconds) for a {@link List} of fields, belonging to a certain key. + * + * @param key the key of the fields. + * @param seconds the seconds type: long. + * @param fields a {@link List} of 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. + * @since 7.0 + */ + Mono hexpire(K key, long seconds, List fields); + + /** + * Set the time to live (in seconds) for a {@link List} of fields, belonging to a certain key. + * + * @param key the key of the fields. + * @param seconds the seconds type: long. + * @param expireArgs the expire arguments. + * @param fields a {@link List} of 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. + * @since 7.0 + */ + Mono hexpire(K key, long seconds, ExpireArgs expireArgs, List fields); + + /** + * Set the time to live for a {@link List} of fields, belonging to a certain key. + * + * @param key the key. + * @param seconds the TTL {@link Duration} + * @param fields a {@link List} of 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. + * @since 7.0 + */ + Mono hexpire(K key, Duration seconds, List fields); + + /** + * Set the time to live for a {@link List} of fields, belonging to a certain key. + * + * @param key the key. + * @param seconds the TTL {@link Duration} + * @param expireArgs the {@link ExpireArgs}. + * @param fields a {@link List} of 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. + * @since 7.0 + */ + Mono hexpire(K key, Duration seconds, ExpireArgs expireArgs, List fields); + /** * Set the expiration for a key as a UNIX timestamp. * diff --git a/src/main/java/io/lettuce/core/api/sync/RedisKeyCommands.java b/src/main/java/io/lettuce/core/api/sync/RedisKeyCommands.java index 516e4ab072..07faab4c2e 100644 --- a/src/main/java/io/lettuce/core/api/sync/RedisKeyCommands.java +++ b/src/main/java/io/lettuce/core/api/sync/RedisKeyCommands.java @@ -146,6 +146,56 @@ public interface RedisKeyCommands { */ Boolean expire(K key, Duration seconds, ExpireArgs expireArgs); + /** + * Set the time to live (in seconds) for a {@link List} of fields, belonging to a certain key. + * + * @param key the key of the fields. + * @param seconds the seconds type: long. + * @param fields a {@link List} of 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. + * @since 7.0 + */ + Boolean hexpire(K key, long seconds, List fields); + + /** + * Set the time to live (in seconds) for a {@link List} of fields, belonging to a certain key. + * + * @param key the key of the fields. + * @param seconds the seconds type: long. + * @param expireArgs the expire arguments. + * @param fields a {@link List} of 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. + * @since 7.0 + */ + Boolean hexpire(K key, long seconds, ExpireArgs expireArgs, List fields); + + /** + * Set the time to live for a {@link List} of fields, belonging to a certain key. + * + * @param key the key. + * @param seconds the TTL {@link Duration} + * @param fields a {@link List} of 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. + * @since 7.0 + */ + Boolean hexpire(K key, Duration seconds, List fields); + + /** + * Set the time to live for a {@link List} of fields, belonging to a certain key. + * + * @param key the key. + * @param seconds the TTL {@link Duration} + * @param expireArgs the {@link ExpireArgs}. + * @param fields a {@link List} of 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. + * @since 7.0 + */ + Boolean hexpire(K key, Duration seconds, ExpireArgs expireArgs, List fields); + /** * Set the expiration for a key as a UNIX timestamp. * diff --git a/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionKeyAsyncCommands.java b/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionKeyAsyncCommands.java index 44bbd168a3..422111c0ea 100644 --- a/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionKeyAsyncCommands.java +++ b/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionKeyAsyncCommands.java @@ -146,6 +146,56 @@ public interface NodeSelectionKeyAsyncCommands { */ AsyncExecutions expire(K key, Duration seconds, ExpireArgs expireArgs); + /** + * Set the time to live (in seconds) for a {@link List} of fields, belonging to a certain key. + * + * @param key the key of the fields. + * @param seconds the seconds type: long. + * @param fields a {@link List} of 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. + * @since 7.0 + */ + AsyncExecutions hexpire(K key, long seconds, List fields); + + /** + * Set the time to live (in seconds) for a {@link List} of fields, belonging to a certain key. + * + * @param key the key of the fields. + * @param seconds the seconds type: long. + * @param expireArgs the expire arguments. + * @param fields a {@link List} of 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. + * @since 7.0 + */ + AsyncExecutions hexpire(K key, long seconds, ExpireArgs expireArgs, List fields); + + /** + * Set the time to live for a {@link List} of fields, belonging to a certain key. + * + * @param key the key. + * @param seconds the TTL {@link Duration} + * @param fields a {@link List} of 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. + * @since 7.0 + */ + AsyncExecutions hexpire(K key, Duration seconds, List fields); + + /** + * Set the time to live for a {@link List} of fields, belonging to a certain key. + * + * @param key the key. + * @param seconds the TTL {@link Duration} + * @param expireArgs the {@link ExpireArgs}. + * @param fields a {@link List} of 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. + * @since 7.0 + */ + AsyncExecutions hexpire(K key, Duration seconds, ExpireArgs expireArgs, List fields); + /** * Set the expiration for a key as a UNIX timestamp. * diff --git a/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionKeyCommands.java b/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionKeyCommands.java index d09dd4f39a..b523434d24 100644 --- a/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionKeyCommands.java +++ b/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionKeyCommands.java @@ -146,6 +146,56 @@ public interface NodeSelectionKeyCommands { */ Executions expire(K key, Duration seconds, ExpireArgs expireArgs); + /** + * Set the time to live (in seconds) for a {@link List} of fields, belonging to a certain key. + * + * @param key the key of the fields. + * @param seconds the seconds type: long. + * @param fields a {@link List} of 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. + * @since 7.0 + */ + Executions hexpire(K key, long seconds, List fields); + + /** + * Set the time to live (in seconds) for a {@link List} of fields, belonging to a certain key. + * + * @param key the key of the fields. + * @param seconds the seconds type: long. + * @param expireArgs the expire arguments. + * @param fields a {@link List} of 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. + * @since 7.0 + */ + Executions hexpire(K key, long seconds, ExpireArgs expireArgs, List fields); + + /** + * Set the time to live for a {@link List} of fields, belonging to a certain key. + * + * @param key the key. + * @param seconds the TTL {@link Duration} + * @param fields a {@link List} of 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. + * @since 7.0 + */ + Executions hexpire(K key, Duration seconds, List fields); + + /** + * Set the time to live for a {@link List} of fields, belonging to a certain key. + * + * @param key the key. + * @param seconds the TTL {@link Duration} + * @param expireArgs the {@link ExpireArgs}. + * @param fields a {@link List} of 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. + * @since 7.0 + */ + Executions hexpire(K key, Duration seconds, ExpireArgs expireArgs, List fields); + /** * Set the expiration for a key as a UNIX timestamp. * diff --git a/src/main/java/io/lettuce/core/protocol/CommandType.java b/src/main/java/io/lettuce/core/protocol/CommandType.java index 7a9d87524d..bd4c04c982 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, EXPIRE, EXPIREAT, EXPIRETIME, KEYS, MIGRATE, MOVE, OBJECT, PERSIST, PEXPIRE, PEXPIREAT, PEXPIRETIME, PTTL, RANDOMKEY, RENAME, RENAMENX, RESTORE, TOUCH, TTL, TYPE, SCAN, UNLINK, + COPY, DEL, DUMP, EXISTS, HEXPIRE, EXPIRE, EXPIREAT, EXPIRETIME, KEYS, MIGRATE, MOVE, OBJECT, PERSIST, PEXPIRE, PEXPIREAT, PEXPIRETIME, PTTL, RANDOMKEY, RENAME, RENAMENX, RESTORE, TOUCH, TTL, TYPE, SCAN, UNLINK, // String diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisKeyCoroutinesCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisKeyCoroutinesCommands.kt index 6d3f92bcad..f979c8bc4e 100644 --- a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisKeyCoroutinesCommands.kt +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisKeyCoroutinesCommands.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. @@ -136,6 +136,56 @@ interface RedisKeyCoroutinesCommands { */ suspend fun expire(key: K, seconds: Duration, expireArgs: ExpireArgs): Boolean? + /** + * Set the time to live (in seconds) for a [List] of fields, belonging to a certain key. + * + * @param key the key of the fields. + * @param seconds the seconds type: long. + * @param fields a [List] of 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. + * @since 7.0 + */ + suspend fun hexpire(key: K, seconds: Long, fields: List): Boolean? + + /** + * Set the time to live (in seconds) for a [List] of fields, belonging to a certain key. + * + * @param key the key of the fields. + * @param seconds the seconds type: long. + * @param expireArgs the expire arguments. + * @param fields a [List] of 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. + * @since 7.0 + */ + suspend fun hexpire(key: K, seconds: Long, expireArgs: ExpireArgs, fields: List): Boolean? + + /** + * Set the time to live for a [List] of fields, belonging to a certain key. + * + * @param key the key. + * @param seconds the TTL [Duration] + * @param fields a [List] of 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. + * @since 7.0 + */ + suspend fun hexpire(key: K, seconds: Duration, fields: List): Boolean? + + /** + * Set the time to live for a [List] of fields, belonging to a certain key. + * + * @param key the key. + * @param seconds the TTL [Duration] + * @param expireArgs the [ExpireArgs]. + * @param fields a [List] of 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. + * @since 7.0 + */ + suspend fun hexpire(key: K, seconds: Duration, expireArgs: ExpireArgs, fields: List): Boolean? + /** * Set the expiration for a key as a UNIX timestamp. * diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisKeyCoroutinesCommandsImpl.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisKeyCoroutinesCommandsImpl.kt index 5b62a92d3c..d088d03ad8 100644 --- a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisKeyCoroutinesCommandsImpl.kt +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisKeyCoroutinesCommandsImpl.kt @@ -74,6 +74,24 @@ internal class RedisKeyCoroutinesCommandsImpl(internal val ops ): Boolean? = ops.expire(key, seconds, expireArgs).awaitFirstOrNull() + override suspend fun hexpire(key: K, seconds: Long, fields: List): Boolean? = + ops.hexpire(key, seconds, fields).awaitFirstOrNull() + + override suspend fun hexpire(key: K, seconds: Long, expireArgs: ExpireArgs, fields: List): Boolean? = + ops.hexpire(key, seconds, expireArgs, fields).awaitFirstOrNull() + + + override suspend fun hexpire(key: K, seconds: Duration, fields: List): Boolean? = + ops.hexpire(key, seconds, fields).awaitFirstOrNull() + + override suspend fun hexpire( + key: K, + seconds: Duration, + expireArgs: ExpireArgs, + fields: List + ): Boolean? = + ops.hexpire(key, seconds, expireArgs, fields).awaitFirstOrNull() + override suspend fun expireat(key: K, timestamp: Date): Boolean? = ops.expireat(key, timestamp).awaitFirstOrNull() diff --git a/src/main/templates/io/lettuce/core/api/RedisKeyCommands.java b/src/main/templates/io/lettuce/core/api/RedisKeyCommands.java index bdd3568991..6f8ba3c27b 100644 --- a/src/main/templates/io/lettuce/core/api/RedisKeyCommands.java +++ b/src/main/templates/io/lettuce/core/api/RedisKeyCommands.java @@ -138,6 +138,56 @@ public interface RedisKeyCommands { */ Boolean expire(K key, Duration seconds, ExpireArgs expireArgs); + /** + * Set the time to live (in seconds) for a {@link List} of fields, belonging to a certain key. + * + * @param key the key of the fields. + * @param seconds the seconds type: long. + * @param fields a {@link List} of 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. + * @since 7.0 + */ + Boolean hexpire(K key, long seconds, List fields); + + /** + * Set the time to live (in seconds) for a {@link List} of fields, belonging to a certain key. + * + * @param key the key of the fields. + * @param seconds the seconds type: long. + * @param expireArgs the expire arguments. + * @param fields a {@link List} of 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. + * @since 7.0 + */ + Boolean hexpire(K key, long seconds, ExpireArgs expireArgs, List fields); + + /** + * Set the time to live for a {@link List} of fields, belonging to a certain key. + * + * @param key the key. + * @param seconds the TTL {@link Duration} + * @param fields a {@link List} of 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. + * @since 7.0 + */ + Boolean hexpire(K key, Duration seconds, List fields); + + /** + * Set the time to live for a {@link List} of fields, belonging to a certain key. + * + * @param key the key. + * @param seconds the TTL {@link Duration} + * @param expireArgs the {@link ExpireArgs}. + * @param fields a {@link List} of 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. + * @since 7.0 + */ + Boolean hexpire(K key, Duration seconds, ExpireArgs expireArgs, List fields); + /** * Set the expiration for a key as a UNIX timestamp. * diff --git a/src/test/java/io/lettuce/core/commands/KeyCommandIntegrationTests.java b/src/test/java/io/lettuce/core/commands/KeyCommandIntegrationTests.java index 45d7e3840d..fb12d44db5 100644 --- a/src/test/java/io/lettuce/core/commands/KeyCommandIntegrationTests.java +++ b/src/test/java/io/lettuce/core/commands/KeyCommandIntegrationTests.java @@ -20,15 +20,11 @@ package io.lettuce.core.commands; import static org.assertj.core.api.Assertions.*; +import static org.awaitility.Awaitility.await; import java.time.Duration; import java.time.Instant; -import java.util.Date; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import javax.inject.Inject; @@ -62,6 +58,12 @@ @TestInstance(TestInstance.Lifecycle.PER_CLASS) public class KeyCommandIntegrationTests extends TestSupport { + public static final String MY_KEY = "hKey"; + + public static final String MY_FIELD = "hField"; + + public static final String MY_VALUE = "hValue"; + private final RedisCommands redis; @Inject @@ -192,6 +194,49 @@ void expiretime() { assertThat(redis.expiretime(key)).isEqualTo(expiration.getTime() / 1000); } + @Test + @EnabledOnCommand("HEXPIRE") + void hexpire() { + assertThat(redis.hset(MY_KEY, MY_FIELD, MY_VALUE)).isTrue(); + // 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.hexpire("myKey", 1, Collections.singletonList("myField"))).isTrue(); + + await().until(() -> redis.hget("myKey", "myField") == null); + } + + @Test + @EnabledOnCommand("HEXPIRE") + void hexpireExpireArgs() { + assertThat(redis.hset(MY_KEY, MY_FIELD, MY_VALUE)).isTrue(); + // 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.hexpire("myKey", + Duration.ofSeconds(1), + ExpireArgs.Builder.nx(), + Collections.singletonList("myField"))).isTrue(); + assertThat(redis.hexpire("myKey", + Duration.ofSeconds(1), + ExpireArgs.Builder.xx(), + Collections.singletonList("myField"))).isTrue(); + assertThat(redis.hexpire("myKey", + Duration.ofSeconds(10), + ExpireArgs.Builder.gt(), + Collections.singletonList("myField"))).isTrue(); + assertThat(redis.hexpire("myKey", + Duration.ofSeconds(1), + ExpireArgs.Builder.lt(), + Collections.singletonList("myField"))).isTrue(); + + await().until(() -> redis.hget("myKey", "myField") == null); + } + @Test void keys() { assertThat(redis.keys("*")).isEqualTo(list());