about

writing

contact

Redis Setup Notes and One-Liners

By eric

2013-10-22

Being a heavy user of Redis has forced some weird Bash-fu and other commands when I want to find out how things are going. Because Redis is single threaded (see here for more information), I commonly run multiple Redis instances per machine. As a result, when running on AWS, I use a specific machine layout to get the best CPU utilization for Redis. On an m2.4xlarge machine, it comes with 8 cores and 68G of RAM. To take full advantage of that I run 7 instances of Redis and pin one instance to a CPU core (this can be done using taskset in schedutils package). For extra performance, I leave an entire core to the OS (even though the machines do little other than process Redis commands.

Because the machine is doing so much at once with Redis, it is a little more challenging to monitor. If I wanted to find out the stats on anything, I had to do a little scripting. Here are a few commands and scripts that I use regularly to check into the health and state of Redis.

To check the number of commands being executed per second per instance, you can use this script to get a rough idea. Just swap out the ports for the ones you use and the rest should work itself out.

If you want to check the ping time to Redis in thousandths of a second, you can use this script. Admittedly I stole this from commandlinefu.com a while back. But it’s so useful (for scripting) that I still use it from time to time.

When running multiple instances of Redis on a single machine, I try to make sure that the instances don’t “step” on each other with memory. I do this by setting a maximum amount of memory per instance. To check the current utilization over max allowed for that instance, the follow command line was used (yes these print out on different lines intentionally because that makes it easier to read).

One of the ways to keep track of what Redis instance is responsible for what keys is to use namespacing when adding keys. For instance, anything that has to do with caching has a top level namespace of cache. It is then followed by a second level of what is being cached and a third level of the specific item. Specifically the key name will look like this cache::account::12345. This way if you want to clear the cache on all Redis instances, you can use the following one liner.