From 194b6f6f7d04bc028fd44655d4a74c408bcce4ee Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Fri, 26 Mar 2021 10:24:58 +0100 Subject: [PATCH] Polishing #1683 Let RestoreArgs implement CompositeArgument. Tweak Javadoc. Original pull request: #1685. --- .../io/lettuce/core/RedisCommandBuilder.java | 16 +------- .../java/io/lettuce/core/RestoreArgs.java | 39 +++++++++++++++---- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/main/java/io/lettuce/core/RedisCommandBuilder.java b/src/main/java/io/lettuce/core/RedisCommandBuilder.java index 7b7bf12ab5..5995fb1421 100644 --- a/src/main/java/io/lettuce/core/RedisCommandBuilder.java +++ b/src/main/java/io/lettuce/core/RedisCommandBuilder.java @@ -1885,21 +1885,7 @@ Command restore(K key, byte[] value, RestoreArgs restoreArgs) { CommandArgs 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); } diff --git a/src/main/java/io/lettuce/core/RestoreArgs.java b/src/main/java/io/lettuce/core/RestoreArgs.java index f6a4cc3322..bdd095aa9e 100644 --- a/src/main/java/io/lettuce/core/RestoreArgs.java +++ b/src/main/java/io/lettuce/core/RestoreArgs.java @@ -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 RESTORE command. Static import the methods @@ -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}. @@ -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 */ @@ -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 */ @@ -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 */ @@ -172,4 +175,24 @@ public RestoreArgs frequency(long frequency) { this.frequency = frequency; return this; } + + @Override + public void build(CommandArgs 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); + } + } }