Skip to content

Instance Method

subscribe(to:messageReceiver:onSubscribe:onUnsubscribe:)

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

Parameters

channels

The names of channels to subscribe to.

receiver

A closure which will be invoked each time a channel with a name in channels 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

See SUBSCRIBE

Important

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

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

See the PubSub specification