Documentation ¶
Index ¶
- Constants
- type Client
- func (c *Client) Connect()
- func (c *Client) GetState() uint8
- func (c *Client) Listener(kind ListenerType, event string) *Listener
- func (e *Client) On(ev EventType, h EventHandler)
- func (e *Client) OnChannel(ev EventType) chan Event
- func (e *Client) Once(ev EventType, h EventHandler)
- func (c *Client) Subscribe(listener *Listener)
- func (c *Client) TearDown()
- func (c *Client) Unsubscribe(listener *Listener)
- func (e *Client) WaitFor(ev EventType)
- type Event
- type EventHandler
- type EventType
- type Listener
- type ListenerType
Constants ¶
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) 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) Once ¶
func (e *Client) Once(ev EventType, h EventHandler)
Adds a handler that's executed once when an event is emitted.
func (*Client) Subscribe ¶
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 ¶
Removes the listener from the list of subscribers. If it's the last one listening to that Redis event, we unsubscribe entirely.
type Event ¶
type Event struct { Type EventType Packet interface{} }
The event is sent down the client's Events channel when something happens!
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.
type ListenerType ¶
type ListenerType uint8
Used to denote the type of listener - channel or pattern.
const ( Channel ListenerType = iota Pattern )