redis_logo

 

What is Redis?

According to wikipedia, REDIS (REmote DIctionary Server) is a software project that implements data structure servers. It is open-source, networked, in-memory, and stores keys with optional durability.
According to monthly rankings by DB-Engines.com, Redis is often ranked:

  • the most popular key-value database,
  • #4 NoSQL database in user satisfaction and market presence based on user reviews,
  • the most popular NoSQL database in containers,
  • the #1 NoSQL database among Top 50 Developer Tools & Services.

Installation

Debian/Ubuntu

root@debian7 # apt-get install redis-server

Centos/Redhat/Scientific Linux

root@centos7 # yum install redis
root@centos7 # systemctl start redis # if you are using systemd

Configuration and remarquable parameters

The configuration file is /etc/redis/redis.conf for Debian/Ubuntu and /etc/redis.conf for Redhat Centos. The main remarquable parameters are :

Listening address

bind 127.0.0.1

Listening port

port 6379

Daemonize or not the server

daemonize yes

Database number

Set the number of databases.

databases 16

Client number

maxclient 3

Max memory

maxmemory 128m

Max memory policy

Once the allocated maxmemory is consumed, Redis will process to key eviction. There are 5 different manners:

  • volatile-lru -> remove the key with an expire set using an LRU algorithm : evict keys trying to remove the less recently used (LRU) keys first, but only among keys that have an expire set, in order to make space for the new data added
  • allkeys-lru -> remove any key accordingly to the LRU algorithm : evict keys trying to remove the less recently used (LRU) keys first, in order to make space for the new data added.
  • volatile-random -> remove a random key with an expire set
  • allkeys-random -> remove a random key, any key
  • volatile-ttl -> remove the key with the nearest expire time (minor TTL)
  • noeviction -> don’t expire at all, just return an error on write operations

For production use it is recommanded to set this parameter to volatile-lru.

maxmemory-policy volatile-lru

Redis command line interface

To access Redis CLI use redis-cli command:

redis-cli -p REDIS_PORT

if not listening on localhost:

redis-cli -p REDIS_PORT -h REDIS_HOST

Replication Master-Slaves and Security

Slave side

After connecting to redis-cli:

SLAVEOF master_ip master_port

The master can be protected by a password. In this case the slave must be authenticated before receiving the replication

MASTERAUTH master_password

Master side

If you want to protect your data with a password you can set it like below:

REQUIREPASS **STRONG_PASSWORD**

Replication status

To obtain replication status you can use:

redis-cli -p REDIS_PORT -h REDIS_HOST INFO REPLICATON
# Replication
role:master
connected_slaves:1
slave0:ip=XXXXXX,port=YYYY,state=online,offset=29,lag=0
master_repl_offset:29
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:28

To stop replication, on slave :

SLAVEOF NO ONE

Hope that this blogs helps you to set up correctly one of the most popular memory-cache system. Feel free to read our blogs and leave feedbacks. Till next time.

The following two tabs change content below.
I am a hands-on, competent Linux system engineer with 9 years’ experience. I have a strong performance background in wide variety of professional Linux system support including monitoring, configuration, troubleshooting and maintenance. I have worked on numerous projects from concept to completion. A specialist in LAMP platforms, I take pride in administrating Linux systems and regularly refresh my skills to ensure I keep up with ongoing developments and new technologies.