Redis Stuff

[ Home ]

Configure Redis for Memory-Only Mode

1 Feb 2016

Redis' default is to be somewhat durable, but if you want to run Redis more like memcached, you can set up Redis to be non-durable. Ensure the following directives in your redis configuration file are set with the following values.

appendonly no
# save 900 1
# save 300 10
# save 60 10000

In other words, 1) ensure appendonly is set to no (the default anyway, but always good to check), and 2) comment out all save lines.

A Redis Sys V init script

With systemd having taken over (typing this on 4 December 2015), this is now out of date, but here for historical interest.

#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

REDIS_USER=sauto
REDIS_PORT=6379
REDIS_HOME=/usr/local/redis-2.6.9
REDIS_BIN="${REDIS_HOME}/bin"
REDIS_CONF="${REDIS_HOME}/conf/redis.conf"
REDIS_VAR="${REDIS_HOME}/var"
REDIS_SERVER="${REDIS_BIN}/redis-server"
CLI="${REDIS_BIN}/redis-cli"

PIDFILE="${REDIS_VAR}/redis.pid"

case "$1" in
    start)
        if [ -f $PIDFILE ]
        then
                echo "$PIDFILE exists, process is already running or crashed"
        else
                echo "Starting Redis server..."
                su - $REDIS_USER -c "$REDIS_SERVER $REDIS_CONF"
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                su - $REDIS_USER -c "$CLI -p $REDIS_PORT shutdown"
                while [ -x /proc/${PID} ]
                do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
    *)
        echo "Please use start or stop as first argument"
        ;;
esac