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 64188fedb fix(geo): delete store_key instead of user_key in 
SearchStore (#3456)
64188fedb is described below

commit 64188fedbe891aefaa6d24c4093b40c0c3f6d82a
Author: Songqing Zhang <[email protected]>
AuthorDate: Fri Apr 17 11:24:38 2026 +0800

    fix(geo): delete store_key instead of user_key in SearchStore (#3456)
    
    When GEOSEARCHSTORE yields zero results, the code incorrectly deleted
    the source key (user_key) instead of the destination key (store_key).
---
 src/types/redis_geo.cc            |  2 +-
 tests/gocase/unit/geo/geo_test.go | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/types/redis_geo.cc b/src/types/redis_geo.cc
index e9294081c..3926d4417 100644
--- a/src/types/redis_geo.cc
+++ b/src/types/redis_geo.cc
@@ -167,7 +167,7 @@ rocksdb::Status Geo::SearchStore(engine::Context &ctx, 
const Slice &user_key, Ge
     auto result_length = static_cast<int64_t>(geo_points->size());
     int64_t returned_items_count = (count == 0 || result_length < count) ? 
result_length : count;
     if (returned_items_count == 0) {
-      auto s = ZSet::Del(ctx, user_key);
+      auto s = ZSet::Del(ctx, store_key);
       if (!s.ok()) return s;
     } else {
       std::vector<MemberScore> member_scores;
diff --git a/tests/gocase/unit/geo/geo_test.go 
b/tests/gocase/unit/geo/geo_test.go
index 7113336f8..fc465d629 100644
--- a/tests/gocase/unit/geo/geo_test.go
+++ b/tests/gocase/unit/geo/geo_test.go
@@ -481,6 +481,18 @@ var testGeo = func(t *testing.T, configs 
util.KvrocksServerConfigs) {
                require.Equal(t, []string{"Beijing"}, rdb.ZRange(ctx, "dst", 0, 
-1).Val())
        })
 
+       t.Run("GEOSEARCHSTORE should not delete source key when result is 
empty", func(t *testing.T) {
+               require.NoError(t, rdb.Do(ctx, "DEL", "src", "dst").Err())
+               require.NoError(t, rdb.Do(ctx, "GEOADD", "src", "13.361389", 
"38.115556", "Palermo").Err())
+               require.NoError(t, rdb.Do(ctx, "GEOADD", "dst", "20", "20", 
"OldMember").Err())
+               // Search from src with a tiny radius that yields no results, 
storing into dst.
+               require.EqualValues(t, 0,
+                       rdb.Do(ctx, "GEOSEARCHSTORE", "dst", "src", 
"FROMLONLAT", "1", "1", "BYRADIUS", "1", "m").Val())
+               // The dst key should be removed, but the src key must still 
exist.
+               require.EqualValues(t, 0, rdb.Exists(ctx, "dst").Val())
+               require.EqualValues(t, 1, rdb.Exists(ctx, "src").Val())
+       })
+
        t.Run("GEOHASH is able to return geohash strings", func(t *testing.T) {
                require.NoError(t, rdb.Del(ctx, "points").Err())
                require.NoError(t, rdb.GeoAdd(ctx, "points", 
&redis.GeoLocation{Name: "test", Longitude: -5.6, Latitude: 42.6}).Err())

Reply via email to