Command builders for Redis geospatial operations.
Provides pure functions that build command lists for storing, querying, and
measuring geographic coordinates using Redis sorted sets. Supports adding
members with longitude/latitude (GEOADD), searching by radius or bounding box
(GEOSEARCH), computing distances (GEODIST), and retrieving positions (GEOPOS).
Each function returns a plain list of strings suitable for passing to
Redis.command/2 or Redis.pipeline/2.
These functions contain no connection or networking logic -- they only construct the Redis protocol command as a list.
Examples
Add geographic coordinates for several locations:
iex> Redis.Commands.Geo.geoadd("restaurants", [{-122.4194, 37.7749, "San Francisco"}, {-73.9857, 40.7484, "New York"}])
["GEOADD", "restaurants", "-122.4194", "37.7749", "San Francisco", "-73.9857", "40.7484", "New York"]Search for members within a radius of a given point:
iex> Redis.Commands.Geo.geosearch("restaurants", fromlonlat: {-122.4194, 37.7749}, byradius: {50, "km"}, asc: true)
["GEOSEARCH", "restaurants", "FROMLONLAT", "-122.4194", "37.7749", "BYRADIUS", "50", "km", "ASC"]Compute the distance between two members:
iex> Redis.Commands.Geo.geodist("restaurants", "San Francisco", "New York", "mi")
["GEODIST", "restaurants", "San Francisco", "New York", "mi"]
Summary
Functions
Builds a GEOADD command to add members with longitude/latitude to a geo set.
Builds a GEODIST command to compute the distance between two members.
Builds a GEOPOS command to retrieve the longitude/latitude of one or more members.
Deprecated: use geosearch/2 instead.
Deprecated: use geosearch/2 instead.
Builds a GEOSEARCH command to query members within a geographic area.
Functions
Builds a GEOADD command to add members with longitude/latitude to a geo set.
Each member is a {longitude, latitude, name} tuple. Supports :nx (only add
new members), :xx (only update existing), and :ch (return count of changed
elements).
Example
iex> Redis.Commands.Geo.geoadd("places", [{13.361389, 38.115556, "Palermo"}], ch: true)
["GEOADD", "places", "CH", "13.361389", "38.115556", "Palermo"]
Builds a GEODIST command to compute the distance between two members.
The optional unit argument can be "m" (meters, default), "km", "mi", or "ft".
Examples
iex> Redis.Commands.Geo.geodist("places", "Palermo", "Catania")
["GEODIST", "places", "Palermo", "Catania"]
iex> Redis.Commands.Geo.geodist("places", "Palermo", "Catania", "km")
["GEODIST", "places", "Palermo", "Catania", "km"]
Builds a GEOPOS command to retrieve the longitude/latitude of one or more members.
Example
iex> Redis.Commands.Geo.geopos("places", ["Palermo", "Catania"])
["GEOPOS", "places", "Palermo", "Catania"]
@spec georadius( String.t(), float(), float(), float() | integer(), String.t(), keyword() ) :: [ String.t() ]
Deprecated: use geosearch/2 instead.
@spec georadiusbymember( String.t(), String.t(), float() | integer(), String.t(), keyword() ) :: [ String.t() ]
Deprecated: use geosearch/2 instead.
Builds a GEOSEARCH command to query members within a geographic area.
Requires an origin (:fromlonlat or :frommember) and a shape (:byradius
or :bybox). Supports ordering (:asc/:desc), result limiting (:count),
and optional coordinate/distance/hash output (:withcoord, :withdist,
:withhash).
Example
iex> Redis.Commands.Geo.geosearch("places", frommember: "Palermo", byradius: {200, "km"}, count: 5, withcoord: true)
["GEOSEARCH", "places", "FROMMEMBER", "Palermo", "BYRADIUS", "200", "km", "COUNT", "5", "WITHCOORD"]