How to install Redis on Linux

Redis is an in-memory data structure project implementing a distributed, in-memory key-value database with optional durability. Redis supports different kinds of abstract data structures, such as strings, lists, maps, sets, sorted sets, HyperLogLogs, bitmaps, streams, and spatial indexes. The project is mainly developed by Salvatore Sanfilippo and as of 2019, is sponsored by Redis Labs. It is open-source software released under a BSD 3-clause license.

Install Redis on Linux

  1. Install Redis Server and PHP-Redis
    apt-get update
    apt-get upgrade
    apt-get install redis-server
    apt-get install php-redis
  2. Start Redis service
    systemctl start redis-server
  3. Check Redis status
    systemctl status redis-server
  4. Enable Redis on system boot
    systemctl enable redis-server.service

Configure Redis

  1. Set the Redis port
    vi /etc/redis/redis.conf
  2. Set the max number of connected clients at the same time. By default this limit is set to 10000 clients, however, if the Redis server is not able to configure the process file limit to allow for the specified limit the max number of allowed clients is set to the current file limit minus 32 (as Redis reserves a few file descriptors for internal uses).
    Once the limit is reached Redis will close all the new connections sending an error ‘max number of clients reached’.
  3. Set a memory usage limit to the specified amount of bytes. When the memory limit is reached Redis will try to remove keys according to the eviction policy selected (see maxmemory-policy).If Redis can’t remove keys according to the policy, or if the policy is set to ‘noeviction’, Redis will start to reply with errors to commands that would use more memory, like SET, LPUSH, and so on, and will continue to reply to read-only commands like GET.
  4. Restart Redis-server
    service redis-server restart