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 SET is idempotent: it returns 1 the first time the flag is added to a key, and 0 on later calls if the key already carries that flag.
  • A blessed key is skipped as an eviction candidate under every maxmemory-policy value. See Protecting keys from eviction for how this interacts with the maxmemory limit.
  • BLESS SET generates a bless keyspace notification event.
  • BLESS SET can itself be blocked with an out-of-memory error under the same conditions as any other write command. BLESS CLEAR isn't subject to this, so you can always remove protection to free up eviction candidates.
  • The flag isn't included in DUMP output, and RESTORE doesn't set it on the restored key. If RESTORE targets a key that's already blessed and uses REPLACE, 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
❌ Active-Active
❌ Standard
❌ Active-Active

Return information

One of the following:

See also

BLESS CLEAR | BLESS GET | BLESS SCAN

RATE THIS PAGE
Back to top ↑