redis/jedis · error · IllegalArgumentException

COUNT or EXACTLY must be specified.

Error message

COUNT or EXACTLY must be specified.

What it means

LMPOP-style multi-list move params must carry a COUNT or EXACTLY selector before being serialized. LMoveMParams.addParams() throws this IllegalArgumentException when neither count(...) nor exactly(...) was called, because the command arguments would be incomplete/invalid.

Solutions

  1. Call .count(n, order) or .exactly(n, order) on the LMoveMParams before executing the command
  2. If you don't want a count, use the command overload that takes no LMoveMParams
  3. Check factory/builder code paths to ensure one of the two selector methods is always invoked

Example fix

// before
LMoveMParams params = new LMoveMParams();
jedis.lmpop(keys, LeftRight.LEFT, params);
// after
LMoveMParams params = new LMoveMParams().count(3, ListMoveOrder.OBO);
jedis.lmpop(keys, LeftRight.LEFT, params);
Defensive patterns

Strategy: validation

Validate before calling

if (params == null || !hasSelector(params)) params = new LMoveMParams().count(n, ListMoveOrder.OBO);

Try / catch

try {
  jedis.lmpop(keys, LeftRight.LEFT, params);
} catch (IllegalArgumentException e) {
  jedis.lmpop(keys, LeftRight.LEFT, new LMoveMParams().count(1, ListMoveOrder.OBO));
}

Prevention

When it happens

Trigger: Executing the multi-list LMOVE/LMPOP command with LMoveMParams built only via builder methods other than count()/exactly() — e.g. an empty new LMoveMParams() or one constructed by a factory that only set the order.

Common situations: Building params conditionally where both count and exactly branches were skipped; reusing a params object whose selector was expected to be set elsewhere; misunderstanding that COUNT/EXACTLY is mandatory for this command form.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of redis/jedis@6dac31d4c2 (2026-09-08). Data as JSON: /api/errors/f8af903589d148dc. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/redis/clients/jedis/params/LMoveMParams.java:62

  /**
   * Move exactly {@code count} elements, or nothing (a {@code null} reply) if the source list does
   * not hold that many, ordered by {@code order}. Mutually exclusive with
   * {@link #count(int, ListMoveOrder)} (last call wins).
   */
  public LMoveMParams exactly(int count, ListMoveOrder order) {
    if (order == null) {
      throw new IllegalArgumentException("Ordering (OBO or BULK) must not be null.");
    }
    this.selector = Keyword.EXACTLY;
    this.count = count;
    this.order = order;
    return this;
  }

  @Override
  public void addParams(CommandArguments args) {
    if (selector == null || count == null) {
      throw new IllegalArgumentException("COUNT or EXACTLY must be specified.");
    }
    args.add(selector).add(count).add(order);
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
    LMoveMParams that = (LMoveMParams) o;
    return selector == that.selector && Objects.equals(count, that.count) && order == that.order;
  }

  @Override
  public int hashCode() {
    return Objects.hash(selector, count, order);
  }
}

View on GitHub (pinned to 6dac31d4c2)