Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

GEOADD

Last updated
GEOADD key [NX | XX] [CH] longitude latitude member [longitude latitude member ...]
Group
Geospatial
Complexity
O(log N) per member
Arity
-5 (at least 5 words, counting the command name)
Flags
write
Keys
first 1, last 1, step 1
HotKV Cloud
All plans
On-Premise
no license needed

GEOADD stores each member with its position in the sorted set at key, creating the key if needed. The position is encoded as the member’s score, so you can also use sorted set commands such as ZRANGE, ZREM and ZCARD on the same key. Adding a member that already exists updates its position.

Longitude comes first, then latitude. Valid longitudes are -180 to 180 and valid latitudes -85.05112878 to 85.05112878 (the poles are not covered).

Option Effect
NX Only add new members; never update existing ones.
XX Only update existing members; never add new ones.
CH Return the number of members added or moved, instead of only added.

NX and XX cannot be combined. The options come before the first longitude.

Case RESP2 RESP3
Default Integer: members added Integer
With CH Integer: members added plus members whose position changed Integer

Error replies:

  • ERR syntax error when NX and XX are combined or the triplets are incomplete.
  • ERR value is not a valid float for a coordinate that is not a number.
  • ERR invalid longitude,latitude pair 200.000000,10.000000 (with your values) for an out-of-range position.
  • WRONGTYPE if the key holds a value that is not a sorted set.

Nothing is stored when any argument is invalid.

127.0.0.1:6379> GEOADD cities -0.1276 51.5072 london 2.3522 48.8566 paris 4.3517 50.8503 brussels
(integer) 3
127.0.0.1:6379> GEOADD cities CH 4.3517 50.8503 brussels 4.9041 52.3676 amsterdam
(integer) 1
127.0.0.1:6379> GEOADD cities NX 0 0 paris
(integer) 0
127.0.0.1:6379> GEOADD cities 200 10 nowhere
(error) ERR invalid longitude,latitude pair 200.000000,10.000000

Same as Redis 7 and Valkey 8. Members get the same scores as in Redis, so geospatial sorted sets can be copied between the two with ZRANGE and ZADD.

GEOPOS, GEODIST, GEOSEARCH, GEOHASH, ZREM