Skip to content

Instantly share code, notes, and snippets.

@josephdicdican
Last active February 9, 2017 09:18
Show Gist options
  • Save josephdicdican/224d4c7258a8255234cff2d839eb283b to your computer and use it in GitHub Desktop.
Save josephdicdican/224d4c7258a8255234cff2d839eb283b to your computer and use it in GitHub Desktop.
Redis Setup Unix

Redis Setup (unix)

Download and install redis

wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
make

Essentials

  • redis-server - Redis Server
  • redis-cli - command line interface utility to talk with Redis

Make install

sudo make install

To execute or call redis-server/redis-cli without specifying full path.

Starting Redis

$ redis-server
[28550] 01 Aug 19:29:28 # Warning: no config file specified, using the default config. In order to specify a config file use 'redis-server /path/to/redis.conf'
[28550] 01 Aug 19:29:28 * Server started, Redis version 2.2.12
[28550] 01 Aug 19:29:28 * The server is now ready to accept connections on port 6379
... more logs ...

Check Redis if working

$ redis-cli ping
PONG

And its all done. Find out more at Official Redis Guide.

Setting up Redis on upstart

Add user redis

sudo useradd -s /bin/false -d /var/lib/redis -M redis

Create Redis pid file directory

sudo mkdir /var/run/redis/ -p && sudo chown redis:redis /var/run/redis

Create Redis config directory

sudo mkdir /etc/redis && sudo chown redis:redis /etc/redis -Rf

Create Redis logs directory

sudo mkdir /var/log/redis/ -p && sudo chown redis:redis /var/log/redis/ -Rf

Create Redis config and put it to /etc/redis/redis.conf

sudo mkdir /etc/redis
sudo cp redis.conf /etc/redis/redis.conf
sudo chown redis:redis /etc/redis/redis.conf

Change parameters in config with preferred text editor.

sudo vi /etc/redis/redis.conf

Add this minimum configuration example:

daemonize no
#where to put pid file
pidfile /var/run/redis/redis.pid
#loglevel and path to log file
loglevel warning
logfile /var/log/redis/redis.log
#set port to listen for incoming connections, by default 6379
port 6379
#set IP on which daemon will be listening for incoming connections
bind 127.0.0.1
#where to dump database
dir /var/lib/redis

Create Upstart file for Redis

sudo touch /etc/init/redis.conf

Put text below to /etc/init/redis.conf file

#!upstart
description "redis server"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
respawn limit 10 5
exec sudo -u redis /usr/local/bin/redis-server /etc/redis/redis.conf

Start server

sudo service redis start

Add Redis to system startup

sudo update-rc.d redis defaults

Done. Find Redis formal setup in this link.

@josephdicdican
Copy link
Author

5. Configure Redis connection and default queue driver for laravel queueing

a. In app/config/database.php, change the default settings to the correct host. For port leave it as ease.

'redis' => array(
  'cluster' => true,
  'default' => array('host' => '127.0.0.1', 'port' => 6379), // change host if needed (or in prod)
),

b. Also in app/config/queue.php, change default to redis. This will let redis manage all the queueing.
Previous queueing were setup manually with cronjob, so no need to bother.

'default' => 'redis',

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment