Free up to 1MM monthly messages. No credit card required.
This tutorial walks you through a proof-of-concept for global, multi data center Redis replication of data using PubNub and NodeJS. We’re continuing to grow our collection of persistence adapters for PubNub using Node.JS.
Redis replication can be difficult due to TCP windowing and other Kernal tuning obstacles. In this blog post, we’ll show you one way to approach a replication model, specifically intended for low throughput and high volume. And with PubNub, you’ll get multi data center Redis replication, a globally redundent method for replicating Redis data.
Note: this is not production ready! It is supposed to provoke inspiration and conversation while we work, test and get the bugs out. Thanks so much for checking it out!
Redis replication consists of 2 phases:
The current Redis replicator can read RDB files from Redis 2.4 and earlier. We’re investigating adding support for 2.6+ soon! Even if Phase 1 isn’t working for you, it is very likely that Phase 2 will work for receiving real-time updates.
To start a Redis replication client, use this command:
This starts up the replication process. You should see something like this:
What happened? The replication client connected to your redis instance, started an RDB replication transfer, and sent all of the entities to the PubNub channel “redisrepl”.
The PING commands are harmless – they are just there because the replication client needs to stay connected to the server.
That wasn’t bad, was it? Let’s try an update!
You should see something like this:
Pretty awesome! That means that the replication client saw the update, and sent it out on the “redisrepl” channel.
To start a Redis replication listener, use this command:
This starts a listener on the given PubNub channel. You can modify the listener to do whatever you want with the data it receives (this one just logs to console).
As you perform updates, you should see messages like this:
This starts a listener on the given PubNub channel that proxies data to another Redis instance on port 6399.
As you perform updates, you should see messages like this:
If you check the redis instance on port 6399, you should see something like this:
We hope you enjoyed this example of replicating Redis data using PubNub and Node.JS. In the future, we’ll implement and review more Redis commands, and start getting this sample code a bit more production ready. If you run into any issues or have any suggestions for making this more awesome, please drop us a line!
Display real-time notification badges with PubNub and React Native to display important information and bring users back to your...
Michael Carroll
The concept of Digital Twins has evolved over the last two decades, however, one thing remains the same: the need for real-time...
Michael Carroll
Learn the ins-and-outs of PubNub message size and get a better idea of how many text characters fit in a single message.
Michael Carroll