Clearing redis cache memory

Although redis memory, as a rule, is based on storing the cache so that the website opens much faster, in some situations it may be necessary to clear the redis cache.

It is worth adding here that too frequent clearing of redis memory may result in slower performance of the site because the cache will have to be built from scratch each time.

To clear the memory we have three options.

1) Clearing Redis memory from within cPanel

To begin, we log into cPanel and navigate to the Redis Server application.

Then click “Wyczyść Pamięć”

Redis memory has been cleared.

2)clearing Redis memory from the terminal/ssh level

To use this option to begin with, you need to enable ssh in the customer panel

Go to https://www.smarthost.eu/panel/services

While in the panel, click the cogwheel icon on the bar of the hosting service then go to the Settings tab and click “enable ssh”.

In a further step, log in to cPanel and go to from the Terminal application

They will be in the terminal you should type the command:

/usr/bin/redis-cli -s /home/user_name/.redis/redis.sock -a redis_key flushall

Accordingly, for ,,user_name,, enter the cpanel username and for ,,redis_key, enter the redis database password available in cpanel -> Redis Server.

After calling the command, the redis memory will be cleared.

3)Cron clearing Redis memory

This option should be used most judiciously, clearing memory too often will result in almost the same effect as if Redis was disabled.

To create a cron we log into cPanel and go to “Cron jobs”.

To begin with, we set what time the cron task should execute, the most common configurations can be selected from the drop-down bar:

After selecting the interval, enter the command in the “Command” field:

/usr/bin/redis-cli -s /home/user_name/.redis/redis.sock -a redis_key flushall >/dev/null 2>&1

Accordingly, for ,,user_name,, enter the cpanel username and for ,,redis_key, enter the redis database password available in cpanel -> Redis Server.

After typing the command, click ,,Add new cron job,,

This is how Redis Memory will be cleared at the selected frequency.

It should be emphasized here that cleaning Redis memory during ordinary use is not necessary and even not recommended, although if for some reason there is a need to do so, approaching the clearing of Redis memory should not be done too often, so that in fact this cache has the ability to function properly.

Tomasz