Skip to content

Instantly share code, notes, and snippets.

@byjg
Last active February 26, 2023 15:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save byjg/23c15091b6bc9bf8d9744da551abf209 to your computer and use it in GitHub Desktop.
Save byjg/23c15091b6bc9bf8d9744da551abf209 to your computer and use it in GitHub Desktop.
Redis Replication with Docker
docker network create test
cat << EOF > master.conf
bind 0.0.0.0
appendonly yes
appendfilename "appendonly.aof"
EOF
docker run -it --rm -v $PWD/master.conf:/etc/master.conf --name master --network test -d redis:6.2 redis-server /etc/master.conf
cat << EOF > slave.conf
bind 0.0.0.0
slaveof master 6379
EOF
docker run -it --rm -v $PWD/slave.conf:/etc/slave.conf --name slave --network test -d redis:6.2 redis-server /etc/slave.conf

Connect to master

docker exec -it master redis-cli

run:

info

The result should be something like:

# Replication
role:master
connected_slaves:1

add some keys:

SET test value
GET test

Connect to Slave

docker exec -it slave redis-cli

run:

info

The result should be something like:

# Replication
role:slave
master_host:master
master_port:6379
master_link_status:up

Try to retrieve the key from master:

GET test

Promate slave to master:

slaveof no one

Back to slave:

slaveof master 6379

Disabliing replication without restart

slaveof no one

Enabling replication without restart

slaveof master 6379

Master has requirepass

add to config:

masterpass <MASTERPASSORD>

Timeout receiving bulk data from MASTER

CONFIG SET repl-timeout <higher value in seconds> 

Big DB Replication fail and always restart full sync

On Master:

CONFIG SET client-output-buffer-limit "slave 103079215104 68719476736 60"
CONFIG SET repl-backlog-size 1gb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment