First of all, log in to your server with SSH (root). Once you've logged into the server, open the Terminal. Now, run the following command to copy the existing Redis config file for backup purposes:
cp /etc/redis/redis.conf /etc/redis/redis.conf_bak
Now, modify /etc/redis/redis.conf file with nano editor or using SFTP:
nano /etc/redis/redis.conf
Set the following values:
maxmemory 256mb
maxmemory-policy allkeys-lfu
If you already have uncommented values starting with # at the Redis config, edit the value without adding them manually to the config! Once the value is added. restart Redis by running the following command line:
service redis restart
Done! Make sure to replace the maxmemory value with your own, depending on the RAM of your server. For example 256mb for 4GB of RAM, and 512mb for more than 4GB of RAM.