c# - Redis keyspace notifications with StackExchange.Redis -


i've looking around , i'm unable find how perform subscription keyspace notifications on redis using stackexchange.redis library.

checking available tests i've found pubsub using channels, more work service bus/queueing rather subscribing specific redis key events.

is possible take advantage of redis feature using stackexchange.redis?

the regular subscriber api should work fine - there no assumption on use-cases, , should work fine.

however, kinda agree inbuilt functionality perhaps benefit helper methods on api, , perhaps different delegate signature - encapsulate syntax of keyapace notifications people don't need duplicate it. that: suggest log issue doesn't forgotten.

simple sample of how subscribe keyspace event

first of all, it's important check redis keyspace events enabled. example, events should enabled on keys of type set. can done using config set command:

config set notify-keyspace-events kes 

once keyspace events enabled, it's subscribing pub-sub channel:

using (connectionmultiplexer connection = connectionmultiplexer.connect("localhost")) {     idatabase db = connection.getdatabase();     isubscriber subscriber = connection.getsubscriber();      subscriber.subscribe("__keyspace@0__:*", (channel, value) =>         {             if ((string)channel == "__keyspace@0__:users" && (string)value == "sadd")             {                 // stuff if item added hypothethical "users" set in redis             }         }     ); } 

learn more keyspace events here.


Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -