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", with_coordinates: false, with_distance: false, with_hash: false, count: nil, order: nil, store: nil, store_distance: 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")
  • count (Integer) (defaults to: nil)

    Limit the number of results to at most this many.

  • order (Symbol) (defaults to: nil)

    ‘:ASC` Sort returned items from the nearest to the farthest, relative to the center. `:DESC` Sort returned items from the farthest to the nearest, relative to the center.

  • with_coordinates (Boolean) (defaults to: false)

    Also return the longitude,latitude coordinates of the matching items.

  • with_distance (Boolean) (defaults to: false)

    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.

  • with_hash (Boolean) (defaults to: false)

    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.

  • store (Key) (defaults to: nil)
  • store_distance (Key) (defaults to: nil)

See Also:



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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/protocol/redis/methods/geospatial.rb', line 74

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

#georadiusbymember(key, member, radius, unit = "m", with_coordinates: false, with_distance: false, with_hash: false, count: nil, order: nil, store: nil, store_distance: 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")
  • count (Integer) (defaults to: nil)

    Limit the number of results to at most this many.

  • order (Symbol) (defaults to: nil)

    ‘:ASC` Sort returned items from the nearest to the farthest, relative to the center. `:DESC` Sort returned items from the farthest to the nearest, relative to the center.

  • with_coordinates (Boolean) (defaults to: false)

    Also return the longitude,latitude coordinates of the matching items.

  • with_distance (Boolean) (defaults to: false)

    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.

  • with_hash (Boolean) (defaults to: false)

    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.

  • store (Key) (defaults to: nil)
  • store_distance (Key) (defaults to: nil)

See Also:



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/protocol/redis/methods/geospatial.rb', line 130

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