This is an automated email from the ASF dual-hosted git repository.

hulk pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks.git


The following commit(s) were added to refs/heads/unstable by this push:
     new 84a62899 GEO FROMMEMBER returns error when member does not exist 
(#1766)
84a62899 is described below

commit 84a628991ea3d5d135a707c0145db2d5076c6fa7
Author: Binbin <[email protected]>
AuthorDate: Mon Sep 18 22:37:29 2023 +0800

    GEO FROMMEMBER returns error when member does not exist (#1766)
    
    Redis will return a specific error if the member does not exist,
    but Kvrocks currently handles it as if the src key does not exist:
    ```
    127.0.0.1:6666> geoadd src 10 10 Shenzhen
    (integer) 1
    127.0.0.1:6666> GEOSEARCHSTORE dst src FROMMEMBER Shenzhen_2 BYBOX 88 88 m
    (integer) 0
    
    127.0.0.1:6379> GEOADD src 10 10 Shenzhen
    (integer) 1
    127.0.0.1:6379> GEOSEARCHSTORE dst src FROMMEMBER Shenzhen_2 BYBOX 88 88 m
    (error) ERR could not decode requested zset member
    ```
    
    Now we will return an error, the error message is the same
    as Redis: could not decode requested zset member
    ```
    127.0.0.1:6666> GEOSEARCHSTORE dst src FROMMEMBER Shenzhen_2 BYBOX 88 88 m
    (error) ERR Invalid argument: could not decode requested zset member
    
    127.0.0.1:6666> GEORADIUSBYMEMBER src Shenzhen_2 20 M STORE dst
    (error) ERR Invalid argument: could not decode requested zset member
    ```
---
 src/types/redis_geo.cc            |  2 +-
 tests/gocase/unit/geo/geo_test.go | 24 ++++++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/src/types/redis_geo.cc b/src/types/redis_geo.cc
index cc8173e6..37adc35d 100644
--- a/src/types/redis_geo.cc
+++ b/src/types/redis_geo.cc
@@ -188,7 +188,7 @@ rocksdb::Status Geo::Get(const Slice &user_key, const Slice 
&member, GeoPoint *g
 
   auto iter = geo_points.find(member.ToString());
   if (iter == geo_points.end()) {
-    return rocksdb::Status::NotFound();
+    return rocksdb::Status::InvalidArgument("could not decode requested zset 
member");
   }
   *geo_point = iter->second;
   return rocksdb::Status::OK();
diff --git a/tests/gocase/unit/geo/geo_test.go 
b/tests/gocase/unit/geo/geo_test.go
index fe7bb199..6db8c222 100644
--- a/tests/gocase/unit/geo/geo_test.go
+++ b/tests/gocase/unit/geo/geo_test.go
@@ -136,6 +136,18 @@ func TestGeo(t *testing.T) {
                require.EqualValues(t, []interface{}([]interface{}{}), 
rdb.Do(ctx, "GEORADIUSBYMEMBER_RO", "points", "member", "1", "km").Val())
        })
 
+       t.Run("GEORADIUSBYMEMBER against non existing member", func(t 
*testing.T) {
+               require.NoError(t, rdb.Do(ctx, "DEL", "src", "dst").Err())
+
+               require.NoError(t, rdb.Do(ctx, "GEOADD", "src", "10", "10", 
"Shenzhen").Err())
+               require.Error(t, rdb.Do(ctx, "GEORADIUSBYMEMBER", "src", 
"Shenzhen_2", 20, "M").Err())
+
+               require.NoError(t, rdb.Do(ctx, "GEOADD", "dst", "20", "20", 
"Guangzhou").Err())
+               require.Error(t, rdb.Do(ctx, "GEORADIUSBYMEMBER", "src", 
"Shenzhen_2", 20, "M", "STORE", "dst").Err())
+               // Verify command does not affect dst
+               require.EqualValues(t, 1, rdb.Exists(ctx, "dst").Val())
+       })
+
        t.Run("GEORADIUSBYMEMBER store: remove the dst key when there is no 
result set", func(t *testing.T) {
                require.NoError(t, rdb.Do(ctx, "DEL", "src", "dst").Err())
 
@@ -244,6 +256,18 @@ func TestGeo(t *testing.T) {
                require.EqualValues(t, 0, rdb.Do(ctx, "GEOSEARCHSTORE", "dst", 
"src", "FROMMEMBER", "Shenzhen", "BYBOX", 88, 88, "m").Val())
        })
 
+       t.Run("GEOSEARCH / GEOSEARCHSTORE FROMMEMBER against non existing 
member", func(t *testing.T) {
+               require.NoError(t, rdb.Do(ctx, "DEL", "src", "dst").Err())
+
+               require.NoError(t, rdb.Do(ctx, "GEOADD", "src", "10", "10", 
"Shenzhen").Err())
+               require.Error(t, rdb.Do(ctx, "GEOSEARCH", "src", "FROMMEMBER", 
"Shenzhen_2", "BYBOX", 88, 88, "M").Err())
+
+               require.NoError(t, rdb.Do(ctx, "GEOADD", "dst", "20", "20", 
"Guangzhou").Err())
+               require.Error(t, rdb.Do(ctx, "GEOSEARCHSTORE", "dst", "src", 
"FROMMEMBER", "Shenzhen_2", "BYBOX", 88, 88, "M").Err())
+               // Verify command does not affect dst
+               require.EqualValues(t, 1, rdb.Exists(ctx, "dst").Val())
+       })
+
        t.Run("GEOSEARCHSTORE remove the dst key when there is no result set", 
func(t *testing.T) {
                require.NoError(t, rdb.Do(ctx, "del", "src", "dst").Err())
 

Reply via email to