Redis

Redis (Remote Dictionary Server) is in-memory key-value database.

Mac install

brew install redis

Start

redis-server

Testing

redis-cli ping

Should return PONG.

Using cli

redis-cli
set car Lexus
get car

Saving database

save

Closing

shutdown

Python

import redis
r.set('moto', 'suzuki')
r.get('moto')
pipe = r.pipeline()
pipe.set('country', 'Poland')
pipe.set('city', 'Barcelona')
pipe.get('car')
pipe.execute()

Counter

r.set("price", 1)
r.incr("price")
r.get("price")

Docker

docker run --detach --publish=6379:6379 --name=redis redis

Then you can connect from your mac using redis-cli.

redis-cli
set car Toyota

You can also run cli in docker:

docker exec -it redis ]redis-cli
get car

Updated: 2019-12-21