ZhangZhihui's Blog  

 

127.0.0.1:6379> JSON.GET store $..headphones[?(@price<70&&@wireless==true)]
[{"id":12346,"name":"Wireless earbuds","description":"Wireless Bluetooth in-ear headphones","wireless":true,"connection":"Bluetooth","price":64.99,"stock":17,"free-shipping":false,"colors":["black","white"]}]

 

127.0.0.1:6379> JSON.GET store $.inventory.*[?(@.connection=="Bluetooth")].name
Invalid argument(s)
127.0.0.1:6379> JSON.GET store '$.inventory.*[?(@.connection=="Bluetooth")].name'
["Noise-cancelling Bluetooth headphones","Wireless earbuds","Wireless keyboard"]

 

This example, starting with version v2.4.2, filters only keyboards with some sort of USB connection using regex match. Notice this match is case-insensitive thanks to the prefix (?i) in the regular expression pattern "(?i)usb":

127.0.0.1:6379> JSON.GET store '$.inventory.keyboards[?(@.connection =~ "(?i)usb")]'
[{"id":22346,"name":"USB-C keyboard","description":"Wired USB-C keyboard","wireless":false,"connection":"USB-C","price":29.99,"stock":30,"free-shipping":false}]

 

posted on 2024-01-12 14:13  ZhangZhihuiAAA  阅读(18)  评论(0)    收藏  举报