Cache invalidation
Remove a cached response after its source data changes.
Redis · Command
DEL removes one or more specified keys and ignores names that do not exist. It returns the count of keys successfully deleted.
DEL removes every named key that currently exists. Missing keys are ignored, and the command reports how many keys it actually removed. Supplying multiple keys lets one command delete several cache entries.
DEL key [key ...]| Name | Type | Description |
|---|---|---|
key | key | The first key to remove; required. |
key ... | key | Zero or more additional keys to remove. |
Integer reply: the number of keys that were removed.
SET session:123 "active"
DEL session:123 session:missing
EXISTS session:123Creates a key, removes it along with a nonexistent key, then verifies that the existing key is gone.
Remove a cached response after its source data changes.
Invalidate a session or token immediately during logout.
Clean up several related temporary keys in one request.
DEL accepts one or more keys and removes the ones that exist. Its integer result is the number of keys removed, so missing keys contribute zero.
Follow-up: How would you avoid blocking the server while removing a very large value? Use UNLINK when asynchronous reclamation is preferable.
The command syntax is DEL key [key ...]. The first key is required, and the bracketed repetition permits additional keys in the same command.
Follow-up: What constraint matters when deleting several keys in a cluster? Keys may need to satisfy the cluster's multi-key operation requirements.
DEL has O(N) time complexity, where N is the number of keys being removed. It is categorized by Redis as a keyspace write command with slow-command classification.
Follow-up: What alternative has the same deletion purpose but moves memory reclamation away from the main execution path? UNLINK.
EXISTSGETSETUNLINK