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:

  • key (String)
  • member (Array)

    arguemnts for member or members: longitude, latitude, name

Returns:

  • (Integer)

    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:

  • key (String)
  • members (Array<String>)
  • unit ('m', 'km', 'mi', 'ft') (defaults to: 'm')

Returns:

  • (String, nil)

    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:

  • key (String)
  • member (String, Array<String>)

    one member or array of members

Returns:

  • (Array<String, nil>)

    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:

  • key (String)
  • member (String, Array<String>)

    one member or array of members

Returns:

  • (Array<Array<String>, nil>)

    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:

  • args (Array)

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

  • sort ('asc', 'desc')

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

  • count (Integer)

    limit the results to the first N matching items

  • options ('WITHDIST', 'WITHCOORD', 'WITHHASH')

    to return additional information

Returns:

  • (Array<String>)

    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:

  • args (Array)

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

  • sort ('asc', 'desc')

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

  • count (Integer)

    limit the results to the first N matching items

  • options ('WITHDIST', 'WITHCOORD', 'WITHHASH')

    to return additional information

Returns:

  • (Array<String>)

    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