Documentation ¶
Overview ¶
Package goredis implements a Celery broker using Redis and https://github.com/redis/go-redis.
Index ¶
Constants ¶
const DefaultReceiveTimeout = 5
DefaultReceiveTimeout defines how many seconds the broker's Receive command should block waiting for results from Redis.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Broker ¶
type Broker struct {
// contains filtered or unexported fields
}
Broker is a Redis broker that sends/receives messages from specified queues.
func NewBroker ¶
func NewBroker(options ...BrokerOption) *Broker
NewBroker creates a broker backed by Redis. By default, it connects to localhost.
func (*Broker) Observe ¶
Observe sets the queues from which the tasks should be received. Note, the method is not concurrency safe.
func (*Broker) Receive ¶
Receive fetches a Celery task message from a tail of one of the queues in Redis. After a timeout it returns nil, nil.
Celery relies on BRPOP command to process messages fairly, see https://github.com/celery/kombu/issues/166. Redis BRPOP is a blocking list pop primitive. It blocks the connection when there are no elements to pop from any of the given lists. An element is popped from the tail of the first list that is non-empty, with the given keys being checked in the order that they are given, see https://redis.io/commands/brpop/.
Note, the method is not concurrency safe.
type BrokerOption ¶
type BrokerOption func(*Broker)
BrokerOption sets up a Broker.
func WithClient ¶
func WithClient(c *redis.Client) BrokerOption
WithClient sets Redis client representing a pool of connections.
func WithReceiveTimeout ¶
func WithReceiveTimeout(timeout time.Duration) BrokerOption
WithReceiveTimeout sets a timeout of how long the broker's Receive command should block waiting for results from Redis. Larger the timeout, longer the client will have to wait for Celery app to exit. Smaller the timeout, more BRPOP commands would have to be sent to Redis.