redis

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2023 License: MIT Imports: 5 Imported by: 1

Documentation

Overview

Package redis implements a Celery broker using Redis and github.com/gomodule/redigo.

Index

Constants

View Source
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

func (br *Broker) Observe(queues []string)

Observe sets the queues from which the tasks should be received.

func (*Broker) Receive

func (br *Broker) Receive() ([]byte, error)

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/.

func (*Broker) Send

func (br *Broker) Send(m []byte, q string) error

Send inserts the specified message at the head of the queue using LPUSH command.

type BrokerOption

type BrokerOption func(*Broker)

BrokerOption sets up a Broker.

func WithPool

func WithPool(pool *redis.Pool) BrokerOption

WithPool sets Redis connection pool.

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.

Note, the read timeout you specified with redis.DialReadTimeout() method should be bigger than the receive timeout. Otherwise redigo would return i/o timeout error.

Jump to

Keyboard shortcuts

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