Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GEOSEARCHSTORE not overwrite the dst key #1677

Merged

Conversation

enjoy-binbin
Copy link
Member

When doing store, we should call overwrite instead of add, when
doing add, which leads us to perform zadd dst xxx in disguise.
And this cause the following issues.

The first case is more common, it is a normal user case.
We always adding the member results in a incorrect zset:

127.0.0.1:6666> flushall
OK
127.0.0.1:6666> geoadd src 10 10 Shenzhen
(integer) 1
127.0.0.1:6666> geoadd src2 10 10 Beijing
(integer) 1
127.0.0.1:6666> GEOSEARCHSTORE dst src FROMMEMBER Shenzhen BYBOX 88 88 m
(integer) 1
127.0.0.1:6666> GEOSEARCHSTORE dst src2 FROMMEMBER Beijing BYBOX 88 88 m
(integer) 1
127.0.0.1:6666> zcard dst
(integer) 2
127.0.0.1:6666> zrange dst 0 -1
1) "Beijing"
2) "Shenzhen"

127.0.0.1:6379> flushall
OK
127.0.0.1:6379> geoadd src 10 10 Shenzhen
(integer) 1
127.0.0.1:6379> geoadd src2 10 10 Beijing
(integer) 1
127.0.0.1:6379> GEOSEARCHSTORE dst src FROMMEMBER Shenzhen BYBOX 88 88 m
(integer) 1
127.0.0.1:6379> GEOSEARCHSTORE dst src2 FROMMEMBER Beijing BYBOX 88 88 m
(integer) 1
127.0.0.1:6379> zcard dst
(integer) 1
127.0.0.1:6379> zrange dst 0 -1
1) "Beijing"

The second one is a dst key with the wrong type, the add will
actually return an error (wrong type error) and take no effect
and the result is not actually written:

127.0.0.1:6666> flushall
OK
127.0.0.1:6666> geoadd src 10 10 Shenzhen
(integer) 1
127.0.0.1:6666> set dst string
OK
127.0.0.1:6666> GEOSEARCHSTORE dst src FROMMEMBER Shenzhen BYBOX 88 88 m
(integer) 1
127.0.0.1:6666> type dst
string

127.0.0.1:6379> flushall
OK
127.0.0.1:6379> geoadd src 10 10 Shenzhen
(integer) 1
127.0.0.1:6379> set dst string
OK
127.0.0.1:6379> GEOSEARCHSTORE dst src FROMMEMBER Shenzhen BYBOX 88 88 m
(integer) 1
127.0.0.1:6379> type dst
zset

Copy link
Contributor

@torwig torwig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@enjoy-binbin enjoy-binbin merged commit 5efb8d3 into apache:unstable Aug 16, 2023
26 checks passed
@enjoy-binbin enjoy-binbin deleted the fix_geosearch_store_overwrite branch August 16, 2023 02:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants