pubsub

package
v2.5.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2016 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Not currently connected to a server.
	DisconnectedState uint8 = iota
	// Connected to a server, but not yet linked as a pubsub client.
	ConnectedState
	// We're in the process of closing the client.
	ClosingState
	// We were connected, but closed gracefully.
	ClosedState
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

The Client is responsible for maintaining a subscribed redis client, reconnecting and resubscribing if it drops.

func New

func New(pool *redis.Pool, reconnectPolicy conn.ReconnectPolicy) *Client

Creates and returns a new pubsub client client and subscribes to it.

func (*Client) Connect

func (c *Client) Connect()

Tries to reconnect to pubsub, looping until we're able to do so successfully. This must be called to activate the client.

func (*Client) GetState

func (c *Client) GetState() uint8

Gets the current client state.

func (*Client) Listener

func (c *Client) Listener(kind ListenerType, event string) *Listener

Convenience function to create a new listener for an event.

func (*Client) On

func (e *Client) On(ev EventType, h EventHandler)

Adds a handler that's executed when an event happens.

func (*Client) OnChannel

func (e *Client) OnChannel(ev EventType) chan Event

Creates a channel that gets written to when a new event comes in.

func (*Client) Once

func (e *Client) Once(ev EventType, h EventHandler)

Adds a handler that's executed once when an event is emitted.

func (*Client) Subscribe

func (c *Client) Subscribe(listener *Listener)

Subscribes to a Redis event. Strings are sent back down the listener channel when they come in, and

func (*Client) TearDown

func (c *Client) TearDown()

Tears down the client - closes the connection and stops listening for connections.

func (*Client) Unsubscribe

func (c *Client) Unsubscribe(listener *Listener)

Removes the listener from the list of subscribers. If it's the last one listening to that Redis event, we unsubscribe entirely.

func (*Client) WaitFor

func (e *Client) WaitFor(ev EventType)

Blocks until an event is received. Mainly for backwards-compatibility.

type Event

type Event struct {
	Type   EventType
	Packet interface{}
}

The event is sent down the client's Events channel when something happens!

type EventHandler

type EventHandler func(Event)

A function which handles an incoming event.

type EventType

type EventType uint8

Events that are sent down the "Events" channel.

const (
	ConnectedEvent EventType = iota
	DisconnectedEvent
	ClosingEvent
	ClosedEvent
	MessageEvent
	SubscribeEvent
	UnsubscribeEvent
	ErrorEvent
	AnyEvent
)

type Listener

type Listener struct {
	// The event slug we're listening for.
	Event string
	// and its type
	Type ListenerType
	// The channel we send events down for plain subscriptions.
	Messages chan redis.Message
	// The channel we send events down for pattern subscriptions.
	PMessages chan redis.PMessage
	// The client it's attached to.
	Client *Client
	// Whether its active. True by default, false after unsubscribed.
	Active bool
}

The listener is used to keep track of events that the client is listening to.

func (*Listener) Resubscribe

func (l *Listener) Resubscribe()

Resubscribes the listener.

func (*Listener) Unsubscribe

func (l *Listener) Unsubscribe()

Unsubscribes the listener.

type ListenerType

type ListenerType uint8

Used to denote the type of listener - channel or pattern.

const (
	Channel ListenerType = iota
	Pattern
)

Jump to

Keyboard shortcuts

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