Skip to content

Instance Method

psubscribe(to:messageReceiver:onSubscribe:onUnsubscribe:)

Subscribes the client to the specified Redis channel name patterns, invoking the provided message receiver each time a message is published to a matching channel.
func psubscribe(to patterns: [String], messageReceiver receiver: @escaping RedisSubscriptionMessageReceiver, onSubscribe subscribeHandler: RedisSubscriptionChangeHandler?, onUnsubscribe unsubscribeHandler: RedisSubscriptionChangeHandler?) -> EventLoopFuture<Void>

Parameters

patterns

A list of glob patterns used for matching against PubSub channel names to subscribe to.

receiver

A closure which will be invoked each time a channel with a name matching the specified pattern(s) publishes a message.

subscribeHandler

An optional closure to be invoked when the subscription becomes active.

unsubscribeHandler

An optional closure to be invoked when the subscription becomes inactive.

Return Value

A notification NIO.EventLoopFuture that resolves once the subscription has been registered with Redis.

Discussion

Note

If the client is also subscribed to a channel directly by name which also matches a pattern, both subscription message receivers will be invoked.

See PSUBSCRIBE

Important

This will establish the client in a “PubSub mode” where only a specific list of commands are allowed to be executed.

Commands issues with this client outside of that list will resolve with failures.

See the PubSub specification