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

Using GET to get json type key will not return error. #1969

Closed
2 tasks done
jihuayu opened this issue Dec 25, 2023 · 2 comments
Closed
2 tasks done

Using GET to get json type key will not return error. #1969

jihuayu opened this issue Dec 25, 2023 · 2 comments
Labels
bug type bug

Comments

@jihuayu
Copy link
Member

jihuayu commented Dec 25, 2023

Search before asking

  • I had searched in the issues and found no similar issues.

Version

unstable

Minimal reproduce step

Using GET to get json type key will not return error.
I writed below test case.

t.Run("GET JSON type key", func(t *testing.T) {
	require.NoError(t, rdb.Do(ctx, "JSON.SET", "a", "$", ` {"x":1,"y":2} `).Err())
	require.EqualValues(t, "\x00{\"x\":1,\"y\":2}", rdb.Get(ctx, "a").Val())
})

What did you expect to see?

test failed

What did you see instead?

test Passed

Anything Else?

Maybe is this line problem.https://github.com/apache/kvrocks/blob/unstable/src/types/redis_string.cc#L86

if (metadata.Type() != kRedisString && metadata.size > 0) {
    return rocksdb::Status::InvalidArgument(kErrMsgWrongType);
  }

Why do we need to check metadata.size > 0?

Are you willing to submit a PR?

  • I'm willing to submit a PR!
@jihuayu jihuayu added the bug type bug label Dec 25, 2023
@git-hulk
Copy link
Member

git-hulk commented Dec 25, 2023

@jihuayu Good catch!

Why do we need to check metadata.size > 0?

For example, we need to regard it as a non-existing key if all subkeys are deleted in a list(same as the hash/set/zset). But some types allow the empty subkey list like stream/bloomfilter. Can refer: storage/redis_db.cc#L62

The better way is to use GetMetadata to replace the decode function in redis_string.

@jihuayu
Copy link
Member Author

jihuayu commented Jan 2, 2024

Fixed after #1971

@jihuayu jihuayu closed this as completed Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug type bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants