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.
More Redis Questions
View all →- Intermediate What is Redis Cluster and how does it shard data?
- Intermediate What is the difference between Redis Sentinel and Redis Cluster?
- Intermediate How do MULTI and EXEC work in Redis transactions?
- Intermediate What is WATCH and optimistic locking in Redis?
- Intermediate What is Lua scripting in Redis and when should you use it?