The Redis replication system is failing because a replica is unable to connect to and synchronize with multiple master instances simultaneously.

This typically happens when a replica is configured to point to more than one master, a setup that Redis doesn’t natively support for standard master-slave replication. The error message you’re seeing, often ERR Master is not a master or connection refused errors, indicates that the replica is trying to establish a replication connection with something that isn’t a valid master, or more commonly, that the replica is already in a replication state with one master and cannot initiate a second, independent one.

Here are the most common causes and their fixes:

  1. Misconfiguration of replicaof or masterof directives: The most frequent culprit is an incorrect replicaof (or masterof in older Redis versions) directive in the replica’s configuration file. A replica can only replicate from one master. If you have multiple replicaof lines, or if you’re trying to set up a multi-master scenario using standard replication, it will fail.

    • Diagnosis: Check the redis.conf file of the replica instance. Look for replicaof directives.
    • Fix: Ensure there is only one replicaof <masterip> <masterport> line. If you need to replicate from multiple masters, you’ll need to set up multiple replica instances, each pointing to a different master.
      # Example redis.conf snippet on the replica
      replicaof 192.168.1.100 6379
      # NO other replicaof lines
      
    • Why it works: Redis’s replication protocol is inherently a one-to-one relationship from replica to master. The directive tells the replica which single source of truth to follow.
  2. Replica is already replicating from another master: If the replica was previously configured to replicate from a different master, it needs to be explicitly told to stop before it can start replicating from a new one.

    • Diagnosis: Connect to the replica instance using redis-cli and run REPLICAINFO. This will show you if it’s currently replicating and from whom.
    • Fix: First, stop replication from the old master. Then, configure it for the new master.
      redis-cli -p <replica_port>
      > REPLICAOF NO ONE
      > REPLICAOF <new_master_ip> <new_master_port>
      
    • Why it works: REPLICAOF NO ONE breaks the existing replication stream, allowing the instance to transition to a standalone state before establishing a new replication link.
  3. Network connectivity issues to all masters: If the replica cannot reach any of the masters it’s configured to replicate from, it will fail. This is especially relevant if you’ve specified multiple replicaof lines (even though only one will be attempted at a time, the system might try to validate them or error out on the first invalid one).

    • Diagnosis: From the replica server, try to ping or telnet to each master’s IP address and port.
      ping 192.168.1.100
      telnet 192.168.1.100 6379
      
    • Fix: Ensure firewalls (e.g., ufw, iptables, cloud security groups) are not blocking traffic on the Redis port (default 6379) between the replica and all masters. Verify network routes are correct.
    • Why it works: Redis replication relies on a stable TCP connection. If the connection cannot be established, the replication handshake fails.
  4. Authentication mismatch (if using requirepass): If your master instances require a password for replication (masterauth directive) and the replica is not configured with the correct password, the replication will fail with authentication errors.

    • Diagnosis: Check the redis.conf of the master for requirepass and the redis.conf of the replica for masterauth.
    • Fix: In the replica’s redis.conf, add or correct the masterauth directive to match the master’s password.
      # In replica's redis.conf
      masterauth <master_password>
      replicaof <master_ip> <master_port>
      
    • Why it works: Redis uses a password-based handshake during replication to authenticate the replica to the master.
  5. Master is not actually a master (or is misconfigured): The error "Master is not a master" can sometimes be literal. The instance designated as a master might itself be configured as a replica, or it might have issues preventing it from accepting replication connections.

    • Diagnosis: Connect to the intended master instance and run INFO replication. It should show role:master. If it shows role:slave, it’s configured as a replica.
    • Fix: If the intended master is a replica, reconfigure it to be a master by removing its replicaof directive or setting it to NO ONE. If it’s a master but not accepting connections, check its redis.conf for protected-mode yes and ensure bind is set appropriately, or that it’s not in a state where it’s refusing new connections.
      # On the intended master
      redis-cli
      > CONFIG SET protected-mode no
      > CONFIG SET bind 0.0.0.0 # Or specific interface IP
      > CONFIG REWRITE
      > INFO replication # Should show role:master
      
    • Why it works: Ensures the designated master is indeed functioning as a master and is accessible for replication.
  6. Redis version compatibility issues: While less common, very old versions of Redis might have subtle differences in replication handling. If you’re mixing very old and very new versions, or if you’ve upgraded masters but not replicas (or vice-versa) without proper planning, you could encounter issues.

    • Diagnosis: Check the Redis versions on all involved instances using redis-cli --version or INFO server.
    • Fix: Upgrade all Redis instances to a recent, stable version. Prioritize upgrading masters before replicas, or ensure compatibility between versions if an immediate upgrade isn’t possible.
    • Why it works: Ensures consistent behavior and bug fixes across the replication topology.

After resolving these, you might encounter a NOAUTH Authentication required error if your masters have requirepass set, but your replicas were not configured with masterauth.

Want structured learning?

Take the full Redis course →