Skip to content

Commit

Permalink
Fix GEOSEARCH/GEOSEARCHSTORE FROMMEMBER against non existing src key …
Browse files Browse the repository at this point in the history
…reply (apache#1625)

The new GEOSEARCH and GEOSEARCHSTORE commands were added
in apache#1533. When typing the FROMMEMBER option against non-existing
src key, an IsNotFound error is returned and resulting in the
following inconsistency:
```
127.0.0.1:6666> GEOSEARCH src FROMMEMBER Shenzhen BYBOX 88 88 m
(error) ERR NotFound:
127.0.0.1:6666> GEOSEARCHSTORE dst src FROMMEMBER Shenzhen BYBOX 88 88 m
(error) ERR NotFound:

127.0.0.1:6379> GEOSEARCH src FROMMEMBER Shenzhen BYBOX 88 88 m
(empty array)
127.0.0.1:6379> GEOSEARCHSTORE dst src FROMMEMBER Shenzhen BYBOX 88 88 m
(integer) 0
```
  • Loading branch information
enjoy-binbin authored and p1u3o committed Aug 1, 2023
1 parent b77bee7 commit 2bcb596
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/types/redis_geo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ rocksdb::Status Geo::SearchStore(const Slice &user_key, GeoShape geo_shape, Orig
if (point_type == kMember) {
GeoPoint geo_point;
auto s = Get(user_key, member, &geo_point);
if (!s.ok()) return s;
if (!s.ok()) return s.IsNotFound() ? rocksdb::Status::OK() : s;

geo_shape.xy[0] = geo_point.longitude;
geo_shape.xy[1] = geo_point.latitude;
Expand Down
10 changes: 10 additions & 0 deletions tests/gocase/unit/geo/geo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ func TestGeo(t *testing.T) {
require.EqualValues(t, []interface{}{nil, nil, nil}, rdb.Do(ctx, "GEOHASH", "points", "a", "b", "c").Val())
})

t.Run("GEOSEARCH against non existing src key", func(t *testing.T) {
require.NoError(t, rdb.Del(ctx, "points").Err())
require.EqualValues(t, []interface{}([]interface{}{}), rdb.Do(ctx, "GEOSEARCH", "src", "FROMMEMBER", "Shenzhen", "BYBOX", 88, 88, "m").Val())
})

t.Run("GEOSEARCH simple", func(t *testing.T) {
require.NoError(t, rdb.Del(ctx, "points").Err())
require.NoError(t, rdb.GeoAdd(ctx, "points",
Expand Down Expand Up @@ -191,6 +196,11 @@ func TestGeo(t *testing.T) {
rdb.GeoSearch(ctx, "points", &redis.GeoSearchQuery{BoxWidth: 200, BoxHeight: 200, BoxUnit: "km", Member: "Washington", Sort: "DESC"}).Val())
})

t.Run("GEOSEARCHSTORE against non existing src key", func(t *testing.T) {
require.NoError(t, rdb.Del(ctx, "points").Err())
require.EqualValues(t, 0, rdb.Do(ctx, "GEOSEARCHSTORE", "dst", "src", "FROMMEMBER", "Shenzhen", "BYBOX", 88, 88, "m").Val())
})

t.Run("GEOSEARCHSTORE with BYRADIUS", func(t *testing.T) {
require.NoError(t, rdb.Del(ctx, "points").Err())
require.NoError(t, rdb.GeoAdd(ctx, "points",
Expand Down

0 comments on commit 2bcb596

Please sign in to comment.