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

In GEOSEARCH/GEOSEARCHSTORE (and GEORADIUS variants), the ANY modifier is only meaningful together with COUNT: it lets Redis return the first matching members found rather than the nearest ones. GeoRadiusParam.any() enforces ordering — if count was never set, calling any() throws IllegalArgumentException telling the caller to set COUNT first.

Solutions

  1. Call count(n) before any(): geoRadiusParam().count(10).any().
  2. If unlimited results are wanted, remove any() — it has no meaning without COUNT.
  3. Wrap params construction in a helper that always applies count first when any is requested.

Example fix

// before
GeoRadiusParam params = GeoRadiusParam.geoRadiusParam().any(); // COUNT missing
// after
GeoRadiusParam params = GeoRadiusParam.geoRadiusParam().count(10).any();
Defensive patterns

Strategy: validation

Validate before calling

if (wantAny && countValue == null) {
  throw new IllegalArgumentException("GEO any() requires count(n) first");
}

Try / catch

try {
  jedis.geosearch(key, member, radius, unit, params);
} catch (IllegalArgumentException e) {
  if (e.getMessage().contains("COUNT must be set before ANY")) {
    params = GeoRadiusParam.geoRadiusParam().count(defaultCount).any();
  } else throw e;
}

Prevention

When it happens

Trigger: Calling geoRadiusParam().any() (or geoSearchParam...any()) without a preceding count(n) on the same params object; building params where any() is invoked before count() in the builder chain.

Common situations: Copying GEOSEARCH ANY examples from the Redis CLI without the accompanying COUNT; method-chaining any() first out of reading order; generic param builders that apply flags in the wrong sequence.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of redis/jedis@6dac31d4c2 (2026-09-08). Data as JSON: /api/errors/b86cc025ce237b0b. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/redis/clients/jedis/params/GeoRadiusParam.java:65

  public GeoRadiusParam sortingOrder(SortingOrder order) {
    this.sortingOrder = order;
    return this;
  }

  public GeoRadiusParam count(int count) {
    this.count = count;
    return this;
  }

  public GeoRadiusParam count(int count, boolean any) {
    this.count = count;
    this.any = any;
    return this;
  }

  public GeoRadiusParam 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 (withCoord) {
      args.add(Keyword.WITHCOORD);
    }
    if (withDist) {
      args.add(Keyword.WITHDIST);
    }
    if (withHash) {
      args.add(Keyword.WITHHASH);
    }

View on GitHub (pinned to 6dac31d4c2)