Redis

Using Redis

Reminders... # Run redis server docker run --name some-redis -d redis redis-server --appendonly yes # single server # Run another redis container executing redis-cli in it, connecting our first container docker run -it --link some-redis:redis --rm redis redis-cli -h redis -p 6379 docker stop CONTAINER_ID docker start CONTAINER_ID docker exec -it CONTAINER_ID /bin/bash # shell inside container redis-benchmark

vs

They are for very different purposes!!

Redis vs other DBS

Redis Architecture: Single Server

Redis Persistence

docker container ls # looking for some-redis docker exec -it CONTAINER_ID /bin/bash # shell inside container bash: redis-benchmark # executable (not redis command) redis-server: SAVE # redis command, then take a look at db file (or BGSAVE) bash: ls -al

RDB Pros and Cons

AOF Pros and Cons

Advice: Use both.

RDB snapshotting algorithm

fork # so takes advantage of Copy On Write parent: continues to server requests child: write RAM to tmp.rdb child: mv tmp.rdb dump.rdb child: terminates # on redis restart, load dump.rdb

AOF algorithm

write to log whenever a command modifies a key # on redis restart, run the log # How durable? Depends on how you configure fsync # fsync on each command/every second/never fsync tradeoffs

AOF rewriting

To keep AOF small, create a shorter version of the log with the same end RAM state ex: increment key 1000 times vs increment key by 100 Algorithm redis-client: BGREWRITEAOF # redis command fork rewriter job parent: continues serving requests, accumulates any new commands in RAM, not current.log child:rewrites current.log to tmp.aof child: mv tmp.aof current.aof child: tell parent "DONE" child: terminates parent: logs accumulated backlog to current.aof parent: continues as in AOF algorithm above

Redis Architecture: Replication (Data)

Healing

Link between master and slave fails

Redis Architecture: Hash Partitioning (=Sharding)

Redis Architecture: Cluster

Redis Architecture: Sentinel

References