pubsub

package
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2021 License: MIT Imports: 4 Imported by: 2

Documentation

Overview

The pubsub package provides a wrapper around a normal redis client which makes interacting with 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

func (*SubClient) PSubscribe

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

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

func (*SubClient) PUnsubscribe

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

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

func (*SubClient) Receive

func (c *SubClient) Receive() *SubReply

Receive returns the next publish reply on the Redis client. It is possible Receive will timeout, and the *SubReply will be an ErrorReply. You can use the Timeout() method on SubReply 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{}) *SubReply

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

func (*SubClient) Unsubscribe

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

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

type SubReply

type SubReply struct {
	Type     SubReplyType // SubReply type
	Channel  string       // Channel reply is on (MessageReply)
	Pattern  string       // The pattern that was matched by this reply, if PSubscribe was used
	SubCount int          // Count of subs active after this action (SubscribeReply or UnsubscribeReply)
	Message  string       // Publish message (MessageReply)
	Err      error        // SubReply error (ErrorReply)
	Reply    *redis.Reply // Original Redis reply (MessageReply)
}

SubReply wraps a Redis reply and provides convienient access to Pub/Sub info.

func (*SubReply) Timeout

func (r *SubReply) Timeout() bool

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

type SubReplyType

type SubReplyType uint8
const (
	ErrorReply SubReplyType = iota
	SubscribeReply
	UnsubscribeReply
	MessageReply
)

Jump to

Keyboard shortcuts

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