Protocol::Redis SourceProtocolRedisMethodsGeospatial

module Geospatial

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.

Implementation

def geoadd(key, longitude, latitude, member, *arguments)
	call("GEOADD", 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.

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.

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)).

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.

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", storedist)
		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.

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
	
	if store
		arguments.append("STORE", store)
	end
	
	if store_distance
		arguments.append("STOREDIST", storedist)
	end
	
	readonly = true
	
	if store
		arguments.append("STORE", store)
		readonly = false
	end
	
	if store_distance
		arguments.append("STOREDIST", storedist)
		readonly = false
	end
	
	# https://redis.io/commands/georadius#read-only-variants
	if readonly
		call("GEORADIUSBYMEMBER_RO", *arguments)
	else
		call("GEORADIUSBYMEMBER", *arguments)
	end
end