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 one minute (and indefinitely until
# a message is received):
t1 <- proc.time()[[3]]
while(proc.time()[[3]] - t1 < 60)
{
print(redisGetResponse())
}
redisUnsubscribe(c('channel1','channel2'))
Run the code above in your browser using DataLab