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 8ec8e8f5 Fix GEORADIUSBYMEMBER STORE should return the elements number 
(#1749)
8ec8e8f5 is described below

commit 8ec8e8f51bcca1c09c7fda9f72985e5543d373e1
Author: Binbin <[email protected]>
AuthorDate: Mon Sep 11 13:29:34 2023 +0800

    Fix GEORADIUSBYMEMBER STORE should return the elements number (#1749)
    
    When using the STORE variant, we should return the number of
    elements in the resulting set.
    
    ```
    127.0.0.1:6666> geoadd src 13 14 Shenzhen 25 30 Guangzhou
    (integer) 2
    127.0.0.1:6666> georadiusbymember src Shenzhen 5000 km store dst
    1) "Shenzhen"
    2) "Guangzhou"
    
    127.0.0.1:6379> geoadd src 13 14 Shenzhen 25 30 Guangzhou
    (integer) 2
    127.0.0.1:6379> georadiusbymember src Shenzhen 5000 km store dst
    (integer) 2
    ```
---
 src/commands/cmd_geo.cc           |  7 ++++++-
 tests/gocase/unit/geo/geo_test.go | 13 +++++++++++--
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/src/commands/cmd_geo.cc b/src/commands/cmd_geo.cc
index 5f3cfa67..353b2947 100644
--- a/src/commands/cmd_geo.cc
+++ b/src/commands/cmd_geo.cc
@@ -641,7 +641,12 @@ class CommandGeoRadiusByMember : public CommandGeoRadius {
       return {Status::RedisExecErr, s.ToString()};
     }
 
-    *output = GenerateOutput(geo_points);
+    if (store_key_.size() != 0) {
+      *output = redis::Integer(geo_points.size());
+    } else {
+      *output = GenerateOutput(geo_points);
+    }
+
     return Status::OK();
   }
 };
diff --git a/tests/gocase/unit/geo/geo_test.go 
b/tests/gocase/unit/geo/geo_test.go
index 6184846c..0db2a811 100644
--- a/tests/gocase/unit/geo/geo_test.go
+++ b/tests/gocase/unit/geo/geo_test.go
@@ -140,6 +140,15 @@ func TestGeo(t *testing.T) {
                require.EqualValues(t, 
[]redis.GeoLocation([]redis.GeoLocation{{Name: "wtc one", Longitude: 0, 
Latitude: 0, Dist: 0, GeoHash: 0}, {Name: "union square", Longitude: 0, 
Latitude: 0, Dist: 0, GeoHash: 0}, {Name: "central park n/q/r", Longitude: 0, 
Latitude: 0, Dist: 0, GeoHash: 0}, {Name: "4545", Longitude: 0, Latitude: 0, 
Dist: 0, GeoHash: 0}, {Name: "lic market", Longitude: 0, Latitude: 0, Dist: 0, 
GeoHash: 0}}), rdb.GeoRadiusByMember(ctx, "nyc", "wtc one", 
&redis.GeoRadiusQuery{Radius: [...]
        })
 
+       t.Run("GEORADIUSBYMEMBER store option", func(t *testing.T) {
+               require.NoError(t, rdb.Do(ctx, "DEL", "src", "dst").Err())
+
+               require.EqualValues(t, 2, rdb.Do(ctx, "GEOADD", "src", "13", 
"14", "Shenzhen", "25", "30", "Guangzhou").Val())
+               require.EqualValues(t, 2, rdb.Do(ctx, "GEORADIUSBYMEMBER", 
"src", "Shenzhen", "5000", "km", "store", "dst").Val())
+               require.EqualValues(t, []interface{}([]interface{}{"Shenzhen", 
"Guangzhou"}), rdb.Do(ctx, "GEORADIUSBYMEMBER", "src", "Shenzhen", "5000", 
"km").Val())
+               require.EqualValues(t, []interface{}([]interface{}{"Shenzhen", 
"Guangzhou"}), rdb.Do(ctx, "ZRANGE", "dst", 0, -1).Val())
+       })
+
        t.Run("GEOHASH errors", func(t *testing.T) {
                require.NoError(t, rdb.Del(ctx, "points").Err())
 
@@ -152,7 +161,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.NoError(t, rdb.Del(ctx, "src").Err())
                require.EqualValues(t, []interface{}([]interface{}{}), 
rdb.Do(ctx, "GEOSEARCH", "src", "FROMMEMBER", "Shenzhen", "BYBOX", 88, 88, 
"m").Val())
        })
 
@@ -216,7 +225,7 @@ func TestGeo(t *testing.T) {
        })
 
        t.Run("GEOSEARCHSTORE against non existing src key", func(t *testing.T) 
{
-               require.NoError(t, rdb.Del(ctx, "points").Err())
+               require.NoError(t, rdb.Del(ctx, "src").Err())
                require.EqualValues(t, 0, rdb.Do(ctx, "GEOSEARCHSTORE", "dst", 
"src", "FROMMEMBER", "Shenzhen", "BYBOX", 88, 88, "m").Val())
        })
 

Reply via email to