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.
root@debian7 # apt-get install redis-server
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 :
Daemonize or not the server
Set the number of databases.
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.
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
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
If you want to protect your data with a password you can set it like below:
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.
Latest posts by ZIADI Mohamed Ali (see all)
- How to show mounted devices in Linux? - July 25, 2017
- How to use Positional parameters and special variables in Linux - June 28, 2017
- Linux: Connect to your WiFi network through CLI? - June 25, 2017
- How to find a file in Linux? - March 19, 2017
- Mysql: How to find table and database size? - January 9, 2017