最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

redis - Using forward slash (``) in key of a RedisJSON object on Amazon Elasticache - Stack Overflow

programmeradmin2浏览0评论

We're using AWS Elasticache for Redis with engine 7.1. It has a different behaviour than our tests running on docker image: redis/redis-stack-server:7.2.0-v14.

Best shown through an example:

AWS Elasticache

AWS:6379> del "key"
(integer) 1
AWS:6379> "JSON.SET" "key" "$" "{}" "NX"
OK
AWS:6379> "JSON.SET" "key" "$.path" "{}" "NX"
OK
AWS:6379> json.set "key" "$.path[\"0/1\"]" "{\"ID\":\"0/1\"}"
OK
AWS:6379> json.get "key"
"{\"path\":{\"0\":[null,{\"ID\":\"0/1\"}]}}"

And I can also get:

AWS:6379> json.set "key" "$.path[\"0/1+\"]" "{\"ID\":\"0/1+\"}"
OK
AWS:6379> json.get "key"
"{\"path\":{\"0\":{\"1+\":{\"ID\":\"0/1+\"}}}}"

What happens on tests (docker image: redis/redis-stack-server:7.2.0-v14):

127.0.0.1:49960> del "key"
(integer) 0
127.0.0.1:49960> "JSON.SET" "key" "$" "{}" "NX"
OK
127.0.0.1:49960> "JSON.SET" "key" "$.path" "{}" "NX"
OK
127.0.0.1:49960> json.set "key" "$.path[\"0/1\"]" "{\"ID\":\"0/1+\"}"
OK
127.0.0.1:49960> json.get "key"
"{\"path\":{\"0/1\":{\"ID\":\"0/1+\"}}}"

So what I expect to happen is the JSON path is analysed as is, and "0/1" is used as the key, just like in our tests. I tried multiple options for path "0\/1", "0\\/1", "0\\\/1", but none give the wanted result.

We're using AWS Elasticache for Redis with engine 7.1. It has a different behaviour than our tests running on docker image: redis/redis-stack-server:7.2.0-v14.

Best shown through an example:

AWS Elasticache

AWS:6379> del "key"
(integer) 1
AWS:6379> "JSON.SET" "key" "$" "{}" "NX"
OK
AWS:6379> "JSON.SET" "key" "$.path" "{}" "NX"
OK
AWS:6379> json.set "key" "$.path[\"0/1\"]" "{\"ID\":\"0/1\"}"
OK
AWS:6379> json.get "key"
"{\"path\":{\"0\":[null,{\"ID\":\"0/1\"}]}}"

And I can also get:

AWS:6379> json.set "key" "$.path[\"0/1+\"]" "{\"ID\":\"0/1+\"}"
OK
AWS:6379> json.get "key"
"{\"path\":{\"0\":{\"1+\":{\"ID\":\"0/1+\"}}}}"

What happens on tests (docker image: redis/redis-stack-server:7.2.0-v14):

127.0.0.1:49960> del "key"
(integer) 0
127.0.0.1:49960> "JSON.SET" "key" "$" "{}" "NX"
OK
127.0.0.1:49960> "JSON.SET" "key" "$.path" "{}" "NX"
OK
127.0.0.1:49960> json.set "key" "$.path[\"0/1\"]" "{\"ID\":\"0/1+\"}"
OK
127.0.0.1:49960> json.get "key"
"{\"path\":{\"0/1\":{\"ID\":\"0/1+\"}}}"

So what I expect to happen is the JSON path is analysed as is, and "0/1" is used as the key, just like in our tests. I tried multiple options for path "0\/1", "0\\/1", "0\\\/1", but none give the wanted result.

Share Improve this question edited Jan 29 at 14:15 fa44 5411 gold badge3 silver badges11 bronze badges asked Jan 29 at 10:37 MarkoMarko 7819 silver badges25 bronze badges 2
  • 1 Doesn't happen with the real RedisJson. Why use a knockoff? – Ofir Luzon Commented Jan 29 at 20:08
  • I don't think my company will change our Cloud provider for Redis based on this bug. – Marko Commented Jan 30 at 14:31
Add a comment  | 

1 Answer 1

Reset to default 0

You need to use ~1 instead of / like following:

> json.set "key" "$" "{}" "NX"
OK
> json.set "key" "$.path" "{}" "NX"
OK
> json.set "key" "$.path[\"0~11\"]" "{\"ID\":\"0/1+\"}"
OK
> json.get "key"
"{\"path\":{\"0/1\":{\"ID\":\"0/1+\"}}}"

Links:

  • JSON Pointer spec documentation:

Because the characters '~' (%x7E) and '/' (%x2F) have special
meanings in JSON Pointer, '~' needs to be encoded as '~0' and '/'
needs to be encoded as '~1' when these characters appear in a
reference token.

  • Purpose of tilde in JSON Pointer
发布评论

评论列表(0)

  1. 暂无评论