redis/jedis · error · IllegalArgumentException

Both FROMMEMBER and FROMLONLAT cannot be used.

Error message

Both FROMMEMBER and FROMLONLAT cannot be used.

What it means

GEOSEARCH accepts exactly one origin: FROMMEMBER (a sorted-set member) or FROMLONLAT (coordinates). GeoSearchParam.addParams() detects that both fromMember and fromLonLat were set and refuses to build a command that Redis would reject, throwing this IllegalArgumentException client-side.

Solutions

  1. Remove one of the two origin calls so only fromMember OR fromLonLat remains
  2. If the origin is dynamic, branch explicitly and set only one, e.g. member != null ? param.fromMember(member) : param.fromLonLat(lon, lat)
  3. Reset/rebuild the GeoSearchParam instead of reusing one that already has an origin set

Example fix

// before
GeoSearchParam p = new GeoSearchParam().fromMember("palermo").fromLonLat(15.0, 37.0);
// after
GeoSearchParam p = new GeoSearchParam().fromMember("palermo");
Defensive patterns

Strategy: type-guard

Validate before calling

if (fromMember != null && coords != null) throw new IllegalStateException("Set only one GEOSEARCH origin: FROMMEMBER or FROMLONLAT");

Type guard

GeoSearchParam origin(GeoSearchParam p, String member, double lon, double lat) {
  return member != null ? p.fromMember(member) : p.fromLonLat(lon, lat);
}

Try / catch

try {
  jedis.geosearch(key, params);
} catch (IllegalArgumentException e) {
  params = rebuildWithSingleOrigin();
}

Prevention

When it happens

Trigger: Calling both .fromMember(...) and .fromLonLat(lon, lat) (or .fromCoordinate(...)) on the same GeoSearchParam before executing GEOSEARCH or GEOSEARCHSTORE.

Common situations: Merging two param-building code paths that each set a different origin; conditionally setting an origin but accidentally setting both branches; copy-paste leaving a stale fromLonLat default.

Related errors


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

Appendix: source

Thrown at src/main/java/redis/clients/jedis/params/GeoSearchParam.java:119

  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) {
      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.");
    }

View on GitHub (pinned to 6dac31d4c2)