Redis 8.12 adds expiry for individual Set members
Redis 8.12 brings per-member TTLs to Sets and memory improvements worth checking in self-hosted Laravel deployments.
Stop creating one temporary key for every item
For presence, active invitations, or short-lived permissions, the usual Redis pattern has been one key per item with its own TTL. It works, but it increases the number of keys and makes related data harder to manage as a group. Redis 8.12 adds expiration at the Set-member level, so lifetime no longer has to belong only to the whole key. (redis.io)
The model is straightforward: one key still groups related members, while every member can expire at a different time. For real-time presence, I can keep one Set per room, channel, or project. Each client heartbeat refreshes the TTL for that specific user instead of rebuilding the entire collection. That fits nicely in Laravel applications already using Redis for cache, sessions, queues, and transient state.
The commands worth knowing
SEXPIRE sets a TTL in seconds for one or more existing Set members. STTL reads the remaining lifetime, while SPERSIST removes expiration from the requested members. Redis also provides millisecond and absolute-time variants, but seconds are usually easier to read and maintain in application code. (redis.io)
Redis 8.12 also introduces SADDEX, which adds Set members and assigns an expiration in the same command. That is useful for presence tracking or invitations because it avoids splitting the insert and TTL assignment into separate operations. Its syntax requires the MEMBERS keyword, followed by the member count and the actual member values. (redis.io)
use Illuminate\Support\Facades\Redis;
Redis::command('saddex', [
'presence:room:42',
'EX', 90,
'MEMBERS', 1, 'user:123',
]);
Redis::command('sexpire', [
'presence:room:42',
90, 'XX',
'MEMBERS', 1, 'user:123',
]);
$ttl = Redis::command('sttl', [
'presence:room:42',
'MEMBERS', 1, 'user:123',
]);Here, SADDEX stores the user with a 90-second lifetime. The following SEXPIRE call uses XX, so it only renews the TTL when that member already has an expiration; this is useful when permanent members and temporary ones share the same Set. NX, XX, GT, and LT are mutually exclusive SEXPIRE options that control when a TTL update is accepted. (redis.io)
Where I would use it in Laravel
Presence tracking is the obvious use case: one Set per resource, with one member for each user, connection, or device. Every client ping refreshes its expiration, and Redis removes the member when activity stops without requiring an application cleanup job. To show who is still online, the application can read the Set and trust that only recently refreshed members remain.
It also works well for short-lived invitations or permissions. Instead of creating a separate key for every invitation, I can group them by team, document, or project and let each token expire independently. For rate limiting, it can help when the model is a temporary collection of identifiers, but it does not automatically replace counters, fixed windows, sliding windows, or scripts when those are the guarantees the limiter requires.
Memory improvements only matter for the right data
Version 8.12 integrates compressed bitmaps into Redis core and adds related commands, including BITRANGEINTARRAY and BITROAROP. The goal is lower memory use and better bitmap operations when the data pattern benefits from a compact representation. This is not a generic Laravel cache optimization; it is relevant when the application actually stores flags, cohorts, or state collections as bitmaps. (github.com)
Redis 8.12 also announces a new B+ tree encoding for large Sorted Sets, intended to reduce their memory footprint. That can matter when the same self-hosted Redis instance holds rankings, temporary indexes, supporting queue data, or ZSETs that have quietly grown over time. Normal commands such as ZADD and ZRANGE remain the way the application works with Sorted Sets, so this is not a reason to rewrite existing code. (github.com)
The details that can spoil a neat design
A member TTL is not a key TTL. If all expiring members disappear, the application should verify how that key behaves in its own flow and avoid using key existence as the only business-level signal. Expiration commands also operate on the members passed to them, and their cost grows with the number of members in the command, so a routine heartbeat should not turn into an unnecessary bulk operation. (redis.io)
It is also a mistake to promise memory savings before measuring them. Compressed bitmaps help bitmap workloads, while the Sorted Set encoding matters only if large ZSETs are a meaningful part of the instance’s real memory usage. Before upgrading a Redis installation that serves Laravel cache, sessions, and workers, I would inspect current metrics, test representative load, and make sure every connected client supports Redis 8.12.
The practical change for me is being able to stop creating temporary keys when the data genuinely belongs to one collection. A Set for presence, invitations, or temporary permissions can be easier to understand and operate than thousands of keys sharing a prefix. The remaining memory work is a good reason to review Redis usage, not a reason to assume every workload will become cheaper without testing it.
Redis 8.12.0 release notes Official Redis 8.12 command documentation