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
- Pass a positive integer (>= 1) for the page size.
- Stop paginating before calling the command when the remaining count reaches 0.
- 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
- Stop pagination before requesting 0 items
- Clamp page-size config to >= 1
- Keep page-size defaults positive in config classes
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
- BLOCK milliseconds must be a non-negative integer
- BLOCK min_count must be a positive integer
- Aggregators must be non-null and non-empty
- Aggregators must not contain null elements
- FILTER arguments must be set.
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)