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

json.arrinsert is not atomic #1129

Open
jihuayu opened this issue Nov 3, 2023 · 1 comment
Open

json.arrinsert is not atomic #1129

jihuayu opened this issue Nov 3, 2023 · 1 comment
Labels

Comments

@jihuayu
Copy link

jihuayu commented Nov 3, 2023

The json.arrinsert is not atomic. As shown below, I used json.arrinsert to insert a number at position 1 in the JSON array. The insertion was successful for match groups 1 and 2, but it failed for match groups 3 and 4. I believe it is a bug.

I found this issue while using the Docker image redis/redis-stack:latest.

127.0.0.1:6379> json.set op $ '{"x":{"y":[1]},"p":{"y":[100,12]},"t":{"y":[]},"bb":{"y":[786]}}'
OK
127.0.0.1:6379> json.arrinsert op $..y 1 99
(error) ERR index out of bounds
127.0.0.1:6379> json.get op
"{\"x\":{\"y\":[1,99]},\"p\":{\"y\":[100,99,12]},\"t\":{\"y\":[]},\"bb\":{\"y\":[786]}}"

There are two valid scenarios in terms of logic:

  1. If any of the match groups are incorrect, all insert operations will fail.
    In my example, the correct return should be:
    "{\"x\":{\"y\":[1]},\"p\":{\"y\":[100,12]},\"t\":{\"y\":[]},\"bb\":{\"y\":[786]}}"
  2. An incorrect match group should not affect the subsequent match groups.
    In my example, the correct return should be:
    "{\"x\":{\"y\":[1,99]},\"p\":{\"y\":[100,99,12]},\"t\":{\"y\":[]},\"bb\":{\"y\":[786,99]}}"

Which logic is the one we like?

@jihuayu jihuayu changed the title json.arrinsert is not atomic json.arrinsert is not atomic Nov 3, 2023
@LiorKogan LiorKogan added the bug label Nov 3, 2023
@LiorKogan
Copy link
Member

@jihuayu - thank you for reporting this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants