One-time token consumption
Consume one-time tokens, then remove them after successful retrieval.
Redis · Module
GETDEL returns a string value and deletes its key in the same command. It returns nil when the key is missing or does not contain a string.
GETDEL atomically retrieves a key's string value and removes that key when the operation succeeds. If the key is absent or holds a non-string value, it returns a nil response and does not provide a value.
GETDEL key| Name | Type | Description |
|---|---|---|
key | key | The name of the key to retrieve and then delete. |
Bulk string reply containing the key's value, or a nil reply when the key does not exist or its value is not a string.
SET session:42 "user-123"
GETDEL session:42
GET session:42The first command stores a string, GETDEL returns it while deleting the key, and the final GET returns nil.
Consume one-time tokens, then remove them after successful retrieval.
Fetch a transient cache entry while ensuring it cannot be read again.
Atomically take ownership of a temporary string-valued work item.
GETDEL takes one key, returns its string value, and deletes the key on success. It combines retrieval and removal in one Redis command.
Follow-up: What happens for a hash key? GETDEL returns nil because the value type is not a string, rather than returning the hash contents.
The syntax is GETDEL key. The key identifies the value to read and then delete.
Follow-up: How would you delete several keys? Use DEL with multiple key arguments, because GETDEL accepts only one key.
A bulk string reply contains the value. A nil response means the key is absent or its value is not a string.
Follow-up: Why should a client not treat nil as an empty string? Redis uses nil to represent the missing or incompatible-type cases, while an existing empty string is still a string value.
GETDELGETEX