Skip to content

Redis 8.12 lets you expire individual set members

New SEXPIRE commands set a TTL on one member of a Set instead of the whole key, and a BLESS command exempts specific keys from eviction.

Source: Redis

Redis shipped the general availability release of 8.12 on 22 November, adding a handful of primitives that used to require workarounds.

The headline feature is expiration on individual set members. New SEXPIRE, SPEXPIRE, SEXPIREAT and SPEXPIREAT commands set a TTL on a single member inside a Set, with STTL, SPTTL, SEXPIRETIME and SPEXPIRETIME to read it back. Previously the only way to expire part of a set was to run your own sweep, or fake it with a sorted set and a background job. There’s also a new BLESS command that marks specific keys as exempt from eviction, so one hot key can survive maxmemory pressure without changing the eviction policy for everything else. Sorted sets get ZMOVE, BZMOVE and ZMOVEMEMBER for atomically moving members between sets, and bitmaps can now use a compressed, roaring-bitmap-backed format for lower memory and faster range queries.

Why it matters: anyone who has built session stores, rate limiters or per-user feature flags on top of Sets has hit the lack of per-member expiry before. SEXPIRE removes a layer of application code that existed only to simulate it, and BLESS gives cache designs a way to protect specific keys without a second instance or a custom eviction policy.

The caveat: the compressed bitmap format is opt-in, behind the bitmap-default-roaring config flag, which ships disabled by default.

Share

Related reading

More from The Wire

All briefs