module Geospatial
Methods for managing Redis geospatial indexes.
Definitions
def geoadd(key, longitude, latitude, member, *arguments)
Add one or more geospatial items in the geospatial index represented using a sorted set. O(log(N)) for each item added, where N is the number of elements in the sorted set. See https://redis.io/commands/geoadd for more details.
Signature
-
parameter
keyKey
Implementation
def geoadd(key, longitude, latitude, member, *arguments)
call("GEOADD", key, longitude, latitude, member, *arguments)
end
def geohash(key, member, *members)
Returns members of a geospatial index as standard geohash strings. O(log(N)) for each member requested, where N is the number of elements in the sorted set. See https://redis.io/commands/geohash for more details.
Signature
-
parameter
keyKey -
parameter
memberString
Implementation
def geohash(key, member, *members)
call("GEOHASH", key, member, *members)
end
def geopos(key, member, *members)
Returns longitude and latitude of members of a geospatial index. O(log(N)) for each member requested, where N is the number of elements in the sorted set. See https://redis.io/commands/geopos for more details.
Signature
-
parameter
keyKey -
parameter
memberString
Implementation
def geopos(key, member, *members)
call("GEOPOS", key, member, *members)
end
def geodist(key, from, to, unit = "m")
Returns the distance between two members of a geospatial index. O(log(N)). See https://redis.io/commands/geodist for more details.
Signature
-
parameter
keyKey -
parameter
member1String -
parameter
member2String -
parameter
unitEnum Distance scale to use, one of "m" (meters), "km" (kilometers), "mi" (miles) or "ft" (feet).
Implementation
def geodist(key, from, to, unit = "m")
call("GEODIST", key, from, to, unit)
end
def georadius(key, longitude, latitude, radius, unit = "m", with_coordinates: false, with_distance: false, with_hash: false, count: nil, order: nil, store: nil, store_distance: nil)
Query a sorted set representing a geospatial index to fetch members matching a given maximum distance from a point. O(N+log(M)) where N is the number of elements inside the bounding box of the circular area delimited by center and radius and M is the number of items inside the index. See https://redis.io/commands/georadius for more details.
Signature
-
parameter
keyKey -
parameter
longitudeDouble -
parameter
latitudeDouble -
parameter
radiusDouble -
parameter
unitEnum -
parameter
countInteger Limit the number of results to at most this many.
-
parameter
orderSymbol :ASCSort returned items from the nearest to the farthest, relative to the center.:DESCSort returned items from the farthest to the nearest, relative to the center.-
parameter
with_coordinatesBoolean Also return the longitude,latitude coordinates of the matching items.
-
parameter
with_distanceBoolean Also return the distance of the returned items from the specified center. The distance is returned in the same unit as the unit specified as the radius argument of the command.
-
parameter
with_hashBoolean Also return the raw geohash-encoded sorted set score of the item, in the form of a 52 bit unsigned integer. This is only useful for low level hacks or debugging and is otherwise of little interest for the general user.
-
parameter
storeKey -
parameter
store_distanceKey
Implementation
def georadius(key, longitude, latitude, radius, unit = "m", with_coordinates: false, with_distance: false, with_hash: false, count: nil, order: nil, store: nil, store_distance: nil)
arguments = [key, longitude, latitude, radius, unit]
if with_coordinates
arguments.append("WITHCOORD")
end
if with_distance
arguments.append("WITHDIST")
end
if with_hash
arguments.append("WITHHASH")
end
if count
arguments.append("COUNT", count)
end
if order
arguments.append(order)
end
readonly = true
if store
arguments.append("STORE", store)
readonly = false
end
if store_distance
arguments.append("STOREDIST", store_distance)
readonly = false
end
# https://redis.io/commands/georadius#read-only-variants
if readonly
call("GEORADIUS_RO", *arguments)
else
call("GEORADIUS", *arguments)
end
end
def georadiusbymember(key, member, radius, unit = "m", with_coordinates: false, with_distance: false, with_hash: false, count: nil, order: nil, store: nil, store_distance: nil)
Query a sorted set representing a geospatial index to fetch members matching a given maximum distance from a member. O(N+log(M)) where N is the number of elements inside the bounding box of the circular area delimited by center and radius and M is the number of items inside the index. See https://redis.io/commands/georadiusbymember for more details.
Signature
-
parameter
keyKey -
parameter
memberString -
parameter
radiusDouble -
parameter
unitEnum -
parameter
countInteger Limit the number of results to at most this many.
-
parameter
orderSymbol :ASCSort returned items from the nearest to the farthest, relative to the center.:DESCSort returned items from the farthest to the nearest, relative to the center.-
parameter
with_coordinatesBoolean Also return the longitude,latitude coordinates of the matching items.
-
parameter
with_distanceBoolean Also return the distance of the returned items from the specified center. The distance is returned in the same unit as the unit specified as the radius argument of the command.
-
parameter
with_hashBoolean Also return the raw geohash-encoded sorted set score of the item, in the form of a 52 bit unsigned integer. This is only useful for low level hacks or debugging and is otherwise of little interest for the general user.
-
parameter
storeKey -
parameter
store_distanceKey
Implementation
def georadiusbymember(key, member, radius, unit = "m", with_coordinates: false, with_distance: false, with_hash: false, count: nil, order: nil, store: nil, store_distance: nil)
arguments = [key, member, radius, unit]
if with_coordinates
arguments.append("WITHCOORD")
end
if with_distance
arguments.append("WITHDIST")
end
if with_hash
arguments.append("WITHHASH")
end
if count
arguments.append("COUNT", count)
end
if order
arguments.append(order)
end
readonly = true
if store
arguments.append("STORE", store)
readonly = false
end
if store_distance
arguments.append("STOREDIST", store_distance)
readonly = false
end
# https://redis.io/commands/georadius#read-only-variants
if readonly
call("GEORADIUSBYMEMBER_RO", *arguments)
else
call("GEORADIUSBYMEMBER", *arguments)
end
end