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 all commits
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| package io.lettuce.core; | ||
|
|
||
| import io.lettuce.core.protocol.CommandArgs; | ||
| import io.lettuce.core.protocol.CommandKeyword; | ||
|
|
||
| /** | ||
| * Argument list builder for the integer-bounded form of the Redis {@code INCREX} command. Accepts {@code long} lower/upper | ||
| * bounds; paired with the {@code increx(K, long, IncrexArgs)} overload on the commands interface (sends {@code BYINT} on the | ||
| * wire). | ||
| * <p> | ||
| * For float-bounded INCREX use {@link IncrexFloatArgs}. | ||
| * <p> | ||
| * Usage: | ||
| * | ||
| * <pre> | ||
| * IncrexArgs.Builder.ubound(100).saturate().ex(60) | ||
| * IncrexArgs.Builder.lbound(0).ubound(100).saturate() | ||
| * new IncrexArgs().ex(30).enx() | ||
| * </pre> | ||
| * | ||
| * @since 7.6 | ||
| */ | ||
| public class IncrexArgs extends BaseIncrexArgs<IncrexArgs> { | ||
|
|
||
| private Long lbound; | ||
|
|
||
| private Long ubound; | ||
|
|
||
| // ── Static Builder ───────────────────────────── | ||
|
|
||
| public static class Builder { | ||
|
|
||
| private Builder() { | ||
| } | ||
|
|
||
| public static IncrexArgs lbound(long lbound) { | ||
| return new IncrexArgs().lbound(lbound); | ||
| } | ||
|
|
||
| public static IncrexArgs ubound(long ubound) { | ||
| return new IncrexArgs().ubound(ubound); | ||
| } | ||
|
|
||
| public static IncrexArgs saturate() { | ||
| return new IncrexArgs().saturate(); | ||
| } | ||
|
|
||
| public static IncrexArgs ex(long seconds) { | ||
| return new IncrexArgs().ex(seconds); | ||
| } | ||
|
|
||
| public static IncrexArgs px(long milliseconds) { | ||
| return new IncrexArgs().px(milliseconds); | ||
| } | ||
|
|
||
| public static IncrexArgs exAt(long timestampSeconds) { | ||
| return new IncrexArgs().exAt(timestampSeconds); | ||
| } | ||
|
|
||
| public static IncrexArgs pxAt(long timestampMilliseconds) { | ||
| return new IncrexArgs().pxAt(timestampMilliseconds); | ||
| } | ||
|
|
||
| public static IncrexArgs persist() { | ||
| return new IncrexArgs().persist(); | ||
| } | ||
|
|
||
| public static IncrexArgs enx() { | ||
| return new IncrexArgs().enx(); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| // ── Fluent Setters ───────────────────────────── | ||
|
|
||
| public IncrexArgs lbound(long lbound) { | ||
| this.lbound = lbound; | ||
| return this; | ||
| } | ||
|
|
||
| public IncrexArgs ubound(long ubound) { | ||
| this.ubound = ubound; | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| protected <K, V> void buildBounds(CommandArgs<K, V> args) { | ||
|
|
||
| if (lbound != null) { | ||
| args.add(CommandKeyword.LBOUND); | ||
| args.add(lbound); | ||
| } | ||
|
|
||
| if (ubound != null) { | ||
| args.add(CommandKeyword.UBOUND); | ||
| args.add(ubound); | ||
| } | ||
| } | ||
|
|
||
| } |
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,100 @@ | ||
| package io.lettuce.core; | ||
|
|
||
| import io.lettuce.core.protocol.CommandArgs; | ||
| import io.lettuce.core.protocol.CommandKeyword; | ||
|
|
||
| /** | ||
| * Argument list builder for the floating-point-bounded form of the Redis {@code INCREX} command. Accepts {@code double} | ||
| * lower/upper bounds; paired with the {@code increx(K, double, IncrexFloatArgs)} overload on the commands interface (sends | ||
| * {@code BYFLOAT} on the wire). | ||
| * <p> | ||
| * For integer-bounded INCREX use {@link IncrexArgs}. | ||
| * <p> | ||
| * Usage: | ||
| * | ||
| * <pre> | ||
| * IncrexFloatArgs.Builder.ubound(100.0).saturate().ex(60) | ||
| * IncrexFloatArgs.Builder.lbound(0.0).ubound(100.0).saturate() | ||
| * new IncrexFloatArgs().ex(30).enx() | ||
| * </pre> | ||
| * | ||
| * @since 7.6 | ||
| */ | ||
| public class IncrexFloatArgs extends BaseIncrexArgs<IncrexFloatArgs> { | ||
|
|
||
| private Double lbound; | ||
|
a-TODO-rov marked this conversation as resolved.
Resolved
|
||
|
|
||
| private Double ubound; | ||
|
|
||
| // ── Static Builder ───────────────────────────── | ||
|
|
||
| public static class Builder { | ||
|
|
||
| private Builder() { | ||
| } | ||
|
|
||
| public static IncrexFloatArgs lbound(double lbound) { | ||
| return new IncrexFloatArgs().lbound(lbound); | ||
| } | ||
|
|
||
| public static IncrexFloatArgs ubound(double ubound) { | ||
| return new IncrexFloatArgs().ubound(ubound); | ||
| } | ||
|
|
||
| public static IncrexFloatArgs saturate() { | ||
| return new IncrexFloatArgs().saturate(); | ||
| } | ||
|
|
||
| public static IncrexFloatArgs ex(long seconds) { | ||
| return new IncrexFloatArgs().ex(seconds); | ||
| } | ||
|
|
||
| public static IncrexFloatArgs px(long milliseconds) { | ||
| return new IncrexFloatArgs().px(milliseconds); | ||
| } | ||
|
|
||
| public static IncrexFloatArgs exAt(long timestampSeconds) { | ||
| return new IncrexFloatArgs().exAt(timestampSeconds); | ||
| } | ||
|
|
||
| public static IncrexFloatArgs pxAt(long timestampMilliseconds) { | ||
| return new IncrexFloatArgs().pxAt(timestampMilliseconds); | ||
| } | ||
|
|
||
| public static IncrexFloatArgs persist() { | ||
| return new IncrexFloatArgs().persist(); | ||
| } | ||
|
|
||
| public static IncrexFloatArgs enx() { | ||
| return new IncrexFloatArgs().enx(); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| // ── Fluent Setters ───────────────────────────── | ||
|
|
||
| public IncrexFloatArgs lbound(double lbound) { | ||
| this.lbound = lbound; | ||
| return this; | ||
| } | ||
|
|
||
| public IncrexFloatArgs ubound(double ubound) { | ||
| this.ubound = ubound; | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| protected <K, V> void buildBounds(CommandArgs<K, V> args) { | ||
|
|
||
| if (lbound != null) { | ||
| args.add(CommandKeyword.LBOUND); | ||
| args.add(lbound); | ||
| } | ||
|
|
||
| if (ubound != null) { | ||
| args.add(CommandKeyword.UBOUND); | ||
| args.add(ubound); | ||
| } | ||
| } | ||
|
|
||
| } | ||
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.