Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

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
a-TODO-rov committed May 22, 2026
commit c1eca2c893511771ba4dfdf20da152535ca85b86
4 changes: 2 additions & 2 deletions src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -1627,8 +1627,8 @@ public RedisFuture<IncrexValue<Long>> increx(K key, long amount, IncrexArgs incr
}

@Override
public RedisFuture<IncrexValue<Double>> increxfloat(K key, double amount, IncrexArgs increxArgs) {
return dispatch(commandBuilder.increxfloat(key, amount, increxArgs));
public RedisFuture<IncrexValue<Double>> increx(K key, double amount, IncrexFloatArgs increxArgs) {
return dispatch(commandBuilder.increx(key, amount, increxArgs));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1669,8 +1669,8 @@ public Mono<IncrexValue<Long>> increx(K key, long amount, IncrexArgs increxArgs)
}

@Override
public Mono<IncrexValue<Double>> increxfloat(K key, double amount, IncrexArgs increxArgs) {
return createMono(() -> commandBuilder.increxfloat(key, amount, increxArgs));
public Mono<IncrexValue<Double>> increx(K key, double amount, IncrexFloatArgs increxArgs) {
return createMono(() -> commandBuilder.increx(key, amount, increxArgs));
}

@Override
Expand Down
120 changes: 120 additions & 0 deletions src/main/java/io/lettuce/core/BaseIncrexArgs.java
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 &mdash; 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 {
Comment thread
a-TODO-rov marked this conversation as resolved.
Resolved

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);

}
107 changes: 8 additions & 99 deletions src/main/java/io/lettuce/core/IncrexArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import io.lettuce.core.protocol.CommandArgs;
import io.lettuce.core.protocol.CommandKeyword;
import io.lettuce.core.protocol.CommandType;

/**
* Argument list builder for the Redis {@code INCREX} command. Holds bounds, saturate flag, expiration, and ENX options.
* 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>
* The increment value and mode (BYINT/BYFLOAT) are determined by which method is called on the commands interface, not by this
* args class.
* For float-bounded INCREX use {@link IncrexFloatArgs}.
* <p>
* Usage:
*
Expand All @@ -20,25 +20,11 @@
*
* @since 7.6
*/
public class IncrexArgs implements CompositeArgument {
public class IncrexArgs extends BaseIncrexArgs<IncrexArgs> {

private Number lbound;
private Long lbound;

private Number ubound;

private boolean saturate = false;

private Long ex;

private Long px;

private Long exAt;

private Long pxAt;

private boolean persist = false;

private boolean enx = false;
private Long ubound;

// ── Static Builder ─────────────────────────────

Expand All @@ -51,18 +37,10 @@ public static IncrexArgs lbound(long lbound) {
return new IncrexArgs().lbound(lbound);
}

public static IncrexArgs lbound(double lbound) {
return new IncrexArgs().lbound(lbound);
}

public static IncrexArgs ubound(long ubound) {
return new IncrexArgs().ubound(ubound);
}

public static IncrexArgs ubound(double ubound) {
return new IncrexArgs().ubound(ubound);
}

public static IncrexArgs saturate() {
return new IncrexArgs().saturate();
}
Expand Down Expand Up @@ -100,58 +78,13 @@ public IncrexArgs lbound(long lbound) {
return this;
}

public IncrexArgs lbound(double lbound) {
this.lbound = lbound;
return this;
}

public IncrexArgs ubound(long ubound) {
this.ubound = ubound;
return this;
}

public IncrexArgs ubound(double ubound) {
this.ubound = ubound;
return this;
}

public IncrexArgs saturate() {
this.saturate = true;
return this;
}

public IncrexArgs ex(long seconds) {
this.ex = seconds;
return this;
}

public IncrexArgs px(long milliseconds) {
this.px = milliseconds;
return this;
}

public IncrexArgs exAt(long timestampSeconds) {
this.exAt = timestampSeconds;
return this;
}

public IncrexArgs pxAt(long timestampMilliseconds) {
this.pxAt = timestampMilliseconds;
return this;
}

public IncrexArgs persist() {
this.persist = true;
return this;
}

public IncrexArgs enx() {
this.enx = true;
return this;
}

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

if (lbound != null) {
args.add(CommandKeyword.LBOUND);
Expand All @@ -162,30 +95,6 @@ public <K, V> void build(CommandArgs<K, V> args) {
args.add(CommandKeyword.UBOUND);
args.add(ubound);
}

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);
}
}

}
Loading
Loading
⌂ 换网址