diff --git a/src/main/java/io/lettuce/core/RedisCommandBuilder.java b/src/main/java/io/lettuce/core/RedisCommandBuilder.java index 82d6a0961c..076d296108 100644 --- a/src/main/java/io/lettuce/core/RedisCommandBuilder.java +++ b/src/main/java/io/lettuce/core/RedisCommandBuilder.java @@ -1886,6 +1886,14 @@ Command restore(K key, byte[] value, RestoreArgs restoreArgs) { args.add(ABSTTL); } + if (restoreArgs.idleTime != null) { + args.add(IDLETIME).add(restoreArgs.idleTime); + } + + if (restoreArgs.frequency != null) { + args.add(FREQ).add(restoreArgs.frequency); + } + return createCommand(RESTORE, new StatusOutput<>(codec), args); } diff --git a/src/main/java/io/lettuce/core/RestoreArgs.java b/src/main/java/io/lettuce/core/RestoreArgs.java index fd845bd734..f6a4cc3322 100644 --- a/src/main/java/io/lettuce/core/RestoreArgs.java +++ b/src/main/java/io/lettuce/core/RestoreArgs.java @@ -37,6 +37,10 @@ public class RestoreArgs { boolean absttl; + Long frequency; + + Long idleTime; + /** * Builder entry points for {@link XAddArgs}. */ @@ -141,4 +145,31 @@ public RestoreArgs absttl(boolean absttl) { this.absttl = absttl; return this; } + + /** + * Set the number of seconds since the object stored at the specified key is idle (not requested by read or write + * operations). + * + * @param idleTime + * @return {@code this}. + * @since 6.1 + */ + public RestoreArgs idleTime(long idleTime) { + + this.idleTime = idleTime; + return this; + } + + /** + * Set the logarithmic access frequency counter of the object stored at the specified key. + * + * @param frequency + * @return {@code this}. + * @since 6.1 + */ + public RestoreArgs frequency(long frequency) { + + this.frequency = frequency; + return this; + } } diff --git a/src/main/java/io/lettuce/core/protocol/CommandKeyword.java b/src/main/java/io/lettuce/core/protocol/CommandKeyword.java index 17c0fb6b27..12e2f3e349 100644 --- a/src/main/java/io/lettuce/core/protocol/CommandKeyword.java +++ b/src/main/java/io/lettuce/core/protocol/CommandKeyword.java @@ -31,7 +31,7 @@ public enum CommandKeyword implements ProtocolKeyword { BY, BYLEX, BYSCORE, CACHING, CAT, CH, CHANNELS, COPY, COUNT, COUNTKEYSINSLOT, CONSUMERS, CREATE, DB, DELSLOTS, DELUSER, DESC, SOFT, HARD, ENCODING, - FAILOVER, FORGET, FLUSH, FORCE, FLUSHSLOTS, GENPASS, GETNAME, GETUSER, GETKEYSINSLOT, GETREDIR, GROUP, GROUPS, HTSTATS, ID, IDLE, + FAILOVER, FORGET, FLUSH, FORCE, FREQ, FLUSHSLOTS, GENPASS, GETNAME, GETUSER, GETKEYSINSLOT, GETREDIR, GROUP, GROUPS, HTSTATS, ID, IDLE, IDLETIME, JUSTID, KILL, KEYSLOT, LEFT, LEN, LIMIT, LIST, LOAD, LOG, MATCH, diff --git a/src/test/java/io/lettuce/core/commands/KeyCommandIntegrationTests.java b/src/test/java/io/lettuce/core/commands/KeyCommandIntegrationTests.java index 12cc5bf2e7..955e702fbf 100644 --- a/src/test/java/io/lettuce/core/commands/KeyCommandIntegrationTests.java +++ b/src/test/java/io/lettuce/core/commands/KeyCommandIntegrationTests.java @@ -337,6 +337,21 @@ void restoreReplace() { assertThat(redis.pttl(key)).isGreaterThan(0).isLessThanOrEqualTo(3000); } + @Test + void restoreIdleTime() { + + redis.set(key, value); + byte[] bytes = redis.dump(key); + redis.set(key, "foo"); + + assertThat(redis.restore(key, bytes, RestoreArgs.Builder.ttl(Duration.ofSeconds(1)).idleTime(111).replace())).isEqualTo("OK"); + assertThat(redis.objectIdletime(key)).isEqualTo(111); + assertThat(redis.get(key)).isEqualTo(value); + assertThat(redis.pttl(key)).isGreaterThan(0).isLessThanOrEqualTo(1000); + + assertThat(redis.restore(key, bytes, RestoreArgs.Builder.ttl(Duration.ofSeconds(1)).frequency(111).replace())).isEqualTo("OK"); + } + @Test @EnabledOnCommand("TOUCH") void touch() {