From 3d55213f0d6c470f6090d3974f1165adeb4de0c8 Mon Sep 17 00:00:00 2001 From: Binbin Date: Mon, 31 Jul 2023 15:56:32 +0800 Subject: [PATCH 1/3] Fix GEOSEARCH/GEOSEARCHSTORE FROMMEMBER against non existing src key reply The new GEOSEARCH and GEOSEARCHSTORE commands was added in #1533. When typing FROMMEMBER option against non-existing src key, an IsNotFound error is return 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 ``` --- src/types/redis_geo.cc | 2 +- tests/gocase/unit/geo/geo_test.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/types/redis_geo.cc b/src/types/redis_geo.cc index e7c343c5d9b..a7deafb81e5 100644 --- a/src/types/redis_geo.cc +++ b/src/types/redis_geo.cc @@ -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; diff --git a/tests/gocase/unit/geo/geo_test.go b/tests/gocase/unit/geo/geo_test.go index fb447287470..a6e099a5071 100644 --- a/tests/gocase/unit/geo/geo_test.go +++ b/tests/gocase/unit/geo/geo_test.go @@ -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", @@ -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", From db2210ba897355c12dff867f49aee2d6b228b30d Mon Sep 17 00:00:00 2001 From: Binbin Date: Mon, 31 Jul 2023 16:34:44 +0800 Subject: [PATCH 2/3] fix ci --- tests/gocase/unit/geo/geo_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/gocase/unit/geo/geo_test.go b/tests/gocase/unit/geo/geo_test.go index a6e099a5071..12501d00b82 100644 --- a/tests/gocase/unit/geo/geo_test.go +++ b/tests/gocase/unit/geo/geo_test.go @@ -141,7 +141,7 @@ func TestGeo(t *testing.T) { 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()) + 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) { From 026f8c2ac41859654bf5efc6709ca61b86f37b6c Mon Sep 17 00:00:00 2001 From: Binbin Date: Mon, 31 Jul 2023 16:41:58 +0800 Subject: [PATCH 3/3] fix ci