Install Redis: Speed that scales is only a few keystrokes away

Redis Installation on Ubuntu:

> sudo apt-get update

> sudo apt-get install php-redis

> sudo apt-get install redis-server

Important Redis Concepts

Redis is an extremely fast In-Memory Cache.

Redis stores data as key value pairs

Redis caches data with a least recently used eviction policy to utilize available RAM for the most frequently accessed objects.

Every Chakra7 System uses 2 Redis Instances: one for the production version and the other for the development version.

Multiple Instances Per Server

A server can have multiple Redis instances listening on different ports. The developer should always configure the server to start all instances on startup.

Read More

Multiple Databases Per Instance

Each Redis instance can have multiple databases. Databases are not titled with strings but are named and referenced with the integers 0-16. If more databases are needed, the number of databases is a config setting in the redis.conf file for the Redis instance

Read More

We recommend using a separate Redis Instance for every System

Chakra7 provides a lot of flexibility as to how you segment your Redis resources for your different projects. You can either use different Redis databases within the same Redis instance or have entirely different Redis instances for each system.

We recommend having distinct, separate Redis instances for each Chakra7 system version. This means each project has one development Redis instance and one production Redis instance.

Configuring Redis Instances

Test Drive:

In SSH terminal #1 run the Redis server daemon, redis-server:

> redis-server

In SSH terminal #2 run the Redis command line client program, redis-cli, and try out a few Redis commands:

> redis-cli

> get myKey

> (nil)

> set myKey thisIsATest

> OK

> get myKey

> “thisIsATest”

Creating a New Redis Instance:

Let’s create a new Redis Instance that will listen on port 6380. As you add more instances, you need to continue to change the port to a new available number (6381, 6382, 6383, ...).

To create a new Redis instance, we need to create a new config file and add the instance startup to the operating system init routine.

Create and Edit A New Redis Config File:

> sudo cp /etc/redis/redis.conf /etc/redis/redis_6380.conf

> sudo nano /etc/redis/redis_6380.conf

Change the following lines:

port 6380

dir /var/lib/redis/6380

Create the Directory:

> sudo mkdir /var/lib/redis/6380

> sudo chmod 0777 /var/lib/redis/6380

Auto Start Your Instance on Boot Up:

Redis installs a startup script(/etc/init.d/redis-server) to run the default Redis config file (/etc/redis/redis.conf) which creates a Redis instance listening on port 6379. The init.d startup script ensures that our instance will always restart when the server boots up.

When we add a new instance, we want the same start up behavior at boot time. To do this we copy the default Redis init.d script, change the appropriate config values, and run the updaterc.d command to install the server startup script.

Create and Edit New Startup init.d Script Using Redis Default as Template:

> sudo cp /etc/init.d/redis-server /etc/init.d/redis-server-6380

> sudo nano /etc/init.d/redis-server-6380

Make the following changes:

Create a /var/rub/redis_6380 folder to correspond with the RUNDIR config directive

> sudo mkdir /var/run/redis_6380

> sudo chmod 0777 /var/run/redis_6380

Install the Startup Script:

> sudo update-rc.d redis-server-6380 defaults

We’re all done! Reboot server and make sure the following commands connect to the various instances:

> redis-cli -p 6379

> redis-cli -p 6380