Learn more about Russian war crimes in Ukraine.

Does Redis Pub/Sub work with master-slave replication?

In short: yes! To see this, start two Redis servers in master-slave configuration, then subscribe to channel foo on the slave:

$ redis-server --port 6379 &
$ redis-server --port 6380 --slaveof 127.0.0.1 6379 &
$ redis-cli -p 6380 subscribe foo
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "foo"

Now publish something to foo on the master:

$ redis-cli -p 6379 publish foo bar

You’ll find that this message does arrive at the client subscribed on the slave:

...
1) "message"
2) "foo"
3) "bar"

All publish commands are replicated to the slave. You can see this by first sending the sync command to the Redis master using redis-cli, which then becomes a Redis slave and prints all replicated commands:

$ redis-cli -p 6379 sync
Entering slave output mode...  (press Ctrl-C to quit)
SYNC with master, discarding 76 bytes of bulk transfer...
SYNC done. Logging commands from master.
"publish","foo","bar"

What can computers do? What are the limits of mathematics? And just how busy can a busy beaver be? This year, I’m writing Busy Beavers, a unique interactive book on computability theory. You and I will take a practical and modern approach to answering these questions — or at least learning why some questions are unanswerable!

It’s only $19, and you can get 50% off if you find the discount code ... Not quite. Hackers use the console!

After months of secret toil, I and Andrew Carr released Everyday Data Science, a unique interactive online course! You’ll make the perfect glass of lemonade using Thompson sampling. You’ll lose weight with differential equations. And you might just qualify for the Olympics with a bit of statistics!

It’s $29, but you can get 50% off if you find the discount code ... Not quite. Hackers use the console!

More by Jim

Tagged #programming, #redis. All content copyright James Fisher 2019. This post is not associated with my employer. Found an error? Edit this page.