Redis Getting Started, CRUD

For Mac, CLI and JSON type data users

Allen Kim
2 min readSep 15, 2022

Install Docker on Mac

Install Docker Desktop on Mac | Docker Documentation

~$ # Check if it's properly installed
~$ docker --version

Docker version 20.xx.xx, build xxx~$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete
Digest: .....
Status: Downloaded newer image for hello-world:latestHello from Docker!
This message shows that your installation appears to be working correctly
....

Install Redis CLI locally

$ brew install redis

Run RedisJSON Docker image locally

$ docker run -d -p 6379:6379 redislabs/rejson:preview

Run redis-cli to perform CRUD; create, read, update, delete

$ redis-cli
127.0.0.1:6379> json.set foo . '{"hello":"world"}'
OK
127.0.0.1:6379> json.get foo
"{\"hello\":\"world\"}

Create with JSON.SET

JSON.SET | Redis
JSON.SET key path value [NX | XX]

NX - only set the key if it does not already exist
XX - only set the key if it already exists

127.0.0.1:6379> JSON.SET doc $ '{"a":2}'
OK

Read with JSON.GET

JSON.GET | Redis
JSON.GET key [INDENT i] [NEWLINE n] [SPACE s][paths[paths...]]

$ redis-cli --raw
127.0.0.1:6379> JSON.GET doc INDENT " " NEWLINE "\n" SPACE " "
{
"a": 2
}

Update with JSON.SET

JSON.SET | Redis
JSON.SET key path value [NX | XX]

127.0.0.1:6379> JSON.SET doc $.b '8'
OK
127.0.0.1:6379> JSON.GET doc $
"[{\"a\":2,\"b\":8}]"

Update with JSON.DEL

JSON.DEL | Redis
JSON.DEL key path

127.0.0.1:6379> JSON.DEL doc $
1
127.0.0.1:6379> JSON.GET doc

To know more about searching, read Indexing, Querying, and Full-Text Search of JSON Documents with Redis | Redis

Happy Learning,

Allen Kim

References

--

--