If you’re currently running WordPress site with W3-Total-Cache plugin you may know Redis act a Database Cache module inside the plugin configuration. Installing and configuring Redis cache on Debian Ubuntu LTS server is very easy and you just need relax time to perform this task.

But, before doing that, what is actually Redis cache? Redis is an open-source software under BSD licensed, which commonly used as a database caching module with built in-memory data structure store. Redis has built-in replication with Lua scripting, LRU eviction, transactions, and different levels of on-disk persistence.

Redis provides high-availability via Sentinel and automatic partitioning with its Cluster module. Redis has also provide data structures like strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes, and streams.

In order to build Redis cache inside your Debian Ubuntu LTS server, simply read the following tutorial.

Install and Configure Redis Cache on Ubuntu LTS Server, including version 14.04, 16.04, 18.04, and 20.04 LTS. Please note, if you’re Debian Ubuntu fans, it’s highly recomended to run only on LTS version if you want to use it as a server.

1.) Let’s install Redis Cache on Ubuntu LTS Server

This should work on all Ubuntu LTS version, including Ubuntu 14.04, 16.04, 18.04, and 20.04 LTS.

$ apt install redis-server php-redis -y

After that, enable and restart redis service.

$ systemctl restart redis-server.service
$ systemctl enable redis-server.service

To monitor redis, simply run this command.

$ redis-cli monitor

To login into redis cli, run this command.

$ redis-cli

To flush all redis caching, simply run this command.

$ flushall

Now, you can quit from redis cli interface.

$ quit

NOTE: For Ubuntu 14.04 – 16.04 LTS, you can use apt-get command, instead of apt command.

2.) Install Redis Cache on Debian Server

Including Debian 8 (Jessie), Debian 9 (Strecht), and Debian 10 (Buster). This is stable release version of the Debian distribution system.

$ apt install redis-server php5-redis php-redis

Restart and enable redis cache service.

$ systemctl restart redis-server.service
$ systemctl enable redis-server.service

Like Ubuntu, command is exactly same as Debian, so let’s login to redis cli interface

$ redis-cli

To monitor redis cache

$ redis-cli monitor

FLush all redis cache

$ flushall

Quit from redis interface

$ quit

3.) Fine-tune for Redis Cache

Let’s doing performance tuning for Redis cache, we can do it via redis.conf configuration file.

Open redis.conf file using nano editor or your preferred Linux editor, and then only change the following redis directive / variable.

$ nano /etc/redis/redis.conf
--------------------------------------------------------------------------------------
...
# TCP listen() backlog.
#
# In high requests-per-second environments you need an high backlog in order
# to avoid slow clients connections issues.
tcp-backlog 65536 # default is 511

# Close the connection after a client is idle for N seconds (0 to disable)
timeout 30

# TCP keepalive.
#
# If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence
# of communication. This is useful for two reasons:
#
# A reasonable value for this option is 60 seconds.
tcp-keepalive 60

################################### LIMITS ####################################

# Once the limit is reached Redis will close all the new connections sending
# an error 'max number of clients reached'.
#
maxclients 10000

# When a child rewrites the AOF file, if the following option is enabled
# the file will be fsync-ed every 32 MB of data generated.
aof-rewrite-incremental-fsync yes
maxmemory 256mb
maxmemory-policy allkeys-lru
--------------------------------------------------------------------------------------

After that, don’t forget to restart redis cache service.

$ systemctl restart redis.service

LEAVE A REPLY

Please enter your comment!
Please enter your name here