Module: Protocol::Redis::Methods::Geospatial

Defined in:
lib/protocol/redis/methods/geospatial.rb

Instance Method Summary collapse

Instance Method Details

#geoadd(key, longitude, latitude, member, *arguments) ⇒ Object

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.

Parameters:

  • key (Key)

See Also:



30
31
32
# File 'lib/protocol/redis/methods/geospatial.rb', line 30

def geoadd(key, longitude, latitude, member, *arguments)
	call("GEOADD", longitude, latitude, member, *arguments)
end

#geodist(key, from, to, unit = "m") ⇒ Object

Returns the distance between two members of a geospatial index. O(log(N)).

Parameters:

  • key (Key)
  • member1 (String)
  • member2 (String)
  • unit (Enum) (defaults to: "m")

    Distance scale to use, one of “m” (meters), “km” (kilometers), “mi” (miles) or “ft” (feet).

See Also:



56
57
58
# File 'lib/protocol/redis/methods/geospatial.rb', line 56

def geodist(key, from, to, unit = "m")
	call("GEODIST", key, from, to, unit)
end

#geohash(key, member, *members) ⇒ Object

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.

Parameters:

  • key (Key)
  • member (String)

See Also:



38
39
40
# File 'lib/protocol/redis/methods/geospatial.rb', line 38

def geohash(key, member, *members)
	call("GEOHASH", key, member, *members)
end

#geopos(key, member, *members) ⇒ Object

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.

Parameters:

  • key (Key)
  • member (String)

See Also:



46
47
48
# File 'lib/protocol/redis/methods/geospatial.rb', line 46

def geopos(key, member, *members)
	call("GEOPOS", key, member, *members)
end

#georadius(key, longitude, latitude, radius, unit = "m", withcoord: false, withdist: false, withhash: false, count: nil, store: nil, storedist: nil) ⇒ Object

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.

Parameters:

  • key (Key)
  • longitude (Double)
  • latitude (Double)
  • radius (Double)
  • unit (Enum) (defaults to: "m")
  • withcoord (Enum) (defaults to: false)
  • withdist (Enum) (defaults to: false)
  • withhash (Enum) (defaults to: false)

See Also:



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/protocol/redis/methods/geospatial.rb', line 70

def georadius(key, longitude, latitude, radius, unit = "m", withcoord: false, withdist: false, withhash: false, count: nil, store: nil, storedist: nil)
	arguments = [key, longitude, latitude, radius, unit]
	
	if withcoord
		arguments.append("WITHCOORD")
	end
	
	if withdist
		arguments.append("WITHDIST")
	end
	
	if withhash
		arguments.append("WITHHASH")
	end
	
	if count
		arguments.append("COUNT", count)
	end
	
	if store
		arguments.append("STORE", store)
	end
	
	if storedist
		arguments.append("STOREDIST", storedist)
	end
	
	call("GEORADIUS", *arguments)
end

#georadiusbymember(key, member, radius, unit = "m", withcoord: false, withdist: false, withhash: false, count: nil, store: nil, storedist: nil) ⇒ Object

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.

Parameters:

  • key (Key)
  • member (String)
  • radius (Double)
  • unit (Enum) (defaults to: "m")
  • withcoord (Enum) (defaults to: false)
  • withdist (Enum) (defaults to: false)
  • withhash (Enum) (defaults to: false)
  • order (Enum)

See Also:



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/protocol/redis/methods/geospatial.rb', line 110

def georadiusbymember(key, member, radius, unit = "m", withcoord: false, withdist: false, withhash: false, count: nil, store: nil, storedist: nil)
	arguments = [key, member, radius, unit]
	
	if withcoord
		arguments.append("WITHCOORD")
	end
	
	if withdist
		arguments.append("WITHDIST")
	end
	
	if withhash
		arguments.append("WITHHASH")
	end
	
	if count
		arguments.append("COUNT", count)
	end
	
	if store
		arguments.append("STORE", store)
	end
	
	if storedist
		arguments.append("STOREDIST", storedist)
	end
	
	call("GEORADIUS", *arguments)
end