GEOPOS
The GEOPOS
command in DiceDB is used to return the longitude, latitude to a specified key which is stored in a sorted set. When elements are added via GEOADD
then they are stored in 52 bit geohash hence the values returned by GEOPOS
might have small margins of error.
Syntax
Parameters
Parameter | Description | Type | Required |
---|---|---|---|
key | The name of the sorted set key whose member’s coordinates are to be returned | string | Yes |
member | A unique identifier for the location. | string | Yes |
Return Values
Condition | Return Value |
---|---|
Coordinates exist for the specified member(s) | Returns an ordered list of coordinates (longitude, latitude) for each specified member |
Coordinates do not exist for the specified member(s) | Returns (nil) for each member without coordinates |
Incorrect Argument Count | ERR wrong number of arguments for 'geopos' command |
Key does not exist in the sorted set | Error: nil |
Behaviour
When the GEOPOS command is issued, DiceDB performs the following steps:
- It checks if argument count is valid or not. If not an error is thrown.
- It checks the validity of the key.
- If the key is invalid then an error is returned.
- Else it checks the members provided after the key.
- For each member it checks the coordinates of the member.
- If the coordinates exist then it is returned in an ordered list of latitude, longitude for the particular member.
- If the coordinates do not exist then a
(nil)
is returned for that member.
Errors
Wrong number of arguments for 'GEOPOS' command
- Error Message: (error) ERR wrong number of arguments for ‘geoadd’ command.
- Occurs when the command is executed with an incorrect number of arguments.
Wrong key for 'GEOPOS' command
- Error Message: Error: nil
- Occurs when the command is executed with a key that does not exist in the sorted set.
Example Usage
Here are a few examples demonstrating the usage of the GEOPOS command: