Skip to content

Instantly share code, notes, and snippets.

@x-yuri
Created May 4, 2024 15:44
Show Gist options
  • Save x-yuri/6dd1bd9e6c910af63ec51bbe07cdc708 to your computer and use it in GitHub Desktop.
Save x-yuri/6dd1bd9e6c910af63ec51bbe07cdc708 to your computer and use it in GitHub Desktop.
redis replication

redis replication

docker-compose.yml:

services:
  master:
    image: redis:5.0.14-alpine3.16
    command: redis-server /etc/redis.conf
    volumes:
      - ./redis-master.conf:/etc/redis.conf

  replica:
    image: redis:7.2.4-alpine3.19
    command: redis-server /etc/redis.conf
    volumes:
      - ./redis-replica.conf:/etc/redis.conf
$ curl -sS https://raw.githubusercontent.com/redis/redis/5.0/redis.conf -o redis-master.conf
$ curl -sS https://raw.githubusercontent.com/redis/redis/7.2/redis.conf -o redis-replica.conf
--- redis-master.conf	2024-05-04 18:39:38.648311660 +0300
+++ redis-master.conf	2024-05-04 18:36:38.060016286 +0300
@@ -66,7 +66,7 @@
 # IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
 # JUST COMMENT THE FOLLOWING LINE.
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-bind 127.0.0.1
+bind 0.0.0.0
 
 # Protected mode is a layer of security protection, in order to avoid that
 # Redis instances left open on the internet are accessed and exploited.
--- redis-replica.conf	2024-05-04 18:39:41.725004406 +0300
+++ redis-replica.conf	2024-05-04 18:35:13.172558188 +0300
@@ -530,7 +530,7 @@
 #    network partition replicas automatically try to reconnect to masters
 #    and resynchronize with them.
 #
-# replicaof <masterip> <masterport>
+replicaof master 6379
 
 # If the master is password protected (using the "requirepass" configuration
 # directive below) it is possible to tell the replica to authenticate before
$ docker compose up
$ docker compose exec master redis-cli set a b
OK
$ docker compose exec replica redis-cli get a
"b"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment