GEOHASH
Syntax
Parameters
Parameter | Description | Type | Required |
---|---|---|---|
key | The name of the sorted set containing geospatial data. | string | Yes |
member | One or more members whose Geohash representations are requested. | string | Yes |
Return Values
Condition | Return Value |
---|---|
Geohash representation for valid members. | A string representing the Geohash of each member. |
Non-existent member in the specified key. | (nil) for that member. |
Incorrect Argument Count | ERR wrong number of arguments for 'geohash' command |
Non-existent or invalid key type. | WRONGTYPE Operation against a key holding the wrong kind of value |
Behaviour
When the GEOHASH command is issued, DiceDB performs the following steps:
- Checks if the key exists and corresponds to a valid geospatial dataset.
- Verifies the presence of each specified member within the dataset.
- For each member:
- If the member exists, its Geohash representation is returned.
- If the member does not exist,
(nil)
is returned.
- Returns the results as an array of strings or nil values, maintaining the order of input members.
Errors
-
Wrong Number of Arguments
- Error Message: (error) ERR wrong number of arguments for ‘geohash’ command
- Occurs when the command is executed without a key or member(s).
-
Key Does Not Exist or Is of Wrong Type
- Error Message: (error) WRONGTYPE Operation against a key holding the wrong kind of value
- Occurs when the specified key does not exist or is not a sorted set.
-
Member Does Not Exist
- Error Message: Returns
(nil)
for non-existent members. - Occurs when a member is specified but not found under the given key.
- Error Message: Returns
Example Usage
Here are a few examples demonstrating the usage of the GEOHASH command:
Example: Retrieve Geohash for Existing Members
Example: Retrieve Geohash for a Non-Existent Member
Example: Retrieve Geohash with a Non-Existent Key
Example: Retrieve Geohash with Missing Arguments
Notes
- The returned Geohash strings are encoded representations of the geographic locations stored in the sorted set.
- Geohash precision is influenced by the DiceDB implementation and is typically sufficient for most spatial queries.