Repository navigation
Introduce INCREX command #3746
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
Merged
Merged
Introduce INCREX command #3746
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev
Previous commit
Separate params
- Loading branch information
commit c1eca2c893511771ba4dfdf20da152535ca85b86
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| package io.lettuce.core; | ||
|
|
||
| import io.lettuce.core.protocol.CommandArgs; | ||
| import io.lettuce.core.protocol.CommandKeyword; | ||
| import io.lettuce.core.protocol.CommandType; | ||
|
|
||
| /** | ||
| * Abstract base for {@code INCREX} arguments. Owns options common to both the integer-bounded variant ({@link IncrexArgs}) and | ||
| * the float-bounded variant ({@link IncrexFloatArgs}): {@code SATURATE}, the | ||
| * {@code EX}/{@code PX}/{@code EXAT}/{@code PXAT}/{@code PERSIST} expiration block, and {@code ENX}. | ||
| * <p> | ||
| * Bounds ({@code LBOUND}/{@code UBOUND}) live on the concrete subclasses so the bound type matches the increment type at | ||
| * compile time — integer-mode {@code increx} only accepts {@link IncrexArgs}, float-mode {@code increx} only accepts | ||
| * {@link IncrexFloatArgs}. | ||
| * | ||
| * @param <T> the concrete subtype, for fluent method chaining | ||
| * @since 7.6 | ||
| */ | ||
| abstract class BaseIncrexArgs<T extends BaseIncrexArgs<T>> implements CompositeArgument { | ||
|
|
||
| private boolean saturate = false; | ||
|
|
||
| private Long ex; | ||
|
|
||
| private Long px; | ||
|
|
||
| private Long exAt; | ||
|
|
||
| private Long pxAt; | ||
|
|
||
| private boolean persist = false; | ||
|
|
||
| private boolean enx = false; | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| private T self() { | ||
| return (T) this; | ||
| } | ||
|
|
||
| /** | ||
| * Saturate the result on out-of-bounds: the value is clamped to the violated bound (or the implicit numeric-type limit when | ||
| * no explicit bound is set), and the second element of the reply reflects the actual applied increment. Without | ||
| * {@code SATURATE}, an out-of-bounds operation is silently rejected: the key value and TTL are unchanged and the reply is | ||
| * {@code [current_value, 0]}. | ||
| */ | ||
| public T saturate() { | ||
| this.saturate = true; | ||
| return self(); | ||
| } | ||
|
|
||
| public T ex(long seconds) { | ||
| this.ex = seconds; | ||
| return self(); | ||
| } | ||
|
|
||
| public T px(long milliseconds) { | ||
| this.px = milliseconds; | ||
| return self(); | ||
| } | ||
|
|
||
| public T exAt(long timestampSeconds) { | ||
| this.exAt = timestampSeconds; | ||
| return self(); | ||
| } | ||
|
|
||
| public T pxAt(long timestampMilliseconds) { | ||
| this.pxAt = timestampMilliseconds; | ||
| return self(); | ||
| } | ||
|
|
||
| public T persist() { | ||
| this.persist = true; | ||
| return self(); | ||
| } | ||
|
|
||
| /** | ||
| * Apply the expiry only if the key does not already have one ({@code Expiry only if Not eXists}). If the key already has a | ||
| * TTL, the existing TTL is preserved. | ||
| */ | ||
| public T enx() { | ||
| this.enx = true; | ||
| return self(); | ||
| } | ||
|
|
||
| @Override | ||
| public <K, V> void build(CommandArgs<K, V> args) { | ||
|
|
||
| buildBounds(args); | ||
|
|
||
| if (saturate) { | ||
| args.add(CommandKeyword.SATURATE); | ||
| } | ||
|
|
||
| if (ex != null) { | ||
| args.add(CommandKeyword.EX).add(ex); | ||
| } | ||
| if (px != null) { | ||
| args.add(CommandKeyword.PX).add(px); | ||
| } | ||
| if (exAt != null) { | ||
| args.add(CommandKeyword.EXAT).add(exAt); | ||
| } | ||
| if (pxAt != null) { | ||
| args.add(CommandKeyword.PXAT).add(pxAt); | ||
| } | ||
| if (persist) { | ||
| args.add(CommandType.PERSIST); | ||
| } | ||
|
|
||
| if (enx) { | ||
| args.add(CommandKeyword.ENX); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Subclasses emit their typed {@code LBOUND}/{@code UBOUND} here. | ||
| */ | ||
| protected abstract <K, V> void buildBounds(CommandArgs<K, V> args); | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.