I've looking around and I'm unable to find how to perform a subscription to keyspace notifications on Redis using StackExchange.Redis library.
Checking available tests I've found pubsub using channels, but this is more to work like a service bus/queueing rather than subscribing to specific Redis key events.
Is it possible to take advantage of this Redis feature using StackExchange.Redis?
Just to extend what the selected answer already describes:
Another important thing, I had to subscribe KEx (CONFIG SET notify-keyspace-events KEx ) to get channel based updates for expiration notifications.
The regular subscriber API should work fine - there is no assumption on use-cases, and this should work fine.
However, I do kinda agree that this is inbuilt functionality that could perhaps benefit from helper methods on the API, and perhaps a different delegate signature - to encapsulate the syntax of the keyapace notifications so that people don't need to duplicate it. For that: I suggest you log an issue so that it doesn't get forgotten.
Simple sample of how to subscribe to a keyspace event
First of all, it's important to check that Redis keyspace events are enabled. For example, events should be enabled on keys of type Set. This can be done using
CONFIG SET
command:Once keyspace events are enabled, it's just about subscribing to the pub-sub channel:
Learn more about keyspace events here.