BLESS SET
BLESS SET key NO-EVICT
- Available since:
- Redis Open Source 8.12.0
- Time complexity:
- O(1)
- ACL categories:
-
@dangerous,@write,@fast, - Compatibility:
- Redis Software and Redis Cloud compatibility
BLESS SET marks a key so that Redis skips it when choosing candidates for eviction under memory pressure. The key must already exist.
Required arguments
key
The name of the key to protect. The key must already exist, or the command returns an error.
NO-EVICT
The protection flag to add. NO-EVICT is currently the only supported flag.
Details
Behavior
BLESS SETis idempotent: it returns1the first time the flag is added to a key, and0on later calls if the key already carries that flag.- A blessed key is skipped as an eviction candidate under every
maxmemory-policyvalue. See Protecting keys from eviction for how this interacts with themaxmemorylimit. BLESS SETgenerates ablesskeyspace notification event.BLESS SETcan itself be blocked with an out-of-memory error under the same conditions as any other write command.BLESS CLEARisn't subject to this, so you can always remove protection to free up eviction candidates.- The flag isn't included in
DUMPoutput, andRESTOREdoesn't set it on the restored key. IfRESTOREtargets a key that's already blessed and usesREPLACE, the destination key keeps its existing protection. - The flag persists across restarts and replicates like any other write.
Examples
redis> SET session:42 "some value" OK redis> BLESS SET session:42 NO-EVICT (integer) 1 redis> BLESS SET session:42 NO-EVICT (integer) 0 redis> BLESS SET missing-key NO-EVICT (error) ERR no such key
Redis Software and Redis Cloud compatibility
| Redis Software |
Redis Cloud |
Notes |
|---|---|---|
| ❌ Standard |
❌ Standard |
Return information
One of the following:
- Integer reply:
1if the flag was added,0if the key already had it. - Simple error reply if the key doesn't exist.
See also
BLESS CLEAR | BLESS GET | BLESS SCAN