Redis provides commands for clearing cached data, including: deleting a single key: DEL, UNLINK clearing the entire database: FLUSHDB, FLUSHALL
Commands to clear Redis cache
Redis provides a variety of commands to clear the data in its cache. These commands are divided into two categories:
-
Deleting a single key: These commands delete the specified key and its associated value.
-
Clear the entire database: These commands delete the entire Redis database and all its keys and values.
Delete a single key
-
DEL key1 [key2 ...]: Delete one or more keys.
-
UNLINK key1 [key2 ...]: Deletes one or more keys asynchronously without blocking Redis.
Clear the entire database
-
FLUSHDB: Delete all keys and values in the current database, but keep other databases.
-
FLUSHALL: Delete all keys and values in all databases.
Choose the appropriate command
Which command you choose depends on the amount of data to be deleted and the desired cleaning speed.
- If you only want to delete a few specific keys, use DEL or UNLINK.
- If you want to clear the entire database, use FLUSHDB or FLUSHALL.
Note:
- Using FLUSHDB or FLUSHALL will block Redis until the clear operation is completed .
-
UNLINK is asynchronous, which means it does not block Redis. The
-
DEL and UNLINK commands return no results, while the FLUSHDB and FLUSHALL commands return "OK".
The above is the detailed content of Command to clear redis cache. For more information, please follow other related articles on the PHP Chinese website!