How to use RedisJSON
Installation
It’s a plugin, thus you should install it first.
To install it, it’s necessary to build it from the source code
git clone https://github.com/RedisJSON/RedisJSON.git
cd RedisJSON
# be shure tha Rust is installed
cargo build --release
Run
Linux
redis-server --loadmodule ./target/release/librejson.so
MacOS
redis-server --loadmodule ./target/release/librejson.dylib
Commands and Examples
Insert
json.set vendor:97 . "{\\"name\\": \\"Peter's Burito\\", \\"phone\\": \\"123-456-789\\", \\"currently_open\\": true, \\"menu\\": [{\\"name\\": \\"Chipotle\\", \\"price\\": \\"22.3\\"}, {\\"name\\": \\"taco\\", \\"price\\": 3.4}, {\\"name\\": \\"nachos\\", \\"price\\": 4.4}]}"
where .
means root
Add one more key
json.set vendor:98 .location '{"street": "Elm Street","number": 23}'
Add to JSON array
json.arrappend vendor:98 .menu '{"name": "Cola","price": "1.3"}'
Remove last from JSON array
json.arrpop vendor:98 .menu[0]
Get by path
json.get vendor:98 .menu[1].price