redis/jedis · error · IllegalArgumentException
Both BYRADIUS and BYBOX cannot be used.
Error message
Both BYRADIUS and BYBOX cannot be used.
What it means
GEOSEARCH accepts exactly one search shape: BYRADIUS or BYBOX. GeoSearchParam.addParams() detects both being set and throws this IllegalArgumentException because the resulting command would be ambiguous and rejected by Redis.
Solutions
- Remove one of the two shape calls so only byRadius OR byBox remains
- Rebuild a fresh GeoSearchParam when switching search shape instead of mutating a shared instance
- Branch explicitly: use byRadius for radius semantics, byBox for rectangle semantics
Example fix
// before
GeoSearchParam p = new GeoSearchParam().fromMember("sicily").byRadius(100, GeoUnit.KM).byBox(100, 100, GeoUnit.KM);
// after
GeoSearchParam p = new GeoSearchParam().fromMember("sicily").byBox(100, 100, GeoUnit.KM); Defensive patterns
Strategy: type-guard
Validate before calling
if (useRadius && useBox) throw new IllegalStateException("Choose BYRADIUS or BYBOX, not both"); Type guard
GeoSearchParam shape(GeoSearchParam p, boolean byRadius, double r, double w, double h, GeoUnit u) {
return byRadius ? p.byRadius(r, u) : p.byBox(w, h, u);
} Try / catch
try {
jedis.geosearch(key, params);
} catch (IllegalArgumentException e) {
params = new GeoSearchParam().fromMember(m).byRadius(r, unit);
} Prevention
- Pick the search shape from a single enum/flag, not two booleans
- Rebuild params when switching shape
- Never apply byBox to a params object already carrying byRadius
When it happens
Trigger: Calling both .byRadius(...) and .byBox(...) (or .byBox with both width/height variants) on the same GeoSearchParam before execution.
Common situations: Code paths that switch between radius and box searches but both run on a shared params object; default params pre-populated with byRadius then updated with byBox instead of being rebuilt.
Related errors
- Both FROMMEMBER and FROMLONLAT cannot be used.
- COUNT must be set before ANY to be set
- Either FROMMEMBER or FROMLONLAT must 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/8468411a76bf5a51.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/redis/clients/jedis/params/GeoSearchParam.java:129
}
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) {
throw new IllegalArgumentException("Both BYRADIUS and BYBOX cannot be used.");
} else if (byRadius) {
args.add(Keyword.BYRADIUS).add(radius).add(unit);
} else if (byBox) {
args.add(Keyword.BYBOX).add(width).add(height).add(unit);
} else {
throw new IllegalArgumentException("Either BYRADIUS or BYBOX must be used.");
}
if (withCoord) {
args.add(Keyword.WITHCOORD);
}
if (withDist) {
args.add(Keyword.WITHDIST);
}
if (withHash) {
args.add(Keyword.WITHHASH);
}
View on GitHub (pinned to 6dac31d4c2)