quarkusio/quarkus · error · IllegalArgumentException

Cannot use LT and GT together

Error message

Cannot use LT and GT together

What it means

ZADD's LT (update only if lower score) and GT (update only if greater score) modifiers are mutually exclusive in Redis. ZAddArgs.toArgs() throws IllegalArgumentException when both boolean flags are set, because the resulting command would be rejected by the server.

Source

Thrown at extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/sortedset/ZAddArgs.java:77

    /**
     * Only update existing elements if the new score is greater than the current score.
     * This flag doesn't prevent adding new elements.
     *
     * @return the current {@code ZAddArgs}
     **/
    public ZAddArgs gt() {
        this.gt = true;
        return this;
    }

    @Override
    public List<Object> toArgs() {
        if (xx && nx) {
            throw new IllegalArgumentException("Cannot use XX and NX together");
        }
        if (lt && gt) {
            throw new IllegalArgumentException("Cannot use LT and GT together");
        }

        List<Object> args = new ArrayList<>();
        putFlag(args, nx, "NX");
        putFlag(args, xx, "XX");
        putFlag(args, lt, "LT");
        putFlag(args, gt, "GT");
        putFlag(args, ch, "CH");
        return args;
    }

    public void putFlag(List<Object> args, boolean value, String flag) {
        if (value) {
            args.add(flag);
        }
    }
}

View on GitHub (pinned to e1c734241f)

Solutions

  1. Keep only .lt() or only .gt() depending on desired update direction
  2. Reset or recreate ZAddArgs when the comparison mode changes
  3. Guard with an if/else so only one flag is ever set

Example fix

// before
ZAddArgs args = new ZAddArgs().lt().gt();
// after
ZAddArgs args = new ZAddArgs().lt(); // lower-than-only updates
Defensive patterns

Strategy: validation

Validate before calling

if (lowerThan && greaterThan) throw new IllegalArgumentException("Choose LT or GT for ZADD, not both");

Try / catch

try {
    sortedSet.zadd(key, score, member, args);
} catch (IllegalArgumentException e) {
    // reset args with only lt or gt
}

Prevention

When it happens

Trigger: Chaining .lt().gt() (or calling both setters) on ZAddArgs before a zadd call.

Common situations: Choosing comparison direction from config/user input where the variable can end up 'both'; reusing a mutated ZAddArgs across calls.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/7ec2056128cdae06. Report an issue: GitHub.