quarkusio/quarkus · error · IllegalArgumentException
Cannot use `MAXLEN` and `MINID` together
Error message
Cannot use `MAXLEN` and `MINID` together
What it means
XADD supports stream trimming either by count (MAXLEN) or by minimum ID (MINID), never both. XAddArgs.toArgs() throws IllegalArgumentException when a maxlen > 0 was set and a minid is also present, since Redis cannot accept both trim strategies in one command.
Source
Thrown at extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/stream/XAddArgs.java:104
*
* @param limit the limit, must be positive
* @return the current {@code XAddArgs}
*/
public XAddArgs limit(long limit) {
this.limit = limit;
return this;
}
@Override
public List<Object> toArgs() {
List<Object> args = new ArrayList<>();
if (nomkstream) {
args.add("NOMKSTREAM");
}
if (maxlen > 0) {
if (minid != null) {
throw new IllegalArgumentException("Cannot use `MAXLEN` and `MINID` together");
}
args.add("MAXLEN");
if (approximateTrimming) {
args.add("~");
} else {
args.add("=");
}
args.add(Long.toString(maxlen));
}
if (minid != null) {
args.add("MINID");
if (approximateTrimming) {
args.add("~");
} else {
args.add("=");
}View on GitHub (pinned to e1c734241f)
Solutions
- Remove one of the two: keep maxlen(n) for count-based trimming or minId(id) for ID-based trimming
- Create a fresh XAddArgs per publish instead of reusing one
- Centralize trim policy in one code path so only one strategy is applied
Example fix
// before
XAddArgs args = new XAddArgs().maxlen(1000).minId("1600000000000-0");
// after
XAddArgs args = new XAddArgs().maxlen(1000); Defensive patterns
Strategy: validation
Validate before calling
if (maxLen > 0 && minId != null) throw new IllegalArgumentException("Use MAXLEN or MINID for XADD trimming, not both"); Try / catch
try {
stream.xadd(key, args, entries);
} catch (IllegalArgumentException e) {
// rebuild XAddArgs with a single trim strategy
} Prevention
- Centralize trimming policy in one place; switch strategy, don't stack options
- Never reuse a mutated XAddArgs across publishes
- Model trim strategy as a sealed/enum option (MaxLen or MinId), not two fields
When it happens
Trigger: Calling xAddArgs().maxlen(n) and .minId(id) on the same instance, then executing xadd; or reusing an XAddArgs where maxlen was set earlier and minid added later.
Common situations: Trim policy switched from count-based to ID-based but the old maxlen() call remains; merging default args (maxlen) with request-specific args (minid).
Related errors
- Cannot set the eviction limit when using exact trimming
- Cannot combine `IDLE` and `TIME`
- Cannot set XX and NX together
- BYRADIUS and BYBOX cannot be used together
- Cannot specify both `includes` and `excludes` terms
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/756969fb0e868028.
Report an issue: GitHub.