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.

Parameters:

  • key (String)
  • items (Array<[String, String, String]>)

    Geospatial items (longitude, latitude, member)

Returns:

  • (Integer)

    The number of elements added to the sorted set, not including elements already existing for which the score was updated.

See Also:



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.

Parameters:

  • key (String)
  • member1 (String)

    name of geospatial index member

  • member2 (String)

    name of geospatial index member

  • unit (nil, String) (defaults to: nil)

    that could be one of the following and defaults to meters: m (meters), km (kilometers), mi (miles), ft (feet).

Returns:

  • (nil, String)

    The command returns the distance as a double (represented as a string) in the specified unit, or nil if one or both elements are missing.

See Also:



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.

Parameters:

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

Returns:

  • (Array)

    The command returns an array where each element is the Geohash corresponding to each member name passed as argument to the command.

See Also:



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.

Parameters:

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

Returns:

  • (Array)

    an array where each element is a two elements array representing longitude and latitude (x,y) of each member name passed as argument to the command. Non existing elements are reported as ‘nil` elements of the array.

See Also:



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.

Parameters:

  • key (String)
  • longitude (String)
  • latitude (String)
  • radius (Integer)
  • unit (Symbol)

    that could be one of the following and defaults to meters: m (meters), km (kilometers), mi (miles), ft (feet).

  • opts (Hash) (defaults to: {})

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.

Returns:

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.

Parameters:

  • key (String)
  • member (String)
  • radius (Integer)
  • unit (Symbol)

    that could be one of the following and defaults to meters: m (meters), km (kilometers), mi (miles), ft (feet).

  • opts (Hash) (defaults to: {})

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.

Returns:

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