Module: Redis::Commands::Geo

Included in:
Redis::Commands
Defined in:
lib/redis/commands/geo.rb

Instance Method Summary collapse

Instance Method Details

#geoadd(key, *member) ⇒ Integer

Adds the specified geospatial items (latitude, longitude, name) to the specified key

Parameters:

  • arguemnts for member or members: longitude, latitude, name

Returns:

  • number of elements added to the sorted set



11
12
13
# File 'lib/redis/commands/geo.rb', line 11

def geoadd(key, *member)
  send_command([:geoadd, key, *member])
end

#geodist(key, member1, member2, unit = 'm') ⇒ String?

Returns the distance between two members of a geospatial index

Parameters:

  • (defaults to: 'm')

Returns:

  • returns distance in spefied unit if both members present, nil otherwise.



70
71
72
# File 'lib/redis/commands/geo.rb', line 70

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.

Parameters:

  • one member or array of members

Returns:

  • returns array containg geohash string if member is present, nil otherwise



20
21
22
# File 'lib/redis/commands/geo.rb', line 20

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

Parameters:

  • one member or array of members

Returns:

  • returns array of elements, where each element is either array of longitude and latitude or nil



60
61
62
# File 'lib/redis/commands/geo.rb', line 60

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

Parameters:

  • key, longitude, latitude, radius, unit(m|km|ft|mi)

  • sort returned items from the nearest to the farthest or the farthest to the nearest relative to the center

  • limit the results to the first N matching items

  • to return additional information

Returns:

  • may be changed with ‘options`



33
34
35
36
37
# File 'lib/redis/commands/geo.rb', line 33

def georadius(*args, **geoptions)
  geoarguments = _geoarguments(*args, **geoptions)

  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

Parameters:

  • key, member, radius, unit(m|km|ft|mi)

  • sort returned items from the nearest to the farthest or the farthest to the nearest relative to the center

  • limit the results to the first N matching items

  • to return additional information

Returns:

  • may be changed with ‘options`



48
49
50
51
52
# File 'lib/redis/commands/geo.rb', line 48

def georadiusbymember(*args, **geoptions)
  geoarguments = _geoarguments(*args, **geoptions)

  send_command([:georadiusbymember, *geoarguments])
end