From Redis Keyspace Notifications

Keyspace notifications allow clients to subscribe to Pub/Sub channels in order to receive events affecting the Redis data set in some way.

Examples of events that can be received are:

All the commands affecting a given key.
All the keys receiving an LPUSH operation.
All the keys expiring in the database 0.

Events are delivered using the normal Pub/Sub layer of Redis, so clients implementing Pub/Sub are able to use this feature without modifications.

So, if you need just pub/sub, there is no need of extra configuration regarding Keyspace Notifications

Answer from usuario on Stack Overflow
🌐
Redis
redis.io › docs › latest › develop › pubsub › keyspace-notifications
Redis keyspace notifications | Docs
3 days ago - By default keyspace event notifications are disabled because while not very sensible the feature uses some CPU power. Notifications are enabled using the notify-keyspace-events of redis.conf or via the CONFIG SET.
🌐
GitHub
gist.github.com › JonCole › 0d6205b4771e5c803bc1e085517484a2
Redis Keyspace Notification Example · GitHub
Redis Keyspace Notification Example. GitHub Gist: instantly share code, notes, and snippets.
Discussions

Redis Subscribing to a channel ( key space notifications should be enabled ??) - Stack Overflow
Keyspace notifications allow clients to subscribe to Pub/Sub channels in order to receive events affecting the Redis data set in some way. Examples of events that can be received are: All the commands affecting a given key. All the keys receiving an LPUSH operation. More on stackoverflow.com
🌐 stackoverflow.com
python - Redis keyspace notifications - get both key and value change - Stack Overflow
I'm able to receive key-change pub-sub notifications in redis by launching the server as: ./redis-server --notify-keyspace-events KEA and then simply running the following script: import redis More on stackoverflow.com
🌐 stackoverflow.com
Subscribe to keyspace notification not working
You want to set the configuration to K$, not Ks. Using a lowercase s refers to commands that operate on sets (SADD, SDIFF, etc). The $ is for watching all string operations like GET and SET. Scalars in Redis are confusingly called “strings” even if they contain numbers. More on reddit.com
🌐 r/redis
4
0
May 16, 2022
Redis pubsub - Listening to a specific channel : How to do it?
RTFM mate: https://redis.io/topics/pubsub But to be a little more helpful. "auth" just authenticates your client to the server. There's no magic to Redis clients (except a little bit with Redis Sentinel). All they're doing is sending Redis built in commands over the wire. I'd suggest you play around with Redis CLI to familiarize yourself with the commands and then start worrying about programmatic access. The commands you're looking for are "publish" and "subscribe". Side note, Redis pub/sub is similar but entirely tangential to key space notifications. They are completely separate/independent, and unlike keyapace notifications, pub/sub spans Redis DBs. edit: Here's an example handler that I'd probably use in this situation. The handler map object would just be an object with the channel being the key and the value being a function that takes a standardized arg (perhaps the message?). https://pastebin.com/h2BdLLxA More on reddit.com
🌐 r/node
6
2
January 13, 2018
🌐
Redis
redis.io › docs › latest › operate › oss_and_stack › stack-with-enterprise › deprecated-features › triggers-and-functions › concepts › triggers › keyspace_triggers
Keyspace triggers | Docs
3 days ago - For a complete list of supported events, please refer to the Redis keyspace notifications page. To register a keyspace trigger, you need to use the redis.registerKeySpaceTrigger API when loading your library. The following example demonstrates how to register a database trigger that adds a "last updated" field whenever a hash key is modified:
🌐
DEV Community
dev.to › sayganov › redis-keyspace-notifications-with-a-c-example-2ahp
Redis keyspace notifications with a C# example - DEV Community
April 25, 2023 - We will cover the different types of events that can trigger notifications, how to configure Redis to send notifications, and how to receive and process notifications in a C# application using the StackExchange.Redis library. I presume that a Redis instance is already operational locally or elsewhere and that Redis CLI access is already available to you. By default keyspace event notifications are disabled and in order to enable it we need to execute the following command:
🌐
AWS re:Post
repost.aws › knowledge-center › elasticache-redis-keyspace-notifications
Implement Redis keyspace notifications in ElastiCache | AWS re:Post
April 29, 2024 - Note: By default, ElastiCache turns off Redis keyspace notifications. To activate keyspace notifications in a custom cache parameter group, use the notify-keyspace-events parameter. This parameter value uses multiple parameters to determine which channel (keyspace or key-event) is used and the information to post to the channel.
🌐
Medium
medium.com › @micah1powell › using-redis-keyspace-notifications-for-a-reminder-service-with-node-c05047befec3
Redis Keyspace Notifications for a Reminder Service with Node | by Micah Powell | Medium
January 13, 2018 - We have to configure this connection to emit the keyspace events that we want to listen to. // src/redis.repo.jsimport Redis from "ioredis"; const host = "localhost"; const port = 6379; const db = 0;export default class RedisRepo { constructor() { this.redis = new Redis({ port, host, db }); this.redis.on("ready", () => { this.redis.config("SET", "notify-keyspace-events", "Ex"); }); } }
Top answer
1 of 2
2

From Redis Keyspace Notifications

Keyspace notifications allow clients to subscribe to Pub/Sub channels in order to receive events affecting the Redis data set in some way.

Examples of events that can be received are:

All the commands affecting a given key.
All the keys receiving an LPUSH operation.
All the keys expiring in the database 0.

Events are delivered using the normal Pub/Sub layer of Redis, so clients implementing Pub/Sub are able to use this feature without modifications.

So, if you need just pub/sub, there is no need of extra configuration regarding Keyspace Notifications

2 of 2
0

key-space-notifications and pub/sub are 2 different concepts.

PUB/SUB: It's usual method publishing data to a channel and other clients can subscribe to the same channel by it's name. published messages are characterised into channels, without knowledge of what (if any) subscribers there may be.

This is enabled by default. messages are not persisted here, and once delivered/lost, messages cannot be retrieved.

key-space-notifications: This also a way of subscribing to Pub/Sub channels in order to receive events by the clients.

This we need to enable manually as this consumes little more CPU. Use below code to enable this

redisClient.configSet("notify-keyspace-events", "Ex");

we can subscribe to 2 different channels

  1. Key-space channel: receives the name of the event as message.
  2. Key-event channel: receives the name of the key as message.

example: To subscribe to key expired events, use the below code

export const subscribeForExpiry = () => {
  //.: Subscribe to the "notify-keyspace-events" 
  // channel used for expired type events
  client.configSet("notify-keyspace-events", "Ex");
  const sub = client.duplicate();
  sub.connect();

  sub.subscribe(
    `__keyevent@${process.env.REDIS_DATABASE_INDEX}__:expired`,
    (key) => {
      console.log("key=> ", key);
      // do something with key, can't retrieve value here
    }
  );
};
Find elsewhere
🌐
Microsoft Community Hub
techcommunity.microsoft.com › microsoft community hub › communities › products › azure › azure paas blog
Redis Keyspace Events Notifications | Microsoft Community Hub
January 15, 2021 - Some times the keys were deleted or evicted, other times the TTL expired and we are not aware of that. In these cases to monitor operations in the keys, we can enable the Redis Keyspace Notifications as described here to receive a notification when something happen: https://redis.io/topics/notifications
🌐
GitHub
github.com › redis-developer › keyspace-notifications-node-redis
GitHub - redis-developer/keyspace-notifications-node-redis: Keyspace Notifications demo with Node Redis 4 · GitHub
Keyspace Notifications demo with Node Redis 4. Contribute to redis-developer/keyspace-notifications-node-redis development by creating an account on GitHub.
Starred by 7 users
Forked by 2 users
Languages   Python 70.2% | JavaScript 29.8%
🌐
Upstash
upstash.com › docs › redis › howto › keyspacenotifications
Listen Keyspace Notifications - Upstash Documentation
For example, you can use the following command to receive keyspace notifications only for the hash commands: ... curl -X POST \ -d '["CONFIG", "SET", "notify-keyspace-events", "Kh"]' \ -H "Authorization: Bearer $UPSTASH_REDIS_REST_TOKEN" \ $UPSTASH_REDIS_REST_URL
🌐
StackExchange.Redis
stackexchange.github.io › StackExchange.Redis › KeyspaceNotifications.html
Redis Keyspace Notifications | StackExchange.Redis
To make this easier, StackExchange.Redis provides dedicated APIs for subscribing to keyspace and keyevent notifications that handle this for you. As an example, we’ll subscribe to all keys with a specific prefix, and print out the key and event type for each notification.
🌐
GitHub
github.com › redis › redis-doc › blob › master › docs › manual › keyspace-notifications.md
redis-doc/docs/manual/keyspace-notifications.md at master · redis/redis-doc
By default keyspace event notifications are disabled because while not very sensible the feature uses some CPU power. Notifications are enabled using the notify-keyspace-events of redis.conf or via the CONFIG SET.
Author   redis
🌐
GitHub
github.com › oneuptime › blog › tree › master › posts › 2026-01-30-redis-keyspace-notifications
blog/posts/2026-01-30-redis-keyspace-notifications at master · OneUptime/blog
... # Monitor a specific user's data redis-cli SUBSCRIBE '__keyspace@0__:user:12345' # Monitor all session keys redis-cli PSUBSCRIBE '__keyspace@0__:session:*' # Monitor configuration keys redis-cli PSUBSCRIBE '__keyspace@0__:config:*'
Author   OneUptime
🌐
Redis
redis.io › docs › latest › develop › pubsub › keyspace-notifications › index.html.md
Redis
For instance a [`DEL`]() operation targeting the key named `mykey` in database `0` will trigger the delivering of two messages, exactly equivalent to the following two [`PUBLISH`]() commands: PUBLISH __keyspace@0__:mykey del PUBLISH __keyevent@0__:del mykey The first channel listens to all the events targeting the key `mykey` and the other channel listens only to `del` operation events on the key `mykey` The first kind of event, with `keyspace` prefix in the channel is called a **Key-space notification**, while the second, with the `keyevent` prefix, is called a **Key-event notification**. In the previous example a `del` event was generated for the key `mykey` resulting in two messages: * The Key-space channel receives as message the name of the event.
🌐
Medium
medium.com › nerd-for-tech › redis-getting-notified-when-a-key-is-expired-or-changed-ca3e1f1c7f0a
Redis — Getting Notified When a Key is Expired or Changed | by Aditya Rama | Nerd For Tech | Medium
June 18, 2021 - After the first SET command, we got 2 notifications point 1–4 twice. I’ll try to explain it one by one. Look out this 4 lines (first message): 1.) pmessage 2.) __key*__:* 3.) __keyspace@0__:mykey 4.) set · When you set a key, redis will publish a pub sub message (point number 1), with a kind of “channel” point number 3 (with mykey is the key that is being changed, i guess 0 is the redis default DB?), in which we got since we listened to __key*__:* (subscribe pattern), and point number 4 is the command happened to that key, which is set.
🌐
KatPadi's Point
blog.katpadi.ph › home › til: redis keyspace notifications
TIL: Redis Keyspace Notifications - KatPadi's Point
February 24, 2023 - The said notifications are enabled using the notify-keyspace-events of redis.conf or via the CONFIG SET. It is disabled by default. ... For my particular case, I needed to use “zE” string because I want to catch the name of the key (and not the name of the event) when zrem, which is a sorted set command, is encountered. Let’s cut to the chase! Use keyspace if you want to receive the name of the event. Use keyevent if you want to receive the name of the key. So, here’s an example ...
🌐
Bqdong
bqdong.github.io › redis-docs › manual › keyspace-notifications
Redis keyspace notifications - Redis Documentation
By default keyspace event notifications are disabled because while not very sensible the feature uses some CPU power. Notifications are enabled using the notify-keyspace-events of redis.conf or via the CONFIG SET.
🌐
OneUptime
oneuptime.com › home › blog › how to create redis keyspace notifications
How to Create Redis Keyspace Notifications
January 30, 2026 - You must explicitly enable them using the notify-keyspace-events configuration parameter. The parameter accepts a string of characters, where each character enables a specific class of events: Add this line to your redis.conf file to enable all events on both channel types: