Irresponsibly Short Redis Cluster Intro
Redis Cluster has been real soon now for the past three years, but this time, real soon is actually happening.
Let's Cluster Redis
This page shows you how to set up a 24 instance Redis Cluster (or 64 or 96 or 128+ instance cluster) with two easily repeatable commands.
(Note: you'll need tmux, ruby, and the redis gem installed for this to work. If you're an OS X citizen, you can try: brew install tmux; sudo gem install redis)
You need two terminals for this hotness.
First, let's start 24
redis-server processes. Copy and paste the block below to: download the
unstable redis branch, compile it, download a helper utility, start 24 Redis servers in cluster mode.
mkdir -p ~/repos pushd ~/repos git clone https://github.com/antirez/redis git clone https://github.com/mattsta/redis-cluster-playground pushd redis time make -j4 popd pushd redis-cluster-playground ./play.sh nodes 24
You now have 24
redis-server processes running in Terminal A. (Protip: You can quit them by
Ctrl-C'ing your way through all open sessions until
redis-server processes aren't a cluster yet.
Let's tell the servers about each other by creating a cluster of 24 instances with two copies of all data.Run this in Terminal B:
pushd ~/repos/redis-cluster-playground ./play.sh create-with-replicas 24 2 yes ./play.sh check 7001
You now have a working 24 instance Redis Cluster on your machine. Run
redis-cli -p [PORT] to connect to one of your 24 Redis Cluster instances (use ports between 7000 and 7023 to connect to different instances). Now run your favorite Redis commands against your connected instance to see how things respond in a connected cluster.
What's All This Then?
Your shiny, new-car-smell 24 instance Redis Cluster has 8 masters with 2 dedicated replicas for each master (8 masters + 8 masters * 2 replicas = 24 total instances).
Redis Cluster is designed to run multiple instances per host. Using IP addresses of instances, the Redis Cluster creation helper assigns replicas to different hosts than their paired masters (see
redis/src/redis-trib.rb). In this case of running everything on one host, the helper gives up and assigns replicas and their matching masters to the same host. This practice is not advised for production setups.
Instances are light, fluffy things
At first glance, your cluster may look poorly configured. After all, you've got 24 instances, but only 8 are masters recieving writes? Is having 16 instances dedicated to being replicas a waste?
Not at all. You have to get away from thinking about a Redis Cluster instance as a heavyweight infrastructure. Redis Cluster instances are effecient, light processes designed to co-exist with
2 x $CORE_COUNT instances on the same machine.
You can almost (almost) think of a Redis Cluster instance as vnodes. You run multiple vnodes on one host, and they can be relocated to other hosts as necessary (Note: no relocating happens in Redis Cluster yet—the only automated recovery is promotion of a replica node to a new master node).
Great, so you have a cluster. What can you do with it? Well, you use it to write, read, publish, and subscribe. Redis Cluster does most of what standalone Redis does. You can play with Redis Cluster using
redis-cli directly. If you use a Redis library in your code, it needs to be cluster aware to get any useful work done.
I often use the words "node" and "instance" interchangeably, but in an attempt to not confuse you, I'm only using "instance" here so you don't think each
redis-server process requires its own machine.
Current Operational Friction
Things to watch out for:
- Redis Cluster is currently pre-beta with beta coming very soon (less than two months out).
- The management interfaces and automatic-ness of tools aren't solidified yet.
- Your favorite Redis clients may not be cluster-aware yet, rendering your fancy cluster not very useful.
What Did I Just Read?
This page is an alternative
README to my Redis Cluster Playground. If you want more Redis Cluster autoconfiguring goodness, go read its