Skip to content

Commit

Permalink
Polishing #1683
Browse files Browse the repository at this point in the history
Let RestoreArgs implement CompositeArgument. Tweak Javadoc.

Original pull request: #1685.
  • Loading branch information
mp911de committed Mar 26, 2021
1 parent 863c19b commit 194b6f6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
16 changes: 1 addition & 15 deletions src/main/java/io/lettuce/core/RedisCommandBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -1885,21 +1885,7 @@ Command<K, V, String> restore(K key, byte[] value, RestoreArgs restoreArgs) {

CommandArgs<K, V> args = new CommandArgs<>(codec).addKey(key).add(restoreArgs.ttl).add(value);

if (restoreArgs.replace) {
args.add(REPLACE);
}

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

if (restoreArgs.idleTime != null) {
args.add(IDLETIME).add(restoreArgs.idleTime);
}

if (restoreArgs.frequency != null) {
args.add(FREQ).add(restoreArgs.frequency);
}
restoreArgs.build(args);

return createCommand(RESTORE, new StatusOutput<>(codec), args);
}
Expand Down
39 changes: 31 additions & 8 deletions src/main/java/io/lettuce/core/RestoreArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
*/
package io.lettuce.core;

import static io.lettuce.core.protocol.CommandKeyword.*;

import java.time.Duration;

import io.lettuce.core.internal.LettuceAssert;
import io.lettuce.core.protocol.CommandArgs;

/**
* Argument list builder for the Redis <a href="http://redis.io/commands/restore">RESTORE</a> command. Static import the methods
Expand All @@ -29,17 +32,17 @@
* @author dengliming
* @since 5.1
*/
public class RestoreArgs {
public class RestoreArgs implements CompositeArgument {

long ttl;

boolean replace;
private boolean replace;

boolean absttl;
private boolean absttl;

Long frequency;
private Long frequency;

Long idleTime;
private Long idleTime;

/**
* Builder entry points for {@link XAddArgs}.
Expand Down Expand Up @@ -136,7 +139,7 @@ public RestoreArgs absttl() {
/**
* TTL will represent an absolute Unix timestamp (in milliseconds) in which the key will expire.
*
* @param absttl
* @param absttl {@code true} to apply absolute TTL instead of a relative remaining TTL.
* @return {@code this}.
* @since 6.1
*/
Expand All @@ -150,7 +153,7 @@ public RestoreArgs absttl(boolean absttl) {
* Set the number of seconds since the object stored at the specified key is idle (not requested by read or write
* operations).
*
* @param idleTime
* @param idleTime the idle time when using a LRU eviction policy.
* @return {@code this}.
* @since 6.1
*/
Expand All @@ -163,7 +166,7 @@ public RestoreArgs idleTime(long idleTime) {
/**
* Set the logarithmic access frequency counter of the object stored at the specified key.
*
* @param frequency
* @param frequency the access frequency when using a LFU eviction policy.
* @return {@code this}.
* @since 6.1
*/
Expand All @@ -172,4 +175,24 @@ public RestoreArgs frequency(long frequency) {
this.frequency = frequency;
return this;
}

@Override
public <K, V> void build(CommandArgs<K, V> args) {

if (replace) {
args.add(REPLACE);
}

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

if (idleTime != null) {
args.add(IDLETIME).add(idleTime);
}

if (frequency != null) {
args.add(FREQ).add(frequency);
}
}
}

0 comments on commit 194b6f6

Please sign in to comment.