quarkusio/quarkus · error · IllegalArgumentException

Cannot set the eviction limit when using exact trimming

Error message

Cannot set the eviction limit when using exact trimming

What it means

The LIMIT option for XADD trimming limits how many entries the eviction may remove per trim, and Redis only permits it when trimming is approximate (with ~). If limit > 0 was set but approximateTrimming is false (exact trimming via =), XAddArgs.toArgs() throws IllegalArgumentException because the LIMIT argument would be invalid.

Source

Thrown at extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/stream/XAddArgs.java:128

            } else {
                args.add("=");
            }
            args.add(Long.toString(maxlen));
        }

        if (minid != null) {
            args.add("MINID");
            if (approximateTrimming) {
                args.add("~");
            } else {
                args.add("=");
            }
            args.add(minid);
        }

        if (limit > 0) {
            if (!approximateTrimming) {
                throw new IllegalArgumentException("Cannot set the eviction limit when using exact trimming");
            }
            args.add("LIMIT");
            args.add(Long.toString(limit));
        }

        args.add(Objects.requireNonNullElse(id, "*"));
        return args;
    }
}

View on GitHub (pinned to e1c734241f)

Solutions

  1. Enable approximate trimming: add .approximateTrimming(true) when using .limit(m)
  2. Or remove the .limit(m) call if exact (MAXLEN =) trimming is required
  3. Reset the XAddArgs builder so a stale limit isn't combined with exact trimming

Example fix

// before
XAddArgs args = new XAddArgs().maxlen(1000).limit(50);
// after
XAddArgs args = new XAddArgs().maxlen(1000).approximateTrimming(true).limit(50);
Defensive patterns

Strategy: validation

Validate before calling

if (limit > 0 && !approximateTrimming) throw new IllegalArgumentException("LIMIT requires approximate (~) trimming");

Try / catch

try {
    stream.xadd(key, args, entries);
} catch (IllegalArgumentException e) {
    // rebuild args with approximateTrimming(true) or drop limit
}

Prevention

When it happens

Trigger: Calling xAddArgs().maxlen(n).limit(m) without .approximateTrimming(true), or setting exact trimming while a limit remains from previous configuration.

Common situations: Copy-pasting example code that sets limit but forgetting approximateTrimming(); defaults that set limit but code path chooses exact trimming; misunderstanding that LIMIT implies '~'.

Related errors


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