pubsub

package
v0.0.0-...-1d6235d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 1, 2015 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package pubsub provides a wrapper around a normal redis client which makes interacting with publish/subscribe commands much easier

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SubClient

type SubClient struct {
	Client *redis.Client
	// contains filtered or unexported fields
}

SubClient wraps a Redis client to provide convenience methods for Pub/Sub functionality.

func NewSubClient

func NewSubClient(client *redis.Client) *SubClient

NewSubClient takes an existing, connected redis.Client and wraps it in a SubClient, returning that. The passed in redis.Client should not be used as long as the SubClient is also being used

func (*SubClient) PSubscribe

func (c *SubClient) PSubscribe(patterns ...interface{}) *SubResp

PSubscribe makes a Redis "PSUBSCRIBE" command on the provided patterns

func (*SubClient) PUnsubscribe

func (c *SubClient) PUnsubscribe(patterns ...interface{}) *SubResp

PUnsubscribe makes a Redis "PUNSUBSCRIBE" command on the provided patterns

func (*SubClient) Receive

func (c *SubClient) Receive() *SubResp

Receive returns the next publish resp on the Redis client. It is possible Receive will timeout, and the *SubResp will be an Error. You can use the Timeout() method on SubResp to easily determine if that is the case. If this is the case you can call Receive again to continue listening for publishes

func (*SubClient) Subscribe

func (c *SubClient) Subscribe(channels ...interface{}) *SubResp

Subscribe makes a Redis "SUBSCRIBE" command on the provided channels

func (*SubClient) Unsubscribe

func (c *SubClient) Unsubscribe(channels ...interface{}) *SubResp

Unsubscribe makes a Redis "UNSUBSCRIBE" command on the provided channels

type SubResp

type SubResp struct {
	*redis.Resp // Original Redis resp

	Type     SubRespType
	Channel  string // Channel resp is on (Message)
	Pattern  string // Pattern which was matched for publishes captured by a PSubscribe
	SubCount int    // Count of subs active after this action (Subscribe or Unsubscribe)
	Message  string // Publish message (Message)
	Err      error  // SubResp error (Error)
}

SubResp wraps a Redis resp and provides convienient access to Pub/Sub info.

func (*SubResp) Timeout

func (r *SubResp) Timeout() bool

Timeout determines if this SubResp is an error type due to a timeout reading from the network

type SubRespType

type SubRespType uint8

SubRespType describes the type of the response being returned from one of the methods in this package

const (
	Error SubRespType = iota
	Subscribe
	Unsubscribe
	Message
)

The different kinds of SubRespTypes

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL