Module: Redis::Commands::Geo
| Relationships & Source Files | |
| Extension / Inclusion / Inheritance Descendants | |
|
Included In:
| |
| Defined in: | lib/redis/commands/geo.rb |
Instance Method Summary
-
#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.
- #_geoarguments(*args, options: nil, sort: nil, count: nil, count_any: false) private
Instance Method Details
#_geoarguments(*args, options: nil, sort: nil, count: nil, count_any: false) (private)
[ GitHub ]# File 'lib/redis/commands/geo.rb', line 175
def _geoarguments(*args, options: nil, sort: nil, count: nil, count_any: false) args << sort if sort if count args << 'COUNT' << Integer(count) args << 'ANY' if count_any end args.concat(Array()) args end
#geoadd(key, *member, nx: false, xx: false, ch: false) ⇒ Integer
Adds the specified geospatial items (latitude, longitude, name) to the specified key
# 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
# 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.
# 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
# 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
# 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
# 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.
# 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.
# 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