Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Setting up Redis on OSX and CentOS (UNIX sockets)

Redis Setup

OSX + Homebrew

Conf files

Make a copy of redis.conf as redis-common.conf:

cp /usr/local/etc/redis{,-common}.conf

Use UNIX sockets instead of TCP. Edit redis-common.conf and change to port 0:

port 0

Create as many conf files as necessary for additional redis instances:

nano /usr/local/etc/redis-1.conf

Include these lines in conf files, changing numbers as necessary:

include /usr/local/etc/redis-common.conf
pidfile /usr/local/var/run/
unixsocket /tmp/redis-1.sock
dbfilename dump-1.rdb


Make a copy of redis.plist:

cp ~/Library/LaunchAgents/homebrew.mxcl.redis.plist ~/Library/LaunchAgents/custom1.redis.plist

Update its contents:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">

Rinse and repeat for subsequent redis-* conf files you have.

Start, stop

Now load these Launchd files:

launchctl load -w ~/Library/LaunchAgents/custom*.redis.plist

You should have a bunch of redis-*.sock files created in /tmp:

ls /tmp

Use redis-cli to check status of each of your instances:

redis-cli -s /tmp/redis-1.sock

If you messed up somewhere, you might need to launchctl unload your .plist file.


Shorter way

Also take note of SELinux; make sure to set to permissive otherwise unix sockets won't work

In redis.conf:

# 0 = do not listen on a port
port 0

# listen on localhost only

# create a unix domain socket to listen on
unixsocket /tmp/redis.sock

# set permissions for the socket
unixsocketperm 755

In your Node.js app:

var redis = require('redis');

var redisClient = redis.createClient('/tmp/redis.sock');


Longer way

Make a copy of redis.conf:

cp /etc/redis.conf /usr/local/etc/redis-common.conf

Give ownership of file to Redis and change permissions:

chown redis:redis /usr/local/etc/redis-common.conf
chmod 770 /usr/local/etc/redis-common.conf

Use unix sockets instead of TCP. Edit redis-common.conf and change to port 0:

port 0

Create additional conf files as necessary for additional instances:

nano /usr/local/etc/redis-1.conf

Add these lines and make necessary adjustments:

include /usr/local/etc/redis-common.conf
pidfile /var/run/
unixsocket /tmp/redis-1.sock
unixsocketperm 777
dbfilename dump-1.rdb


Make a copy of redis.service as a systemd template file. Take note of the @!

sudo cp /etc/systemd/system/ /etc/systemd/system/custom-redis@.service


  • We're putting it in /usr/local/ because it's for personal use. /etc is system default for OS confi files.
  • We're using a systemd template file because we only want to use one .service file to start multiple instances.

Edit your new service file. Take note of %i:

Description=Custom Redis Template

ExecStart=/usr/bin/redis-server /usr/local/etc/redis-%i.conf --supervised systemd


With a template file named as template@.service, you can use parameters in [Service] when launching it. Launch with systemctl:

sudo systemctl start /etc/systemd/system/custom-redis@1.service

Your parameters that come after @ will be used within the template service file as %i.

Check status:

sudo systemctl status custom-redis@1.service -l

Sock file should exist in /tmp:

ls /tmp

Once everything's running okay, enable start on boot:

sudo systemctl start custom-redis@1.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.