Documentation ¶
Overview ¶
Package wublub implements a layer on top of redis subscriptions. Wublub clients can subscribe to arbitrary redis channels, whose publishes will be written to a channel the client passes in.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Opts ¶
type Opts struct { // Optional. Timeout to use when reading/writing subscription information to // redis. Defaults to 5 seconds. Timeout time.Duration // Optional. If false, when a publish occurs and is attempted to be written // to a subscribed channel, and that channel has no readers (and would // therefore block), the behavior is to not write to that channel and // continue on. If this is true, Wublub will instead block until that // channel can be written to. BlockOnPublish bool }
Opts are the options which can be passed in when initializing a Wublub instance using New.
type Publish ¶
Publish comprises all the information related to a publish event that a subscriber can receive
type Wublub ¶
type Wublub struct {
// contains filtered or unexported fields
}
Wublub is a container for all information needd to publish or subscribe with a backing redis instance. All methods on Wublub are thread-safe
func New ¶
New initializes a Wublub instance and returns it. Run should be called in order for the instance to actually do work. Opts may be nil
func (*Wublub) Run ¶
Run does the actual work of subscribing to redis channels and reading publishes of them. This must be called in order to use Wublub. It will create a new connection and block until an error is hit and returned. From there it is at the user's discretion to decide what to do, but it is recommended to simply call Run again on an error.
When an error is hit, all subscribed channels will continue to be subscribed, they don't have to do anything. Subsequent calls to Run will pick up where the previous ones left off.
stopCh is optional, and may be closed at any time to stop the Run and close the connection to redis it created. Run will return nil if this occurs
func (*Wublub) Subscribe ¶
Subscribe registers the given chan to receive Publishes from the given channels. The given chan should never be closed.
Note that if BlockOnPublish is set to true, it is recommended that you run this command in a separate go-routine than the one reading from the given channel, otherwise you may end up in a deadlock.
func (*Wublub) Unsubscribe ¶
Unsubscribe un-registers the given chan from receiving Publishes from the given channels. The given chan must have been used in a Subscribe previously for this to have any effect.
Note that if BlockOnPublish is set to true you should not stop reading from the given channel until this command has returned.