Skip to content

Commit

Permalink
Add support IDLETIME and FREQ args to RESTORE command
Browse files Browse the repository at this point in the history
  • Loading branch information
dengliming committed Mar 22, 2021
1 parent 80b4018 commit b97b45c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/main/java/io/lettuce/core/RedisCommandBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -1886,6 +1886,14 @@ Command<K, V, String> 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);
}

Expand Down
31 changes: 31 additions & 0 deletions src/main/java/io/lettuce/core/RestoreArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public class RestoreArgs {

boolean absttl;

Long frequency;

Long idleTime;

/**
* Builder entry points for {@link XAddArgs}.
*/
Expand Down Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion src/main/java/io/lettuce/core/protocol/CommandKeyword.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit b97b45c

Please sign in to comment.