英文:
How to get only specific properties for multiple keys with RedisJson MGET?
问题
我想要从数据库中获取多个 RedisJson 对象的特定属性。
例如,创建了2个 RedisJson 对象:
JSON.SET Cat:1 . '{ "name": "Mitzi", "color": "pink", "age": 1 }'
JSON.SET Cat:2 . '{ "name": "Lucky", "color": "black", "age": 13 }'
我们只对获取属性 "name" 和 "color" 感兴趣。
对于单个对象,可以这样工作:
JSON.GET Cat:1 .name .color
返回:
"{".name":"Mitzi",".color":"pink"}"
然而,对于多个对象,使用 MGET。
JSON.MGET Cat:1 Cat:2 .name .color
这显然不起作用,还没有找到如何指定属性作为命令参数。
英文:
I would like to get only specific properties of multiple RedisJson objects stored in the DB.
For example, 2 RedisJson were created:
JSON.SET Cat:1 . '{"name":"Mitzi", "color":"pink", "age":1}'
JSON.SET Cat:2 . '{"name":"Lucky", "color":"black", "age":13}'
We are interested to get only properties "name" and "color"
For a single object this would work:
JSON.GET Cat:1 .name .color
returns:
"{\".name\":\"Mitzi\",\".color\":\"pink\"}"
However, for multiple objects using MGET.
JSON.MGET Cat:1 Cat:2 .name .color
This obviously doesn't work, didn't figure out how to specify the properties as command arguments.
答案1
得分: 3
JSON.MGET Cat:1 Cat:2 '$["name","color"]'
["Mitzi","pink"]
["Lucky","black"]
英文:
redis> JSON.MGET Cat:1 Cat:2 '$["name","color"]'
["Mitzi","pink"]
["Lucky","black"]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论