Understand redis keyspace notifications with clear setup, config, and test commands to track real-time changes in your Redis database. Our Live Support Team is always here to help you.

Enable and Test Redis Keyspace Notifications the Right Way

Redis is known for its speed and flexibility, but there are times you need more than just storing and fetching data, especially when dealing with Redis exceptions. That’s where redis keyspace notifications come in. They let you keep track of every change that happens in your Redis dataset. Instead of constantly checking keys, you can subscribe to events and let Redis notify you instantly, even in cases like connection reset.

redis keyspace notifications

What is Redis Keyspace Notification?

In simple terms, it is a publish-subscribe mechanism that alerts you whenever something changes in Redis. Once enabled, you can subscribe to specific channels and get notifications about events like SET, DEL, EXPIRE, and more.

How to Enable

You need to turn on this feature before you can use it. Redis provides two ways to enable it—at runtime or permanently in the configuration file.

At Runtime

You can enable it immediately by running the following command in Redis CLI:

127.0.0.1:6379> CONFIG SET notify-keyspace-events KEA

You should see:

OK

This means keyspace notifications are now active. However, this change will not survive a server restart.

Using Configuration File

To make it permanent, edit the Redis configuration file:

$ sudo nano /etc/redis/redis.conf

Look for this line:

notify-keyspace-events ""

Now change it to:

notify-keyspace-events KEA

Save the file and restart your Redis server.

Understanding RKN Configuration Parameters

You might wonder what KEA means. By default, the directive is empty, so nothing is logged. Redis allows you to pass specific characters to decide what events get logged. Setting it to KEA enables all notifications for every type of event.

How to Test

After enabling the feature, you can easily test it. First, subscribe to the keyspace notification channel by running:

127.0.0.1:6379> psubscribe '__key*__:*'

Now open a second terminal session, connect to Redis, and execute:

127.0.0.1:6379> SET mykey myvalue

The subscription terminal should now display output like this:

1) "pmessage"
2) "__key*__:*"
3) "__keyspace@0__:mykey"
4) "set"

And you may also see:

1) "pmessage"
2) "__key*__:*"
3) "__keyevent@0__:set"
4) "mykey"

This shows how redis report events. The first part (__keyspace@0__:mykey) tells you the key affected, and the second (set) shows the actual event.

Why It Matter

With this feature, applications don’t need to constantly poll Redis for changes. Instead, they can react instantly when something happens, perfect for caching systems, real-time apps, and monitoring tools.

[If needed, Our team is available 24/7 for additional assistance.]

Conclusion

By configuring and testing as shown above, you’ll have a clear understanding of how redis keyspace notifications work in practice. The setup is simple, yet the impact on responsiveness and efficiency is huge.