Using Redis cache in ELMA

System requirements

  1. ELMA 3.9.22, 3.10.12, 3.11.2 or higher
  2. At least three Redis cache cluster servers with Unix OS (Linux, OSX, OpenBSD, NetBSD, FreeBSD and derived OS).

Assembling and installing a Redis package

You can download the latest version of Redis from the official website: https://redis.io/download (use the Stable version).

Generally, the 'make' command is used for assembling.

Installation guide (Ubuntu 14/16 is used as an example).

1. Install additional packages, required for assembling a Redis package. In case of Ubuntu, those are build-essentials and tcl 8.5 (or higher):

  • sudo apt-get update
  • sudo apt-get install build-essential
  • sudo apt-get install tcl8.5

2. Download the Redis package to any folder (e.g. /home/<user>). You can do it manually or with a command:

wget http://download.redis.io/releases/redis-stable.tar.gz (get a URL on the page https://redis.io/download).

3. Unzip the package (the name of the downloaded package may be different):

tar xzf redis-stable.tar.gz

4. Open the folder with the unzipped package (the name may also be different):
cd redis-stable

5. Assemble the package using the command:
make

6. Check the assembled package using the command:
make test

7. Install the package and register it for running, consequently using the commands:
make install
cd utils
./install_server.sh 
(this command is interactive; when requesting parameters you can use default values).

After running these commands, the binary files redis-cli and redis-server will be installed to /usr/local/bin. Additionally, the service with the parameters specified in install_server.sh will be registered.

8. To start the service, use the command:
sudo service redis_6379 start (the server name may be different, depending on the values, specified in the install_server.sh command; to stop the service, type 'stop' instead of 'start').
Configuring the Redis cluster

Official documentation is available here: https://redis.io/topics/cluster-tutorial 
Official documentation on configuring a high-availability solution: https://redis.io/topics/sentinel 
Unofficial (simplified cluster with one master): https://www.digitalocean.com/community/tutorials/how-to-configure-a-redis-cluster-on-ubuntu-14-04 

This guide describes how to configure the simplified variant

The first server is Master, the second and consequent are Slave.

Configuration involves editing the file /etc/redis/redis.conf on each server:

  • Make the server available for all the IP addresses of this server:

#bind 127.0.0.1 (The number sign in this file is a commented out line. In this case, it makes the Redis service available for external addresses)

  • Disable data backup copying to the disk (to ensure maximum performance). To do so:
    • comment out all the lines starting with 'save' (e.g. #save 900 1).
    • set appendonly no

To configure Master:

  • Set the parameter:

tcp-keepalive  60

  • Set the Master access password:

requirepass your_redis_password

  • If necessary, set the used memory limit (upon reaching the threshold, some values will be removed depending on the maxmemory-policy strategy, defined in the parameter):

maxmemory <bytes> (specify the maximum volume in bytes or leave the line commented)

maxmemory-policy volatile-lru (or another value, specified in the comments in this file)

maxmemory-policy noeviction (if using a limit is not required)

To configure Slave:

  • Specify the Slave access password (for the correct functioning of ELMA, specify the same password, as for the Master):

    requirepass your_redis_password

  • Specify the Master address and port:
    slaveof your_redis_master_ip 6379
  • Specify the Master password:
    masterauth your_redis_password

Restart all the servers (first Master, then Slaves):

sudo service redis_6379 restart

Configuration settings in ELMA

  1. In <configSections>, add:
    <section name="RedisCacheProviderSettings" type="EleWise.ELMA.Cache.Redis.RedisCacheProviderSettings, EleWise.ELMA.Cache.Redis"/>
  2. In the root <configuration> add a settings block (with the list of Redis cache machine names and their access passwords):
    <configuration>
      <RedisCacheProviderSettings connectionString="machine1:6379,machine2:6379,machine3:6379,password=your_redis_password" />
    </configuration>

       3. In <cacheService>, add:
         <add name="Redis" type="EleWise.ELMA.Cache.Redis.ElmaCacheService, EleWise.ELMA.Cache.Redis "/>
      And specify that it must be used by default:
      <cacheService defaultProvider="Redis">