quarkusio/quarkus · error · IllegalArgumentException
ANY can only be used if COUNT is also set
Error message
ANY can only be used if COUNT is also set
What it means
GEOSEARCH/GEOPOS-style radius commands in the Quarkus Redis datasource accept an ANY modifier, which tells Redis not to sort results and return them as soon as enough are found. ANY is only meaningful together with the COUNT option, so GeoRadiusStoreArgs.toArgs validates the combination before building the command and throws IllegalArgumentException if `any` is set while no count was configured. This is a client-side guard that prevents sending an invalid command to Redis.
Source
Thrown at extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/geo/GeoRadiusStoreArgs.java:133
}
/**
* Store the items in a sorted set populated with their distance from the center as a floating point number, in the
* same unit specified in the radius.
*
* @param storeDistKey the storeDistKey value
* @return the current {@code GeoRadiusStoreArgs}
**/
public GeoRadiusStoreArgs<K> storeDistKey(K storeDistKey) {
this.storeDistKey = storeDistKey;
return this;
}
@Override
public List<Object> toArgs(Codec codec) {
// Validation
if (any && count == -1) {
throw new IllegalArgumentException("ANY can only be used if COUNT is also set");
}
if (storeDistKey == null && storeKey == null) {
throw new IllegalArgumentException("At least `STORE` or `STOREDIST` must be set");
}
List<Object> list = new ArrayList<>();
if (withDistance) {
list.add("WITHDIST");
}
if (withCoordinates) {
list.add("WITHCOORD");
}
if (withHash) {
list.add("WITHHASH");
}
if (count > 0) {
list.add("COUNT");View on GitHub (pinned to e1c734241f)
Solutions
- Add a COUNT option, e.g. args.setCount(10), whenever ANY is used
- Remove the ANY flag if unbounded results with sorting are acceptable
- Guard the args construction so any is only set when a count value is also configured
Example fix
// before
GeoRadiusStoreArgs<String> args = GeoRadiusStoreArgs.fromCoordinates(...)
.any();
// after
GeoRadiusStoreArgs<String> args = GeoRadiusStoreArgs.fromCoordinates(...)
.count(10)
.any(); Defensive patterns
Strategy: validation
Validate before calling
if (args.isAny() && args.getCount() == -1) { throw new IllegalStateException("ANY requires COUNT"); } Try / catch
try { geo.geoSearchStore(...); } catch (IllegalArgumentException e) { log.error("Invalid geo args: " + e.getMessage()); } Prevention
- Always pair any() with an explicit count(n)
- Centralize geo args construction in a helper method that enforces the invariant
- Add unit tests asserting the args combination you ship
When it happens
Trigger: Calling gposition/georadius args construction where setAny(true) (or the fluent any() variant) was invoked but setCount(...) was never called, then passing the GeoRadiusStoreArgs to a geo command that calls toArgs(codec).
Common situations: Developers copy example code using ANY for performance and forget the COUNT option; refactoring removes a count() call while leaving any(); builders reused across calls where one call set any but count was reset.
Related errors
- `radius` must be positive
- `width` must be positive
- `height` must be positive
- ANY can only be used if COUNT is also set
- At least `STORE` or `STOREDIST` must be set
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/582ae9bbcc13fb74.
Report an issue: GitHub.