Skip to content

Commit cc584db

Browse files
TheSmartnikbadboy
authored andcommitted
Add geohash command
1 parent 7a84d7d commit cc584db

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
@@ -2721,6 +2721,18 @@ def geoadd(key, *member)
27212721
end
27222722
end
27232723

2724+
# Returns geohash string representing position for specified members of the specified key.
2725+
#
2726+
# @param [String] key
2727+
# @param [String, Array<String>] member one member or array of members
2728+
# @return [Array<String, nil>] returns array containg geohash string if member is present, nil otherwise
2729+
def geohash(key, member)
2730+
synchronize do |client|
2731+
client.call([:geohash, key, member])
2732+
end
2733+
end
2734+
2735+
27242736
# Query a sorted set representing a geospatial index to fetch members matching a
27252737
# given maximum distance from a point
27262738
#

test/commands_on_geo_test.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,17 @@ def test_geodist_with_nonexistant_location
7474
distination = r.geodist("Sicily", "Palermo", "Rome")
7575
assert_equal nil, distination
7676
end
77+
78+
def test_geohash
79+
geohash = r.geohash("Sicily", "Palermo")
80+
assert_equal ["sqc8b49rny0"], geohash
81+
82+
geohashes = r.geohash("Sicily", ["Palermo", "Catania"])
83+
assert_equal %w(sqc8b49rny0 sqdtr74hyu0), geohashes
84+
end
85+
86+
def test_geohash_with_nonexistant_location
87+
geohashes = r.geohash("Sicily", ["Palermo", "Rome"])
88+
assert_equal ["sqc8b49rny0", nil], geohashes
89+
end
7790
end

0 commit comments

Comments
 (0)