redisMonitorChannels: redisMonitorChannels

Description Usage Details Value Author(s) References See Also Examples

Description

Subscribe to one or more Redis message channels.

Usage

1

Details

(From the Redis.io documentation): redisSubscribe, redisUnsubscribe and redisPublish implement the Publish/Subscribe messaging paradigm where (citing Wikipedia) senders (publishers) are not programmed to send their messages to specific receivers (subscribers). Rather, published messages are characterized into channels, without knowledge of what (if any) subscribers there may be. Subscribers express interest in one or more channels, and only receive messages that are of interest, without knowledge of what (if any) publishers there are.

The redisMonitorChannels function may be called repeatedly in an event loop to service messages on all subscribed channels. When a message is received, the redisMonitorChannels function will attempt to evaluate a callback function with same name as the channel, with the message as its single argument. If no such function can be found, the message is returned. See the help page for redisGetResponse for a description of the message format.

WARNING: The redisMonitorChannels function blocks indefinitely until a message is received.

Use the lower-level redisGetResponse function to simply poll channels for messages without evaluating function callbacks.

Value

The result of an evaluated function callback message, or if no matching callback exists, the message.

Author(s)

B. W. Lewis

References

http://redis.io/commands

See Also

redisSubscribe redisPublish redisUnsubscribe redisGetResponse

redisMonitorChannels

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
## Not run: 
redisConnect()
# Define a callback function to process messages from channel 1:
channel1 <- function(x) {
  cat("Message received from channel 1: ",x,"\n")
}
# Define a callback function to process messages from channel 2:
channel2 <- function(x) {
  cat("Message received from channel 2: ",x,"\n")
}
redisSubscribe(c('channel1','channel2'))
# Monitor channels for at least 1 minute:
t1 <- proc.time()[[3]]
while(proc.time()[[3]] - t1 < 60)
{
  redisMonitorChannels()
  Sys.sleep(0.05)
}
redisUnsubscribe(c('channel1','channel2'))

## End(Not run)

rredis documentation built on May 2, 2019, 2:02 p.m.