Contenido del Curso
Introduction to Redis
Introduction to Redis
Data Deletion
Managing data in Redis goes beyond simply adding or modifying it. There are scenarios where you might need to remove data, whether it's deleting specific keys or clearing an entire database.
DEL Command
The DEL
command is used to delete one or more keys. If a key exists, its associated data is removed, and the command returns the number of keys deleted. If the key does not exist, the command does nothing.
You can delete multiple keys at once by listing them, separated by spaces:
The command removes two keys: user:1
and user:2
. If these keys exist, Redis erases their data, releases the associated memory, and returns the total number of keys deleted, which in this case is 2
.
FLUSHDB and FLUSHALL Commands
The FLUSHDB
command removes all data from the current Redis database. Redis can handle multiple databases (16
by default, indexed from 0
), and this command clears only the currently selected one.
Usage is straightforward; simply execute:
The FLUSHALL
command is more powerful as it clears all data across all Redis databases, not just the current one.
To execute, use:
1. What does the DEL
command do in Redis?
2. Which command removes all data in the current Redis database?
¡Gracias por tus comentarios!