Skip to content

Commit 9beac92

Browse files
TheSmartnikbadboy
authored andcommitted
Add geopos
1 parent 0daddfb commit 9beac92

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/redis.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2744,6 +2744,17 @@ def georadiusbymember(*args, **geoptions)
27442744
end
27452745
end
27462746

2747+
# Returns longitude and latitude of members of a geospatial index
2748+
#
2749+
# @param [String] key
2750+
# @param [String, Array<String>] member one member or array of members
2751+
# @return [Array<Array<String>, null>] returns array of elements, where each element is either array of longitude and latitude or nil
2752+
def geopos(key, member)
2753+
synchronize do |client|
2754+
client.call([:geopos, key, member])
2755+
end
2756+
end
2757+
27472758
# Interact with the sentinel command (masters, master, slaves, failover)
27482759
#
27492760
# @param [String] subcommand e.g. `masters`, `master`, `slaves`

test/commands_on_geo_test.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,20 @@ def test_georadiusbymember_with_options_count_sort
4343
city = r.georadiusbymember("Sicily", "Catania", 200, 'km', sort: :desc, options: :WITHDIST, count: 1)
4444
assert_equal [["Palermo", "166.2742"]], city
4545
end
46+
47+
def test_geopos
48+
location = r.geopos("Sicily", "Catania")
49+
assert_equal [["15.08726745843887329", "37.50266842333162032"]], location
50+
51+
locations = r.geopos("Sicily", ["Palermo", "Catania"])
52+
assert_equal [["13.36138933897018433", "38.11555639549629859"], ["15.08726745843887329", "37.50266842333162032"]], locations
53+
end
54+
55+
def test_geopos_nonexistant_location
56+
location = r.geopos("Sicily", "Rome")
57+
assert_equal [nil], location
58+
59+
locations = r.geopos("Sicily", ["Rome", "Catania"])
60+
assert_equal [nil, ["15.08726745843887329", "37.50266842333162032"]], locations
61+
end
4662
end

0 commit comments

Comments
 (0)