Help and support

Redis: delete keys (flush cache)

There are several ways to delete all keys from the redis memory: via SSH and via PHP. We will consider both options below.

Removal via SSH using redis-cli

Use the redis-cli utility to connect to your redis server via a socket, which can be obtained from the control panel

 /opt/alt/redis/bin/redis-cli -s /var/www/ch********/.system/redis/socket

While inside the redis-cli utility and connected to a socket, execute the clear keys command


You can check the current size of the key database with the command


Delete via PHP

Create a php script on the site with any name, for example flush-redis.php and place the following code inside. Note that the code specifies the path to your redis server socket, which can be obtained from the control panel

 <?php $redis = new Redis(); $redis->connect('/var/www/ch********/.system/redis/socket'); $redis->flushAll();

Run the script by opening it in the browser. The script doesn't display any output, it just instantly clears all the keys in the redis database

If necessary, use the following script to get the number of keys currently stored in the database

 <?php $redis = new Redis(); $redis->connect('/var/www/ch********/.system/redis/socket'); $keyCount = $redis->dbsize(); echo "ключів в базі даних: $keyCount";