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
1 day ago - If in doubt about how events are generated for a given command, the simplest thing to do is to watch yourself: $ redis-cli config set notify-keyspace-events KEA $ redis-cli --csv psubscribe '__key*__:*' Reading messages...
🌐
Redis
redis.io › docs › latest › operate › oss_and_stack › stack-with-enterprise › deprecated-features › triggers-and-functions › concepts › triggers › keyspace_triggers
Keyspace triggers | Docs
February 26, 2026 - { "event": "<the event name that fired the trigger>", "key": "<key name that the event was fired on as String>", "key_raw": "<key name that the event was fired on as ArrayBuffer>" } Notice that the key field is given only if the key can be decoded as a JS String, otherwise the value will be null. We can display trigger information using TFUNCTION LIST command: 127.0.0.1:6379> TFUNCTION list vvv 1) 1) "engine" 2) "js" 3) "api_version" 4) "1.0" 5) "name" 6) "foo" 7) "pending_jobs" 8) (integer) 0 9) "user" 10) "default" 11) "functions" 12) (empty array) 13) "keyspace_triggers" 14) (empty array) 1
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
    }
  );
};
🌐
GitHub
github.com › redis-developer › keyspace-notifications-node-redis
GitHub - redis-developer/keyspace-notifications-node-redis: Keyspace Notifications demo with Node Redis 4 · GitHub
This is a small project using Redis and 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.
Starred by 7 users
Forked by 2 users
Languages   Python 70.2% | JavaScript 29.8%
🌐
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 - When using Azure Cache for Redis, Keyspace notifications can be enabled in Azure Portal, on Redis blade. Setting the parameter to the empty string disables notifications. In order to enable the feature a non-empty string is used, composed of multiple characters, where every character has a special meaning according to the following table: K Keyspace events, published with __keyspace@<db>__ prefix.
🌐
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 - Now the most interesting part. Here we are subscribing to Redis keyspace notifications. Specifically, it is subscribing to keyspace events that occur on Redis database 0 (zero) by using the __keyspace@0__:* prefix in the channel pattern.
🌐
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.
🌐
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
If in doubt about how events are generated for a given command, the simplest thing to do is to watch yourself: $ redis-cli config set notify-keyspace-events KEA $ redis-cli --csv psubscribe '__key*__:*' Reading messages...
Author   redis
🌐
Redis
redis.io › docs › interact › programmability › triggers-and-functions › concepts › triggers › keyspace_triggers
Keyspace triggers | Redis
{ "event": "<the event name that fired the trigger>", "key": "<key name that the event was fired on as String>", "key_raw": "<key name that the event was fired on as ArrayBuffer>" } Notice that the key field is given only if the key can be decoded as a JS String, otherwise the value will be null. We can display trigger information using TFUNCTION LIST command: 127.0.0.1:6379> TFUNCTION list vvv 1) 1) "engine" 2) "js" 3) "api_version" 4) "1.0" 5) "name" 6) "foo" 7) "pending_jobs" 8) (integer) 0 9) "user" 10) "default" 11) "functions" 12) (empty array) 13) "keyspace_triggers" 14) (empty array) 1
Find elsewhere
🌐
GitHub
github.com › iamchrismiller › redis-notifier
GitHub - iamchrismiller/redis-notifier: Redis Keyspace Event Notifier
Start Redis Server : redis-server CONF --notify-keyspace-events KExe
Starred by 16 users
Forked by 9 users
Languages   JavaScript 100.0% | JavaScript 100.0%
🌐
Upstash
upstash.com › docs › redis › howto › keyspacenotifications
Listen Keyspace Notifications - Upstash Documentation
curl -X POST \ -d '["CONFIG", "SET", "notify-keyspace-events", "Kh"]' \ -H "Authorization: Bearer $UPSTASH_REDIS_REST_TOKEN" \ $UPSTASH_REDIS_REST_URL
🌐
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 - I will then use this PubSub class and its methods throughout my application to subscribe to channels, add listeners and publish events into those channels. You can read more about redis pubsub here. Next, lets create another redis connection which we will use to handle all of our data and keyspace ...
🌐
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 - The first message (keyspace) notify that mykey is expired. While the second message is stating that an expired event is happening on mykey. Therefore, if you need some notification when your “monitored” key is changed / expired so you can put some handling in your application, it’ll be nice to try considering this key space notification feature in Redis...
🌐
GitHub
gist.github.com › JonCole › 0d6205b4771e5c803bc1e085517484a2
Redis Keyspace Notification Example · GitHub
Redis Keyspace Notification Example. GitHub Gist: instantly share code, notes, and snippets.
🌐
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
Description: Use Redis keyspace notifications to react to key events like expiration, deletion, and modifications for event-driven architectures.
Author   OneUptime
🌐
Heroku
help.heroku.com › 5BP0E8RC › how-to-enable-notify-keyspace-events-on-redis
How to enable notify-keyspace-events on Redis - Heroku Help
heroku redis:keyspace-notifications REDIS_URL -c 'AKE' -a your_app_name · where the string following -c is used to set the config options. In the above example, 'AKE' means enabling keyspace notifications for all events except for key miss events.
🌐
SAP Community
community.sap.com › t5 › technology-blog-posts-by-sap › redis-on-sap-btp-where-and-when-to-use-keyspace-events › ba-p › 14098425
Redis on SAP BTP: Where and When to use Keyspace Events
May 14, 2025 - These events are published over Redis Pub/Sub and can be subscribed to by your application. ... Cache invalidation: when a key is updated or deleted, notify other app instances to refresh their local cache. Triggering workflows: when a specific key is set (e.g., user has submitted a form), initiate a micro-process or publish an event. Monitoring key changes: use keyspace events to log, audit, or react to high-value operations (e.g., security tokens being revoked).
🌐
StackExchange.Redis
stackexchange.github.io › StackExchange.Redis › KeyspaceNotifications.html
Redis Keyspace Notifications | StackExchange.Redis
As an example, we’ll subscribe to all keys with a specific prefix, and print out the key and event type for each notification. First, we need to create a RedisChannel: // this will subscribe to __keyspace@0__:user:*, including supporting Redis Cluster var channel = RedisChannel.KeySpacePrefix(prefix: "user:"u8, database: 0);
🌐
DEV Community
dev.to › serhatayata › redis-keyspace-notifications-with-docker-4o90
Redis Keyspace Notifications with Docker - DEV Community
December 16, 2023 - version: '3.4' services: redis: container_name: redis tty: true command: sh -cx "redis-server --daemonize yes && redis-cli config set notify-keyspace-events KEA && sleep infinity" image: redis ports: - 6379:6379 volumes: - /opt/app_data/redis/:/data redisInsight: image: 'redislabs/redisinsight:latest' ports: - 8001:8001