Module: Redis::Commands::Geo
- Included in:
- Redis::Commands
- Defined in:
- lib/redis/commands/geo.rb
Instance Method Summary collapse
-
#geoadd(key, *member, nx: false, xx: false, ch: false) ⇒ Integer
Adds the specified geospatial items (latitude, longitude, name) to the specified key.
-
#geodist(key, member1, member2, unit = 'm') ⇒ String?
Returns the distance between two members of a geospatial index.
-
#geohash(key, member) ⇒ Array<String, nil>
Returns geohash string representing position for specified members of the specified key.
-
#geopos(key, member) ⇒ Array<Array<String>, nil>
Returns longitude and latitude of members of a geospatial index.
-
#georadius(*args, **geoptions) ⇒ Array<String>
Query a sorted set representing a geospatial index to fetch members matching a given maximum distance from a point.
-
#georadiusbymember(*args, **geoptions) ⇒ Array<String>
Query a sorted set representing a geospatial index to fetch members matching a given maximum distance from an already existing member.
-
#geosearch(key, frommember: nil, fromlonlat: nil, byradius: nil, bybox: nil, sort: nil, count: nil, count_any: false, withcoord: false, withdist: false, withhash: false) ⇒ Array<String>
Return the members of a geospatial sorted set that are within the borders of the area specified by a given shape, either a circle (BYRADIUS) or a rectangle (BYBOX), starting from a center point given either by member (FROMMEMBER) or by longitude and latitude (FROMLONLAT).
-
#geosearchstore(destination, source, frommember: nil, fromlonlat: nil, byradius: nil, bybox: nil, sort: nil, count: nil, count_any: false, storedist: false) ⇒ Integer
Like GEOSEARCH, but stores the result in a destination key.
Instance Method Details
#geoadd(key, *member, nx: false, xx: false, ch: false) ⇒ Integer
Adds the specified geospatial items (latitude, longitude, name) to the specified key
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/redis/commands/geo.rb', line 14 def geoadd(key, *member, nx: false, xx: false, ch: false) raise ArgumentError, "can't supply both nx and xx" if nx && xx args = [:geoadd, key] args << "NX" if nx args << "XX" if xx args << "CH" if ch args.concat(member) send_command(args) end |
#geodist(key, member1, member2, unit = 'm') ⇒ String?
Returns the distance between two members of a geospatial index
169 170 171 |
# File 'lib/redis/commands/geo.rb', line 169 def geodist(key, member1, member2, unit = 'm') send_command([:geodist, key, member1, member2, unit]) end |
#geohash(key, member) ⇒ Array<String, nil>
Returns geohash string representing position for specified members of the specified key.
30 31 32 |
# File 'lib/redis/commands/geo.rb', line 30 def geohash(key, member) send_command([:geohash, key, member]) end |
#geopos(key, member) ⇒ Array<Array<String>, nil>
Returns longitude and latitude of members of a geospatial index
72 73 74 |
# File 'lib/redis/commands/geo.rb', line 72 def geopos(key, member) send_command([:geopos, key, member]) end |
#georadius(*args, **geoptions) ⇒ Array<String>
Query a sorted set representing a geospatial index to fetch members matching a given maximum distance from a point
44 45 46 47 48 |
# File 'lib/redis/commands/geo.rb', line 44 def georadius(*args, **) geoarguments = _geoarguments(*args, **) send_command([:georadius, *geoarguments]) end |
#georadiusbymember(*args, **geoptions) ⇒ Array<String>
Query a sorted set representing a geospatial index to fetch members matching a given maximum distance from an already existing member
60 61 62 63 64 |
# File 'lib/redis/commands/geo.rb', line 60 def georadiusbymember(*args, **) geoarguments = _geoarguments(*args, **) send_command([:georadiusbymember, *geoarguments]) end |
#geosearch(key, frommember: nil, fromlonlat: nil, byradius: nil, bybox: nil, sort: nil, count: nil, count_any: false, withcoord: false, withdist: false, withhash: false) ⇒ Array<String>
Return the members of a geospatial sorted set that are within the borders of the area specified by a given shape, either a circle (BYRADIUS) or a rectangle (BYBOX), starting from a center point given either by member (FROMMEMBER) or by longitude and latitude (FROMLONLAT). Available since Redis 6.2.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/redis/commands/geo.rb', line 102 def geosearch(key, frommember: nil, fromlonlat: nil, byradius: nil, bybox: nil, sort: nil, count: nil, count_any: false, withcoord: false, withdist: false, withhash: false) args = [key] args << "FROMMEMBER" << frommember if frommember args << "FROMLONLAT" << fromlonlat[0] << fromlonlat[1] if fromlonlat args << "BYRADIUS" << byradius[0] << byradius[1] if byradius args << "BYBOX" << bybox[0] << bybox[1] << bybox[2] if bybox = [] << "WITHCOORD" if withcoord << "WITHDIST" if withdist << "WITHHASH" if withhash geoarguments = _geoarguments(*args, sort: sort, count: count, count_any: count_any, options: ) send_command([:geosearch, *geoarguments]) end |
#geosearchstore(destination, source, frommember: nil, fromlonlat: nil, byradius: nil, bybox: nil, sort: nil, count: nil, count_any: false, storedist: false) ⇒ Integer
Like GEOSEARCH, but stores the result in a destination key. By default the destination is populated with the matching members and their geospatial scores; when STOREDIST is set, the members are stored with their distance from the center point as the score. Available since Redis 6.2.
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/redis/commands/geo.rb', line 147 def geosearchstore(destination, source, frommember: nil, fromlonlat: nil, byradius: nil, bybox: nil, sort: nil, count: nil, count_any: false, storedist: false) args = [destination, source] args << "FROMMEMBER" << frommember if frommember args << "FROMLONLAT" << fromlonlat[0] << fromlonlat[1] if fromlonlat args << "BYRADIUS" << byradius[0] << byradius[1] if byradius args << "BYBOX" << bybox[0] << bybox[1] << bybox[2] if bybox = [] << "STOREDIST" if storedist geoarguments = _geoarguments(*args, sort: sort, count: count, count_any: count_any, options: ) send_command([:geosearchstore, *geoarguments]) end |