redisPub/Sub


Introduction

Redis provides an implementation of the Publish/Subscribe (Pub/Sub) messaging pattern. Instead of sending messages to specific receivers, Publishers send messages to interested receivers via some indirection mechanism. Receivers specify interest in particular messages. In Redis this functionality is accessed using the PUBLISH and SUBSCRIBE commands on channels.

Syntax

  • SUBSCRIBE channel [channel ...]
  • UNSUBSCRIBE [channel [channel ...]]
  • PUBLISH channel message
  • PSUBSCRIBE pattern [pattern ...]
  • PUNSUBSCRIBE [pattern [pattern ...]]

Remarks

To handle the pub/sub in redis, need to have one client for subscribe & different client for publish. Both can't be handled by same client. Though all other commands can be still handled with same client.