redis/jedis · error · IllegalArgumentException

BLOCK min_count must be <= MAX_COUNT

Error message

BLOCK min_count must be <= MAX_COUNT

What it means

TSReadParams.addParams(CommandArguments) performs a cross-field consistency check: RedisTimeSeries requires BLOCK's min_count to be <= MAX_COUNT when both are set, and the client enforces it locally. If min_count exceeds max_count the command could never return enough samples to satisfy min_count, so the library throws IllegalArgumentException instead of sending a doomed request.

Solutions

  1. Ensure minCount <= maxCount whenever both are set, e.g. block(1000, Math.min(minCount, pageSize)).
  2. Reorder configuration so maxCount is validated first and minCount clamped to it.
  3. If min_count semantics matter more than the page limit, raise maxCount to at least minCount.

Example fix

// before
params.block(1000, 50).maxCount(10); // throws at command build
// after
int minCount = 50, maxCount = 10;
params.block(1000, Math.min(minCount, maxCount)).maxCount(maxCount);
Defensive patterns

Strategy: validation

Validate before calling

if (minCount > maxCount) {
  minCount = maxCount; // clamp before building params
}
params.block(blockMs, minCount).maxCount(maxCount);

Try / catch

try { jedis.tsMRange(params); } catch (IllegalArgumentException e) { log.error("min_count > max_count in TSReadParams", e); throw e; }

Prevention

When it happens

Trigger: Chaining TSReadParams.block(1000, 50).maxCount(10) (or setting the fields in any order) so minCount=50 > maxCount=10; mutating maxCount on a shared params object after block() was configured.

Common situations: Independent config values (block threshold and page size) sourced from different settings that no one reconciled; reuse of a mutable TSReadParams across calls where one field was updated but not the other.

Understand the failure class

Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.

Related errors


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

Appendix: source

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

    }
    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) {
      throw new IllegalArgumentException("BLOCK min_count must be <= MAX_COUNT");
    }

    args.add(timestamp);

    if (blockMilliseconds != null) {
      args.add(BLOCK).add(toByteArray(blockMilliseconds)).add(toByteArray(blockMinCount));
    }

    if (maxCount != null) {
      args.add(MAX_COUNT).add(toByteArray(maxCount));
    }
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }

View on GitHub (pinned to 6dac31d4c2)