12 PubSub Commands
procedure
(make-redis-pubsub client) → redis-pubsub?
client : redis?
PubSub values are synchronizable events whose synchronization results are the messages received via the channels the value is subscribed to.
Messages from channel subscriptions are represented as lists of two elements, where the first element is the name of the channel and the second the value of the message.
Messages from pattern subscriptions are represented as lists of three elements, where the first element is the pattern, the second the channel and the third the value of the message.
While in PubSub mode, any commands you try to send to the original connection will fail.
Here’s an example of how the pieces fit together:
(require redis) (define pool (make-redis-pool)) (thread (lambda _ (call-with-redis-client pool (lambda (c) (sleep 5) (redis-pubsub-publish! c "a" "hello") (sleep 5) (redis-pubsub-publish! c "a" "goodbye"))))) (call-with-redis-client pool (lambda (c) (call-with-redis-pubsub c (lambda (p) (redis-pubsub-subscribe! p "a") (displayln (~v (sync p))) (displayln (~v (sync p)))))))
procedure
(call-with-redis-pubsub client proc) → any
client : redis? proc : (-> redis-pubsub? any)
procedure
(redis-pubsub? v) → boolean?
v : any/c
procedure
(redis-pubsub-kill! pubsub) → void?
pubsub : redis-pubsub?
procedure
(redis-pubsub-publish! client channel message) → exact-nonnegative-integer? client : redis? channel : redis-string/c message : redis-string/c
procedure
(redis-pubsub-subscribe! pubsub channel-or-pattern ...+ [ #:patterns? patterns?]) → void? pubsub : redis-pubsub? channel-or-pattern : redis-string/c patterns? : boolean? = #f
When patterns? is #t, channel-or-pattern values are treated as patterns, otherwise they’re treated as channels.
procedure
(redis-pubsub-unsubscribe! pubsub channel-or-pattern ... [ #:patterns? patterns?]) → void? pubsub : redis-pubsub? channel-or-pattern : redis-string/c patterns? : boolean? = #f
When patterns? is #t, channel-or-pattern values are treated as patterns, otherwise they’re treated as channels.