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
GeoRadiusArgs.toArgs() validates that the ANY option (return any close-enough members instead of the nearest) is only meaningful together with COUNT. Redis rejects ANY without COUNT, so the library throws this IllegalArgumentException before sending the GEORADIUS/GEORADIUSBYMEMBER command.
Source
Thrown at extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/geo/GeoRadiusArgs.java:107
/**
* When ANY is provided the command will return as soon as enough matches are found, so the results may not be the
* ones closest to the specified point, but on the other hand, the effort invested by the server is significantly
* lower.
* <p>
* Using {@code ANY} requires {@code count} to be set.
*
* @return the current {@code GeoRadiusArgs}
**/
public GeoRadiusArgs any() {
this.any = true;
return this;
}
@Override
public List<Object> toArgs() {
// Validation
if (any && count == -1) {
throw new IllegalArgumentException("ANY can only be used if COUNT is also 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");
list.add(Long.toString(count));
}
View on GitHub (pinned to e1c734241f)
Solutions
- Always chain count(n) when using any(): GeoRadiusArgs.Builder.geoRadiusArgs().count(10).any().
- If ANY is set from config, only apply it when a count value is also configured; otherwise drop any().
- Remove any() if the query does not limit results.
Example fix
// before GeoRadiusArgs args = GeoRadiusArgs.Builder.geoRadiusArgs().any(); // throws in toArgs // after GeoRadiusArgs args = GeoRadiusArgs.Builder.geoRadiusArgs().count(10).any();
Defensive patterns
Strategy: validation
Validate before calling
GeoRadiusArgs.Builder b = GeoRadiusArgs.Builder.geoRadiusArgs();
if (useAny) {
if (count <= 0) throw new IllegalArgumentException("ANY requires COUNT>0");
b.count(count).any();
} else if (count > 0) {
b.count(count);
} Try / catch
try { return geo.georadius(key, lon, lat, dist, unit, args); } catch (IllegalArgumentException e) { if (e.getMessage().contains("ANY can only be used if COUNT")) { args.count(10).any(); return geo.georadius(key, lon, lat, dist, unit, args); } throw e; } Prevention
- Treat any() as an add-on to count(n), never a standalone option.
- When any() comes from config, require the count property to also be present and positive.
- Centralize GeoRadiusArgs construction in one helper that enforces the ANY+COUNT pairing.
When it happens
Trigger: Calling geoRadiusArgs.any() without a preceding count(n) on the same args object, then passing it to georadius/georadiusbymember; also when any() is set from a flag but the count value was never configured (left at the internal default -1).
Common situations: Config with an enabled 'useAny' flag but no count property; fluent chains copied from examples that included any() but dropped count(); building options conditionally where count() is skipped by a branch.
Related errors
- Cannot set XX and NX together
- The longitude must be in [-180, 180]
- The latitude must be in [85.05112878, 85.05112878]
- 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/0f501303a6626d23.
Report an issue: GitHub.