Publish/Subscribe
Use Redis as a complete real-time messaging broker
Last updated
Use Redis as a complete real-time messaging broker
Last updated
We have introduced the capability for your CFML code to now leverage Redis Publish and Subscribe constructs. This will allow your CFML code to have native messaging via Redis.
Redis Pub/Sub implements the Publish/Subscribe messaging paradigm. This decoupling of publishers and subscribers can allow for greater scalability and a more dynamic network topology.
Subscribers express interest in one or more channels (literal channels or pattern channels).
Publishers send messages into channels.
Redis will push these messages into different subscribers which have matched the channel's message.
In order to leverage this pattern you will use the following two functions:
Pattern publishing and subscriptions are still not developed yet.
The return of the redisPublish()
function is numeric indicating how many subscribers received the message.
The redisSubscribe()
function returns a struct with two keys in it:
future
- A completable future that is running your subscriber.
subscriber
- The Java Redis subscriber object you can use to inspect the subscription or unsubscribe from the calls via the unsubscribe()
method.
If you will be passing a CFC to the redisSubscribe()
methods then you will need to implement some or all of the following functions.
Function | Description |
---|---|
RedisPublish( channel, message, cacheName )
Publish a message into Redis into a specific channel. Returns how many subscribers are listening to the message and channel.
RedisSubscribe( subscriber, channels, cacheName )
Subscribe to a channel for messages using a closure/lambda or a listener CFC. Returns a future
and a subscriber.