redis/jedis · error · IllegalArgumentException
COUNT must be set before ANY to be set
Error message
COUNT must be set before ANY to be set
What it means
GeoSearchParam.any() adds the ANY modifier to the COUNT option of GEOSEARCH, but Redis semantics require ANY to immediately follow COUNT. The library enforces call order: any() throws if count(x) has not been called yet, preventing an invalid argument ordering from ever reaching the server.
Solutions
- Call .count(n) before .any() in the chain, e.g. new GeoSearchParam().count(10).any()
- If you do not need the ANY optimization, drop the .any() call entirely
Example fix
// before GeoSearchParam p = new GeoSearchParam().any().count(10); // after GeoSearchParam p = new GeoSearchParam().count(10).any();
Defensive patterns
Strategy: validation
Validate before calling
if (wantAny && count <= 0) throw new IllegalArgumentException("ANY requires COUNT set first"); Try / catch
try {
GeoSearchParam p = new GeoSearchParam().count(n).any();
} catch (IllegalArgumentException e) {
GeoSearchParam p = new GeoSearchParam().count(n); // retry without ANY
} Prevention
- Build GeoSearchParam chains in Redis argument order: origin, shape, COUNT, then ANY
- Never start a chain with .any()
- Add a comment noting COUNT-before-ANY ordering
When it happens
Trigger: Calling new GeoSearchParam().any() (or chaining .any() before .count(n)) on GEOSEARCH/GEOSEARCHSTORE params.
Common situations: Builder-call ordering mistakes in fluent chains; devs assuming order-independent setters; upgrading code where count was removed or moved after any().
Understand the failure class
Background: "must be a positive integer", "cannot be empty", "invalid argument": how invalid-argument errors work across open-source libraries — this error's family across 33 libraries.
Related errors
- Both FROMMEMBER and FROMLONLAT cannot be used.
- Either FROMMEMBER or FROMLONLAT must be used.
- Both BYRADIUS and BYBOX cannot be used.
- Either BYRADIUS or BYBOX must be used.
- GeoRadiusStoreParam must has store or storedist option
AI-assisted analysis of redis/jedis@6dac31d4c2 (2026-09-08).
Data as JSON: /api/errors/4d16003317fa75ef.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/redis/clients/jedis/params/GeoSearchParam.java:110
public GeoSearchParam sortingOrder(SortingOrder order) {
sortingOrder = order;
return this;
}
public GeoSearchParam count(int count) {
this.count = count;
return this;
}
public GeoSearchParam count(int count, boolean any) {
this.count = count;
this.any = true;
return this;
}
public GeoSearchParam any() {
if (this.count == null) {
throw new IllegalArgumentException("COUNT must be set before ANY to be set");
}
this.any = true;
return this;
}
@Override
public void addParams(CommandArguments args) {
if (fromMember && fromLonLat) {
throw new IllegalArgumentException("Both FROMMEMBER and FROMLONLAT cannot be used.");
} else if (fromMember) {
args.add(Keyword.FROMMEMBER).add(member);
} else if (fromLonLat) {
args.add(Keyword.FROMLONLAT).add(coord.getLongitude()).add(coord.getLatitude());
} else {
throw new IllegalArgumentException("Either FROMMEMBER or FROMLONLAT must be used.");
}
if (byRadius && byBox) {View on GitHub (pinned to 6dac31d4c2)