Reputation: 243
I've been searching to find out how to perform a subscription to key space notifications on Redis using ServiceStack.Redis library for removal of Key.
Checking available tests on the git-hub and other websites I've found IRedisSubscription can be used for subscribing to specific Redis key events, For set operation it is working absolutely fine but when it comes to Delete operation the action is not invoked.
Is it possible to take advantage of this Redis feature using ServiceStack.Redis and get event on delete operation too?
In the configuration file I have added this line:
notify-keyspace-events KEAg
I am using the following code.
var channels = new[] { "__keyevent@0__:set" , "__keyevent@0__:del" };
using (var redisConsumer = new RedisClient("localhost:6379"))
using (var subscription = redisConsumer.CreateSubscription()) {
subscription.OnMessage = onKeyChange;
subscription.SubscribeToChannelsMatching(channels );
}
Upvotes: 1
Views: 1802
Reputation: 6774
From the surface, it looks like what you got should work.
Try setting notify-keyspace-events
to AKE
, the g
is redundant, as noted in Notifications Config:
A Alias for g$lshztxe, so that the "AKE" string means all the events.
Try using SubscribeToChannels
instead of SubscribeToChannelsMatching
. The latter is for pattern subscription.
You can test how many subscribers you have with the PUBSUB NUMSUB __keyevent@0__:del
command from redis-cli.
Try testing your events are being triggered with SUBSCRIBE __keyevent@0__:del
from redis-cli. This will help you determine if the problem is on redis-server or the app code.
Please update the question with results if you can't get it to work after trying the above.
Upvotes: 1