Search⌘ K
AI Features

Redis Notifications

Explore how Redis notifications allow applications to asynchronously respond to data changes by subscribing to specific Pub/Sub channels. Understand key-space and key-event notifications and learn to implement an asynchronous cache loading mechanism to improve performance and maintainability in applications using Redis and Go.

Redis notifications overview

Redis notifications allow clients to receive events in response to data changes in Redis. Behind the scenes, this is made possible by Redis Pub/Sub channels.

Types of notifications

The way we use notifications is by subscribing to the appropriate Pub/Sub channel, which is based on a specific naming template. There are two types of notifications we can work with:

  • Key-space notification: We can use this to get notified about changes to specific keys. For example, to get notified about all actions on the key testkey, we can use a key-space notification by subscribing to a Pub/Sub channel named __keyspace@0__:testkey. The channel will receive the name of the event (set, delete, etc.), along with the name of the key. It’s possible to further restrict this. For example, if we’re only interested in the set operations on the key, we can subscribe to the __keyspace@0__:testkey set channel instead.

  • Key-event notification: We can use this to get notified about specific actions that are being executed. For example, to ...