🔴 Redis Intermediate

What are Redis keyspace notifications?

Answer

Keyspace notifications allow clients to subscribe to Pub/Sub channels that publish events when certain Redis operations occur on keys. Enable them in redis.conf with notify-keyspace-events (e.g., KEA for all events). Two types of notifications are published: keyspace notifications (on channel __keyspace@db__:key, receive the event name) and keyevent notifications (on channel __keyevent@db__:event, receive the key name). Common use cases: triggering application logic when a key expires (expired event) — implementing a delayed job queue or session expiry cleanup; auditing which keys are being accessed; invalidating application-level caches in other systems when data changes. Note that expired event notifications have a small delay and are not guaranteed to fire exactly at expiry time.