-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Adds support for Redis setGet command #3017
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,7 @@ | |
* | ||
* @author Christoph Strobl | ||
* @author Mark Paluch | ||
* @author Marcin Grzejszczak | ||
* @since 2.0 | ||
*/ | ||
public interface ReactiveStringCommands { | ||
|
@@ -62,15 +63,23 @@ class SetCommand extends KeyCommand { | |
private @Nullable ByteBuffer value; | ||
private Expiration expiration; | ||
private SetOption option; | ||
private boolean get; | ||
|
||
private SetCommand(ByteBuffer key, @Nullable ByteBuffer value, @Nullable Expiration expiration, | ||
@Nullable SetOption option) { | ||
|
||
this(key, value, expiration, option, false); | ||
} | ||
|
||
private SetCommand(ByteBuffer key, @Nullable ByteBuffer value, @Nullable Expiration expiration, | ||
@Nullable SetOption option, boolean get) { | ||
|
||
super(key); | ||
|
||
this.value = value; | ||
this.expiration = expiration; | ||
this.option = option; | ||
this.get = get; | ||
} | ||
|
||
/** | ||
|
@@ -125,6 +134,16 @@ public SetCommand withSetOption(SetOption option) { | |
return new SetCommand(getKey(), value, expiration, option); | ||
} | ||
|
||
/** | ||
* Applies GET option. Return the old string stored at key, or {@code null} if key did not exist. | ||
* An error is returned and SET aborted if the value stored at key is not a string. | ||
* | ||
* @return a new {@link SetCommand} with {@link SetOption} applied. | ||
*/ | ||
public SetCommand withGet() { | ||
return new SetCommand(getKey(), value, expiration, option, true); | ||
} | ||
|
||
/** | ||
* @return | ||
*/ | ||
|
@@ -146,6 +165,13 @@ public Optional<Expiration> getExpiration() { | |
public Optional<SetOption> getOption() { | ||
return Optional.ofNullable(option); | ||
} | ||
|
||
/** | ||
* @return | ||
*/ | ||
public boolean isGet() { | ||
return get; | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -184,6 +210,22 @@ default Mono<Boolean> set(ByteBuffer key, ByteBuffer value, Expiration expiratio | |
.map(BooleanResponse::getOutput); | ||
} | ||
|
||
/** | ||
* Set {@literal value} for {@literal key} with {@literal expiration} and {@literal options}. Return the old | ||
* string stored at key, or nil if key did not exist. An error is returned and SET aborted if the value | ||
* stored at key is not a string. | ||
* | ||
* @param key must not be {@literal null}. | ||
* @param value must not be {@literal null}. | ||
* @param expiration must not be {@literal null}. Use {@link Expiration#persistent()} for no expiration time or | ||
* {@link Expiration#keepTtl()} to keep the existing. | ||
* @param option must not be {@literal null}. | ||
* @return | ||
* @see <a href="https://redis.io/commands/set">Redis Documentation: SET</a> | ||
* @since 3.4 | ||
*/ | ||
Flux<ByteBufferResponse<SetCommand>> setGet(ByteBuffer key, ByteBuffer value, Expiration expiration, SetOption option); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here we need both signatures, The first one delegates to the latter. |
||
|
||
/** | ||
* Set each and every item separately by invoking {@link SetCommand}. | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ | |
* @author Christoph Strobl | ||
* @author Mark Paluch | ||
* @author Jiahe Cai | ||
* @author Marcin Grzejszczak | ||
*/ | ||
public interface ValueOperations<K, V> { | ||
|
||
|
@@ -44,6 +45,33 @@ public interface ValueOperations<K, V> { | |
*/ | ||
void set(K key, V value); | ||
|
||
/** | ||
* Set the {@code value} and expiration {@code timeout} for {@code key}. Return the old | ||
* string stored at key, or nil if key did not exist. An error is returned and SET aborted if the value | ||
* stored at key is not a string. | ||
* | ||
* @param key must not be {@literal null}. | ||
* @param value must not be {@literal null}. | ||
* @param timeout the key expiration timeout. | ||
* @param unit must not be {@literal null}. | ||
* @see <a href="https://redis.io/commands/set">Redis Documentation: SET</a> | ||
* @since 3.4 | ||
*/ | ||
V setGet(K key, V value, long timeout, TimeUnit unit); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might want to update |
||
|
||
/** | ||
* Set the {@code value} and expiration {@code timeout} for {@code key}. Return the old | ||
* string stored at key, or nil if key did not exist. An error is returned and SET aborted if the value | ||
* stored at key is not a string. | ||
* | ||
* @param key must not be {@literal null}. | ||
* @param value must not be {@literal null}. | ||
* @param duration expiration duration | ||
* @see <a href="https://redis.io/commands/set">Redis Documentation: SET</a> | ||
* @since 3.4 | ||
*/ | ||
V setGet(K key, V value, Duration duration); | ||
|
||
/** | ||
* Set the {@code value} and expiration {@code timeout} for {@code key}. | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That isn't going to work as the
set
API returns a boolean response.