Home > Database > Redis > body text

Command to clear redis cache

下次还敢
Release: 2024-04-19 23:15:25
Original
1188 people have browsed it

Redis provides commands for clearing cached data, including: deleting a single key: DEL, UNLINK clearing the entire database: FLUSHDB, FLUSHALL

Command to clear redis cache

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template