redis/jedis · error · IllegalArgumentException

BLOCK min_count must be a positive integer

Error message

BLOCK min_count must be a positive integer

What it means

TSReadParams.block(long milliseconds, int minCount) requires minCount to be a positive integer: BLOCK's min_count tells the server how many qualifying samples must arrive before unblocking, and 0 or negative values are invalid, so the client throws IllegalArgumentException before sending the command.

Solutions

  1. Pass a positive minCount (>= 1).
  2. If min-count is not needed, use the block overload that takes only milliseconds (or omit BLOCK entirely) instead of passing 0.
  3. Default optional config to a sane positive value (e.g. 1) when unset.

Example fix

// before
int minCount = config.getMinCount(); // defaults to 0
params.block(1000, minCount); // throws
// after
int minCount = Math.max(1, config.getMinCount());
params.block(1000, minCount);
Defensive patterns

Strategy: validation

Validate before calling

if (minCount <= 0) throw new IllegalStateException("minCount must be >= 1");
params.block(ms, minCount);

Type guard

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

Try / catch

try { params.block(ms, minCount); } catch (IllegalArgumentException e) { log.warn("invalid min_count {}, using 1", minCount); params.block(ms, 1); }

Prevention

When it happens

Trigger: Calling TSReadParams.block(1000, 0) or block(1000, -5); default/uninitialized int fields (0) passed straight into block().

Common situations: minCount loaded from optional config that defaults to 0 when unset; code that intends to 'skip' the min-count feature but calls the two-arg block() instead of the single-argument variant.

Related errors


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

Appendix: source

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

   * blocking it always yields an empty reply.
   */
  public TSReadParams newSamples() {
    this.timestamp = DOLLAR;
    return this;
  }

  /**
   * Opt into blocking. Both values are always emitted on the wire inside the {@code BLOCK} group.
   * @param milliseconds maximum wait, non-negative; {@code 0} means wait indefinitely
   * @param minCount unblock threshold, positive; the call returns once this many samples qualify
   * @return this
   */
  public TSReadParams block(long milliseconds, int minCount) {
    if (milliseconds < 0) {
      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;

View on GitHub (pinned to 6dac31d4c2)