taoensso / carmine

Redis client + message queue for Clojure
https://www.taoensso.com/carmine
Eclipse Public License 1.0
1.15k stars 130 forks source link

watching a key for changes #236

Closed zcaudate closed 4 years ago

zcaudate commented 4 years ago

Is there a way to listen for changes on a given key so that every time (car/set <key> value) is run, a watch function runs - like that of an atom?

Can this be implemented with pub/sub?

ptaoussanis commented 4 years ago

Hi Chris!

Sure, this is possible- see here for details. In Carmine you can use the corresponding pub/sub API.

Best of luck!

zcaudate commented 4 years ago

Hi Peter

I was playing around with:

(def listener
    (car/with-new-pubsub-listener (:spec (:conn -c-))
      {"*" (fn [msg] (println "Print " msg))}
      (car/psubscribe "*")))

I couldn't figure out why messages were not printing. That link you sent explaining the configuration options really helped.

Adding this fixed it:

(car/wcar (:conn -c-)
            (car/config-set "notify-keyspace-events" "KEA"))

Thanks.