Skip to main content
ubuntuask.com

Back to all posts

How to Create Custom Key-Space-Events on Redis?

Published on
4 min read
How to Create Custom Key-Space-Events on Redis? image

Best Redis Tools to Buy in October 2025

1 Redis in Action

Redis in Action

BUY & SAVE
$34.99
Redis in Action
2 ATEQ VT37 TPMS Sensor Activation and Programming Tool

ATEQ VT37 TPMS Sensor Activation and Programming Tool

  • COMPREHENSIVE TPMS SENSOR DIAGNOSIS FOR ALL VEHICLES.

  • SUPPORTS 20+ TOP AFTERMARKET SENSOR BRANDS FOR VERSATILITY.

  • EASY RELEARN PROCEDURES FOR QUICK TPMS RESETS.

BUY & SAVE
$240.00
ATEQ VT37 TPMS Sensor Activation and Programming Tool
3 Redi Shade No Tools Original Light Filtering Pleated Paper Shade White, 36" W x 72" L, 6 Pack

Redi Shade No Tools Original Light Filtering Pleated Paper Shade White, 36" W x 72" L, 6 Pack

  • LIGHT CONTROL: ENJOY PRIVACY AND UV PROTECTION WITH SOFT LIGHT FILTERING.
  • ALWAYS CORDLESS: SAFE, SLEEK DESIGN WITH CLIPS FOR EASY HEIGHT ADJUSTMENT.
  • DURABLE PAPER: LONG-LASTING, SUN-RESISTANT MATERIAL DESIGNED IN THE USA.
BUY & SAVE
$24.98
Redi Shade No Tools Original Light Filtering Pleated Paper Shade White, 36" W x 72" L, 6 Pack
4 Redi Shade No Tools Original Blackout Pleated Paper Shade Black, 36" W x 72" L, 6 Pack

Redi Shade No Tools Original Blackout Pleated Paper Shade Black, 36" W x 72" L, 6 Pack

  • BLOCK 99% LIGHT FOR ULTIMATE PRIVACY AND UV PROTECTION IN ANY ROOM.
  • CORDLESS DESIGN ENSURES A CLEAN LOOK AND ENHANCED CHILD SAFETY.
  • DURABLE, SUN-RESISTANT PAPER CRAFTED FOR LONG-LASTING PERFORMANCE.
BUY & SAVE
$29.97
Redi Shade No Tools Original Blackout Pleated Paper Shade Black, 36" W x 72" L, 6 Pack
5 Redi-Edge Mini Multi Tool Knife Sharpener – Compact & Lightweight Serrated & Straight Edge Blade Sharpener with Duromite Inserts Set at 40° Inclusive Angle for Outdoor & Indoor Knives

Redi-Edge Mini Multi Tool Knife Sharpener – Compact & Lightweight Serrated & Straight Edge Blade Sharpener with Duromite Inserts Set at 40° Inclusive Angle for Outdoor & Indoor Knives

  • VERSATILE 2-IN-1 SHARPENER FOR STRAIGHT & SERRATED BLADES.
  • CONSISTENT 40° ANGLE FOR RAZOR-SHARP EDGES EVERY TIME.
  • LIGHTWEIGHT, DURABLE DESIGN PERFECT FOR OUTDOOR & KITCHEN USE.
BUY & SAVE
$35.02
Redi-Edge Mini Multi Tool Knife Sharpener – Compact & Lightweight Serrated & Straight Edge Blade Sharpener with Duromite Inserts Set at 40° Inclusive Angle for Outdoor & Indoor Knives
6 Redi Replacement Blades HVHSCPS2

Redi Replacement Blades HVHSCPS2

BUY & SAVE
$18.99
Redi Replacement Blades HVHSCPS2
7 Havalon REDI Non-Serrated Replacement Blades – 3” AUS-8 Stainless Steel Drop Point (2-Pack) – Resharpenable & Replaceable EDC Blades for REDI Folding Knife

Havalon REDI Non-Serrated Replacement Blades – 3” AUS-8 Stainless Steel Drop Point (2-Pack) – Resharpenable & Replaceable EDC Blades for REDI Folding Knife

  • DURABLE AUS-8 STEEL: LONG-LASTING, CORROSION-RESISTANT FOR EVERYDAY USE.

  • HEAVY-DUTY PERFORMANCE: DESIGNED TO TACKLE TOUGH CUTTING TASKS WITH EASE.

  • TOOL-FREE BLADE CHANGE: QUICK, EASY SWAPS FOR SEAMLESS OUTDOOR RELIABILITY.

BUY & SAVE
$21.63
Havalon REDI Non-Serrated Replacement Blades – 3” AUS-8 Stainless Steel Drop Point (2-Pack) – Resharpenable & Replaceable EDC Blades for REDI Folding Knife
+
ONE MORE?

To create custom key-space-events on Redis, you can use the CONFIG SET command to define the types of events you want to listen for. Key-space events allow you to receive notifications when specific types of Redis commands are executed on specific keys.

To set up key-space events, you will first need to configure Redis to broadcast events by setting the notify-keyspace-events configuration parameter. You can specify which events to listen for by using different characters to represent different types of events.

For example, to listen for all key-related events (e.g. set, del, expire), you can set the notify-keyspace-events parameter to the value AKE, which stands for All key events. You can also specify more granular events by using additional characters such as g for generic commands, E for key events related to list operations, and so on.

After configuring the key-space events, you can use the PSUBSCRIBE command to subscribe to specific types of events. When an event occurs that matches the specified pattern, Redis will publish a message to the client, allowing you to take the necessary actions based on the event.

By creating custom key-space events on Redis, you can monitor and react to changes in specific keys, allowing you to build more sophisticated and responsive applications that leverage the power of Redis as a data store.

What is the significance of key-space-events in redis?

In Redis, key-space-events refer to notifications that are triggered whenever a key is created, modified, or deleted in the database. These events are significant because they allow applications to react to changes in the database in real-time.

Key-space-events can be used to implement features such as cache invalidation, real-time notifications, and data synchronization between different parts of an application. By subscribing to key-space-events, developers can build more responsive and efficient applications that react immediately to changes in the database.

Overall, key-space-events in Redis provide a powerful way to build real-time applications and improve the overall performance and responsiveness of the system.

What is the difference between key-space-events and pub/sub mechanisms in redis?

Key-space-events and pub/sub mechanisms in Redis are both mechanisms used for handling events and notifications in Redis, but they have some key differences:

  1. Key-Space-Events:
  • Key-space-events allow clients to subscribe to notifications based on specific key-space events in Redis.
  • Clients can be notified when certain types of commands are executed on keys in the database, such as set, delete, expire, and more.
  • Key-space-events are more focused on specific key operations and are useful for monitoring changes to specific keys in the database.
  1. Pub/Sub Mechanisms:
  • Pub/Sub mechanisms in Redis allow clients to subscribe to channels and receive messages published to those channels by other clients.
  • Pub/Sub mechanisms are more generalized and allow for broader message distribution between clients.
  • Pub/Sub mechanisms are not tied to specific key operations, but rather allow for clients to publish and subscribe to messages on any channels they are interested in.

In summary, key-space-events are more focused on specific key operations and monitoring changes to specific keys, while pub/sub mechanisms are more generalized and allow for broader message distribution between clients.

How to set up key-space-events in redis configuration?

To set up key-space-events in your Redis configuration, follow these steps:

  1. Open the Redis configuration file (redis.conf) in a text editor.
  2. Search for the "notify-keyspace-events" parameter in the file. This parameter controls which Redis events trigger the publication of messages to channels for Pub/Sub support.
  3. By default, the "notify-keyspace-events" parameter is set to an empty value, which means key-space-events notifications are disabled.
  4. To enable key-space-events notifications, set the "notify-keyspace-events" parameter to one or more of the following values, depending on the type of events you want to be notified about: K: Key-space events, such as key expired, evicted, or deleted. E: Key-event events, such as key events related to streams. g: Generic commands (non-type specific) events.
  5. Save the Redis configuration file after making the necessary changes.
  6. Restart the Redis server to apply the new configuration.
  7. You can now subscribe to specific channels to receive notifications about key-space events and key-event events in Redis. For example, you can use the PUBLISH and SUBSCRIBE commands in Redis CLI to publish and subscribe to channels for those events, respectively.

By following these steps, you can set up key-space-events in Redis and start receiving notifications about specific key-related events in your Redis database.