-
Notifications
You must be signed in to change notification settings - Fork 999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for GEORADIUS #3756
base: main
Are you sure you want to change the base?
Changes from 2 commits
0f4d90d
bc2ae75
8c55ed7
586e826
8fec026
838f46f
0b29997
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1148,6 +1148,61 @@ TEST_F(ZSetFamilyTest, GeoRadiusByMember) { | |
"WITHHASH and WITHCOORDS options")); | ||
} | ||
|
||
// GEORADIUS key longitude latitude radius <m | km | ft | mi> | ||
// [WITHCOORD] [WITHDIST] [WITHHASH] [COUNT count [ANY]] [ASC | DESC] | ||
// [STORE key | STOREDIST key] | ||
|
||
TEST_F(ZSetFamilyTest, GeoRadius) { | ||
EXPECT_EQ(10, CheckedInt({"geoadd", "Europe", "13.4050", "52.5200", "Berlin", "3.7038", | ||
"40.4168", "Madrid", "9.1427", "38.7369", "Lisbon", "2.3522", | ||
"48.8566", "Paris", "16.3738", "48.2082", "Vienna", "4.8952", | ||
"52.3702", "Amsterdam", "10.7522", "59.9139", "Oslo", "23.7275", | ||
"37.9838", "Athens", "19.0402", "47.4979", "Budapest", "6.2603", | ||
"53.3498", "Dublin"})); | ||
|
||
auto resp = Run({"GEORADIUS", "invalid_key", "16.3738", "48.2082", "900", "KM"}); | ||
EXPECT_THAT(resp.GetVec().empty(), true); | ||
|
||
resp = Run({"GEORADIUS", "America", "13.4050", "52.5200", "500", "KM", "WITHCOORD", "WITHDIST"}); | ||
EXPECT_THAT(resp.GetVec().empty(), true); | ||
|
||
resp = Run({"GEORADIUS", "Europe", "130.4050", "52.5200", "10", "KM", "WITHCOORD", "WITHDIST"}); | ||
EXPECT_THAT(resp.GetVec().empty(), true); | ||
|
||
resp = Run({"GEORADIUS", "Europe", "13.4050", "52.5200", "500", "KM", "COUNT", "3", "WITHCOORD", | ||
"WITHDIST"}); | ||
EXPECT_THAT( | ||
resp, | ||
RespArray(ElementsAre( | ||
RespArray(ElementsAre("Berlin", DoubleArg(0.00017343178521311378), | ||
RespArray(ElementsAre(DoubleArg(13.4050), DoubleArg(52.5200))))), | ||
RespArray(ElementsAre("Dublin", DoubleArg(487.5619030644293), | ||
RespArray(ElementsAre(DoubleArg(6.2603), DoubleArg(53.3498)))))))); | ||
|
||
resp = Run( | ||
{"GEORADIUS", "Europe", "13.4050", "52.5200", "500", "KM", "DESC", "WITHCOORD", "WITHDIST"}); | ||
EXPECT_THAT( | ||
resp, | ||
RespArray(ElementsAre( | ||
RespArray(ElementsAre("Dublin", DoubleArg(487.5619030644293), | ||
RespArray(ElementsAre(DoubleArg(6.2603), DoubleArg(53.3498))))), | ||
RespArray(ElementsAre("Berlin", DoubleArg(0.00017343178521311378), | ||
RespArray(ElementsAre(DoubleArg(13.4050), DoubleArg(52.5200)))))))); | ||
|
||
EXPECT_EQ(2, CheckedInt({"GEORADIUS", "Europe", "3.7038", "40.4168", "700", "KM", "STORE", | ||
"store_key"})); | ||
resp = Run({"ZRANGE", "store_key", "0", "-1"}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test case failed because
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are the keys involved in this operation? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
2 keys. From key was "Europe", writing to I added some prints in Test Logs:
Trimmed Test cases:
|
||
EXPECT_THAT(resp, RespArray(ElementsAre("Madrid", "Lisbon"))); | ||
resp = Run({"ZRANGE", "store_key", "0", "-1", "WITHSCORES"}); | ||
EXPECT_THAT(resp, | ||
RespArray(ElementsAre("Madrid", "3471766229222696", "Lisbon", "3473121093062745"))); | ||
|
||
EXPECT_EQ(2, CheckedInt({"GEORADIUS", "Europe", "3.7038", "40.4168", "700", "KM", "STOREDIST", | ||
"store_dist_key"})); | ||
resp = Run({"ZRANGE", "store_dist_key", "0", "-1", "WITHSCORES"}); | ||
EXPECT_THAT(resp, RespArray(ElementsAre("Madrid", "0", "Lisbon", "502.20769462704084"))); | ||
} | ||
|
||
TEST_F(ZSetFamilyTest, RangeLimit) { | ||
auto resp = Run({"ZRANGEBYSCORE", "", "0.0", "0.0", "limit", "0"}); | ||
EXPECT_THAT(resp, ErrArg("syntax error")); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a lot of code! 🙂
Quoting Redis docs:
So they already hint that GeoRadius is just a specification of GeoSearch. Maybe we can unite them somehow? They share count, asc/desc, withcord, withdist, storedist... Not mentioning parsing lon/lat and units
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for reviewing. Updated as you suggested.