Module: Protocol::Redis::Methods::Geospatial
- Defined in:
- lib/protocol/redis/methods/geospatial.rb
Instance Method Summary collapse
-
#geoadd(key, longitude, latitude, member, *arguments) ⇒ Object
Add one or more geospatial items in the geospatial index represented using a sorted set.
-
#geodist(key, from, to, unit = "m") ⇒ Object
Returns the distance between two members of a geospatial index.
-
#geohash(key, member, *members) ⇒ Object
Returns members of a geospatial index as standard geohash strings.
-
#geopos(key, member, *members) ⇒ Object
Returns longitude and latitude of members of a geospatial index.
-
#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.
-
#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.
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.
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)).
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.
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.
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.
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.
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 |