Redis provides the following methods to delete the cache: DEL command: delete the cache value corresponding to the specified key UNLINK command: mark the key as deleted, delete it on the next restart FLUSHALL command: delete the cache value FLUSHDB corresponding to all keys in the database Command: Delete cached values corresponding to all keys in the current database
Redis Delete cached code
Redis provides There are many ways to delete the cache. Common codes are listed below:
DEL command:
<code>DEL key</code>
is used to delete the cache value corresponding to a single key.
UNLINK command:
<code>UNLINK key</code>
Similar to the DEL command, but the key will not be deleted immediately, but will be marked as deleted the next time the Redis service is restarted. will actually be deleted.
FLUSHALL command:
<code>FLUSHALL</code>
Delete the cached values corresponding to all keys in the database.
FLUSHDB command:
<code>FLUSHDB</code>
Delete the cache values corresponding to all keys in the current database.
Detailed description:
DEL command:
UNLINK command:
FLUSHALL command:
FLUSHDB Command:
Usage example:
<code>// 使用 DEL 命令删除单个键对应的缓存值 redis.del("key"); // 使用 UNLINK 命令标记键为删除状态 redis.unlink("key"); // 使用 FLUSHALL 命令删除数据库中所有键对应的缓存值 redis.flushall(); // 使用 FLUSHDB 命令删除当前数据库中所有键对应的缓存值 redis.flushdb();</code>
The above is the detailed content of redis delete cached code. For more information, please follow other related articles on the PHP Chinese website!