Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support IDLETIME and FREQ args to RESTORE command #1685

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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