redis/jedis · error · IllegalArgumentException

MAX_COUNT must be a positive integer

Error message

MAX_COUNT must be a positive integer

What it means

TSReadParams.maxCount(int maxCount) validates that MAX_COUNT is a positive integer before adding it to the TS.MREAD/TS.MRANGE command. MAX_COUNT limits how many samples per series are returned; 0 or negative values are invalid per the RedisTimeSeries protocol, so the client throws IllegalArgumentException.

Solutions

  1. Pass a positive integer (>= 1) for the page size.
  2. Stop paginating before calling the command when the remaining count reaches 0.
  3. Apply Math.max(1, requested) at the config boundary if a minimum page size is acceptable.

Example fix

// before
int remaining = total - fetched;
params.maxCount(remaining); // throws when remaining == 0
// after
int remaining = total - fetched;
if (remaining <= 0) return; // done paging
params.maxCount(remaining);
Defensive patterns

Strategy: validation

Validate before calling

int remaining = total - fetched;
if (remaining > 0) params.maxCount(remaining); else return;

Type guard

static boolean validMaxCount(int n) { return n > 0; }

Try / catch

try { params.maxCount(n); } catch (IllegalArgumentException e) { params.maxCount(1); }

Prevention

When it happens

Trigger: Calling TSReadParams.maxCount(0) or maxCount(-1); page-size fields defaulting to 0 from uninitialized config; computed limits like total - fetched that hit 0.

Common situations: Pagination code where a 'zero more items' condition accidentally calls maxCount(0) instead of stopping pagination; optional config defaults.

Related errors


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

Appendix: source

Thrown at src/main/java/redis/clients/jedis/timeseries/TSReadParams.java:107

      throw new IllegalArgumentException("BLOCK milliseconds must be a non-negative integer");
    }
    if (minCount <= 0) {
      throw new IllegalArgumentException("BLOCK min_count must be a positive integer");
    }
    this.blockMilliseconds = milliseconds;
    this.blockMinCount = minCount;
    return this;
  }

  /**
   * Reply cap. When more samples qualify than {@code maxCount}, the oldest {@code maxCount} are
   * returned so callers can page forward. Omitted means unlimited.
   * @param maxCount positive integer
   * @return this
   */
  public TSReadParams maxCount(int maxCount) {
    if (maxCount <= 0) {
      throw new IllegalArgumentException("MAX_COUNT must be a positive integer");
    }
    this.maxCount = maxCount;
    return this;
  }

  /**
   * @return true when the {@code BLOCK} group is present, so the command must be issued with
   *         blocking-command connection handling
   */
  public boolean isBlocking() {
    return blockMilliseconds != null;
  }

  @Override
  public void addParams(CommandArguments args) {

    // min_count <= max_count is required by the server when both are set; validate locally too.
    if (blockMinCount != null && maxCount != null && blockMinCount > maxCount) {

View on GitHub (pinned to 6dac31d4c2)