Skip to content

Commit

Permalink
Fix GEORADIUSBYMEMBER STORE should return the elements number
Browse files Browse the repository at this point in the history
  • Loading branch information
enjoy-binbin committed Sep 9, 2023
1 parent 166f9a7 commit 2e13291
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/commands/cmd_geo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
};
Expand Down
13 changes: 11 additions & 2 deletions tests/gocase/unit/geo/geo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: 7, Unit: "km"}).Val())
})

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())

Expand All @@ -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())
})

Expand Down Expand Up @@ -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())
})

Expand Down

0 comments on commit 2e13291

Please sign in to comment.