Skip to content

Commit 32ab539

Browse files
TheSmartnikbadboy
authored andcommitted
Add geodist command
1 parent 9beac92 commit 32ab539

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/redis.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2755,6 +2755,18 @@ def geopos(key, member)
27552755
end
27562756
end
27572757

2758+
# Returns the distance between two members of a geospatial index
2759+
#
2760+
# @param [String ]key
2761+
# @param [Array<String>] members
2762+
# @param ['m', 'km', 'mi', 'ft'] unit
2763+
# @return [String, nil] returns distance in spefied unit if both members present, nil otherwise.
2764+
def geodist(key, member1, member2, unit = 'm')
2765+
synchronize do |client|
2766+
client.call([:geodist, key, member1, member2, unit])
2767+
end
2768+
end
2769+
27582770
# Interact with the sentinel command (masters, master, slaves, failover)
27592771
#
27602772
# @param [String] subcommand e.g. `masters`, `master`, `slaves`

test/commands_on_geo_test.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,17 @@ def test_geopos_nonexistant_location
5959
locations = r.geopos("Sicily", ["Rome", "Catania"])
6060
assert_equal [nil, ["15.08726745843887329", "37.50266842333162032"]], locations
6161
end
62+
63+
def test_geodist
64+
distination_in_meters = r.geodist("Sicily", "Palermo", "Catania")
65+
assert_equal "166274.1516", distination_in_meters
66+
67+
distination_in_feet = r.geodist("Sicily", "Palermo", "Catania", 'ft')
68+
assert_equal "545518.8700", distination_in_feet
69+
end
70+
71+
def test_geodist_with_nonexistant_location
72+
distination = r.geodist("Sicily", "Palermo", "Rome")
73+
assert_equal nil, distination
74+
end
6275
end

0 commit comments

Comments
 (0)