Skip to content

Commit

Permalink
Add support for RESTORE ABSTTL #1634
Browse files Browse the repository at this point in the history
Original pull request: #1634.
  • Loading branch information
dengliming authored Mar 4, 2021
1 parent 53f152d commit 60be40c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/main/java/io/lettuce/core/RedisCommandBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -1800,6 +1800,10 @@ Command<K, V, String> restore(K key, byte[] value, RestoreArgs restoreArgs) {
args.add(REPLACE);
}

if (restoreArgs.absttl) {
args.add(ABSTTL);
}

return createCommand(RESTORE, new StatusOutput<>(codec), args);
}

Expand Down
25 changes: 25 additions & 0 deletions src/main/java/io/lettuce/core/RestoreArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* {@link RestoreArgs} is a mutable object and instances should be used only once to avoid shared mutable state.
*
* @author Mark Paluch
* @author dengliming
* @since 5.1
*/
public class RestoreArgs {
Expand All @@ -34,6 +35,8 @@ public class RestoreArgs {

boolean replace;

boolean absttl;

/**
* Builder entry points for {@link XAddArgs}.
*/
Expand Down Expand Up @@ -116,4 +119,26 @@ public RestoreArgs replace(boolean replace) {
return this;
}

/**
* TTL will represent an absolute Unix timestamp (in milliseconds) in which the key will expire.
*
* @return {@code this}.
* @since 6.1
*/
public RestoreArgs absttl() {
return absttl(true);
}

/**
* TTL will represent an absolute Unix timestamp (in milliseconds) in which the key will expire.
*
* @param absttl
* @return {@code this}.
* @since 6.1
*/
public RestoreArgs absttl(boolean absttl) {

this.absttl = absttl;
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 @@ -27,7 +27,7 @@
*/
public enum CommandKeyword implements ProtocolKeyword {

ADDR, ADDSLOTS, AFTER, AGGREGATE, ALLCHANNELS, ALLCOMMANDS, ALLKEYS, ALPHA, AND, ASK, ASC, ASYNC, BEFORE, BLOCK, BUMPEPOCH,
ABSTTL, ADDR, ADDSLOTS, AFTER, AGGREGATE, ALLCHANNELS, ALLCOMMANDS, ALLKEYS, ALPHA, AND, ASK, ASC, ASYNC, BEFORE, BLOCK, BUMPEPOCH,

BY, BYLEX, BYSCORE, CACHING, CAT, CHANNELS, COPY, COUNT, COUNTKEYSINSLOT, CONSUMERS, CREATE, DB, DELSLOTS, DELUSER, DESC, SOFT, HARD, ENCODING,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
/**
* @author Will Glozer
* @author Mark Paluch
* @author dengliming
*/
@ExtendWith(LettuceExtension.class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
Expand Down Expand Up @@ -328,6 +329,12 @@ void restoreReplace() {
assertThat(redis.restore(key, bytes, RestoreArgs.Builder.ttl(Duration.ofSeconds(1)).replace())).isEqualTo("OK");
assertThat(redis.get(key)).isEqualTo(value);
assertThat(redis.pttl(key)).isGreaterThan(0).isLessThanOrEqualTo(1000);

redis.del(key);
assertThat(redis.restore(key, bytes, RestoreArgs.Builder.ttl(System.currentTimeMillis() + 3000).replace().absttl()))
.isEqualTo("OK");
assertThat(redis.get(key)).isEqualTo(value);
assertThat(redis.pttl(key)).isGreaterThan(0).isLessThanOrEqualTo(3000);
}

@Test
Expand Down Expand Up @@ -516,4 +523,5 @@ void setup100KeyValues(Set<String> expect) {
expect.add(key + i);
}
}

}

0 comments on commit 60be40c

Please sign in to comment.