Module: Oxblood::Commands::Geo

Included in:
Oxblood::Commands
Defined in:
lib/oxblood/commands/geo.rb

Instance Method Summary collapse

Instance Method Details

#geoadd(key, *items) ⇒ Integer

Add one or more geospatial items in the geospatial index represented using a sorted set.


14
15
16
# File 'lib/oxblood/commands/geo.rb', line 14

def geoadd(key, *items)
  run(*items.unshift(:GEOADD, key))
end

#geodist(key, member1, member2, unit = nil) ⇒ nil, String

Returns the distance between two members of a geospatial index.


56
57
58
59
60
61
62
# File 'lib/oxblood/commands/geo.rb', line 56

def geodist(key, member1, member2, unit = nil)
  if unit
    run(:GEODIST, key, member1, member2, unit)
  else
    run(:GEODIST, key, member1, member2)
  end
end

#geohash(key, *members) ⇒ Array

Returns members of a geospatial index as standard geohash strings.


26
27
28
# File 'lib/oxblood/commands/geo.rb', line 26

def geohash(key, *members)
  run(*members.unshift(:GEOHASH, key))
end

#geopos(key, *members) ⇒ Array

Returns longitude and latitude of members of a geospatial index.


40
41
42
# File 'lib/oxblood/commands/geo.rb', line 40

def geopos(key, *members)
  run(*members.unshift(:GEOPOS, key))
end

#georadius(key, longitude, latitude, radius, unit, opts = {}) ⇒ Array, Integer

Query a sorted set representing a geospatial index to fetch members matching a given maximum distance from a point.

Options Hash (opts):

  • :withcoord (Boolean)

    Also return the longitude, latitude coordinates of the matching items.

  • :withdist (Boolean)

    Also return the distance of the returned items from the specified center. The distance is returned in the same unit as the unit specified as the radius argument of the command.

  • :withhash (Boolean)

    Also return the raw geohash-encoded sorted set score of the item, in the form of a 52 bit unsigned integer. This is only useful for low level hacks or debugging and is otherwise of little interest for the general user.

  • :order (Symbol)

    The command default is to return unsorted items. Two different sorting methods can be invoked using the following two options:

    - ASC: from the nearest to the farthest, relative to the center.
    - DESC: from the farthest to the nearest, relative to the center.
    
  • :count (Integer)

    limit the results to the first N matching items.

  • :store (String)

    generates a valid geo index and stores result to key

  • :storedist (String)

    stores calculated distances to key.

See Also:


98
99
100
101
102
# File 'lib/oxblood/commands/geo.rb', line 98

def georadius(key, longitude, latitude, radius, unit, opts = {})
  args = [:GEORADIUS, key, longitude, latitude, radius, unit]
  add_georadius_opts!(args, opts)
  run(*args)
end

#georadiusbymember(key, member, radius, unit, opts = {}) ⇒ Array, Integer

Query a sorted set representing a geospatial index to fetch members matching a given maximum distance from a member.

Options Hash (opts):

  • :withcoord (Boolean)

    Also return the longitude, latitude coordinates of the matching items.

  • :withdist (Boolean)

    Also return the distance of the returned items from the specified center. The distance is returned in the same unit as the unit specified as the radius argument of the command.

  • :withhash (Boolean)

    Also return the raw geohash-encoded sorted set score of the item, in the form of a 52 bit unsigned integer. This is only useful for low level hacks or debugging and is otherwise of little interest for the general user.

  • :order (Symbol)

    The command default is to return unsorted items. Two different sorting methods can be invoked using the following two options:

    - ASC: from the nearest to the farthest, relative to the center.
    - DESC: from the farthest to the nearest, relative to the center.
    
  • :count (Integer)

    limit the results to the first N matching items.

  • :store (String)

    generates a valid geo index and stores result to key

  • :storedist (String)

    stores calculated distances to key.

See Also:


137
138
139
140
141
# File 'lib/oxblood/commands/geo.rb', line 137

def georadiusbymember(key, member, radius, unit, opts = {})
  args = [:GEORADIUSBYMEMBER, key, member, radius, unit]
  add_georadius_opts!(args, opts)
  run(*args)
end