Redis GEODIST – How to get distance between two members of geospatial value
2 weeks ago Lalit Bhagtani 0
In this tutorial, we will learn about how to get the distance between two members of geospatial value stored at a key, by using a COMMAND – GEODIST in redis-cli.
This command is used to return the distance between two members of geospatial value ( Sorted Set ) stored at a key in specified unit. If one or both specified members does not exist in the geospatial value, then null is returned.
The specified unit must be of the following type :-
- m for meter ( default ).
- km for kilometer.
- mi for miles.
- ft for feet.
Nil is returned when key does not exist and error is returned when key exist but value stored at the key is not of sorted set datatype, populated using GEOADD command. The syntax of redis GEODIST command is as follows :-
redis host:post> GEODIST <keyname> <member-1> <member-2> [unit]
- (string) reply, representing the distance in specified unit. - Nil, if key does not exist. - Error, if key exist and value stored at the key is not a sorted set populated using GEOADD command.
That’s all for how to get the distance between two members of geospatial value stored in redis datastore. If you liked it, please share your thoughts in comments section and share it with others too.