redis

package
v0.0.0-...-122f59b Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnectionOptions

type ConnectionOptions struct {
	RedisURL              string
	MaxOpenConnection     *int
	MaxIdleConnection     *int
	IdleConnectionTimeout *config.DurationSeconds
	MaxConnectionLifetime *config.DurationSeconds
}

func (*ConnectionOptions) ConnKey

func (c *ConnectionOptions) ConnKey() string

type Handle

type Handle struct {
	ConnectionOptions ConnectionOptions
	// contains filtered or unexported fields
}

func NewHandle

func NewHandle(pool *Pool, connectionOptions ConnectionOptions, logger *log.Logger) *Handle

func (*Handle) Client

func (h *Handle) Client() *goredis.Client

func (*Handle) NewMutex

func (h *Handle) NewMutex(name string) *redsync.Mutex

func (*Handle) WithConn

func (h *Handle) WithConn(f func(conn *goredis.Conn) error) error

func (*Handle) WithConnContext

func (h *Handle) WithConnContext(ctx context.Context, f func(conn *goredis.Conn) error) error

type Hub

type Hub struct {
	Pool         *Pool
	Logger       *log.Logger
	SubscriberID *SubscriberID
	PubSub       map[string]*PubSub
	// Mailbox handles 3 messages.
	// This mailbox is never closed.
	Mailbox chan interface{}
}

Hub aims to multiplex multiple subscription to Redis PubSub channel over a single connection.

func NewHub

func NewHub(pool *Pool, lf *log.Factory) *Hub

func (*Hub) Subscribe

func (h *Hub) Subscribe(
	ConnectionOptions *ConnectionOptions,
	channelName string,
) Subscription

type HubMessagePubSubCancel

type HubMessagePubSubCancel struct {
	ConnKey      string
	SubscriberID int64
	ChannelName  string
}

type HubMessagePubSubDead

type HubMessagePubSubDead struct {
	ConnKey string
}

type HubMessageSubscribe

type HubMessageSubscribe struct {
	ConnectionOptions *ConnectionOptions
	ChannelName       string
	Result            chan Subscription
}

type Pool

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

func NewPool

func NewPool() *Pool

func (*Pool) Client

func (p *Pool) Client(connectionOptions *ConnectionOptions) *redis.Client

func (*Pool) Close

func (p *Pool) Close() (err error)

type PubSub

type PubSub struct {
	ConnKey           string
	SupervisorMailbox chan interface{}

	Logger     *log.Logger
	PubSub     *redis.PubSub
	Subscriber map[string][]Subscriber
	// Mailbox handles 3 messages.
	// 1. When the mailbox is closed, that means the actor should die.
	// 2. PubSubMessageJoin
	// 3. PubSubMessageLeave
	Mailbox chan interface{}
}

PubSub is an actor wrapping redis.PubSub

func NewPubSub

func NewPubSub(logger *log.Logger, client *redis.Client, connKey string, supervisorMailbox chan interface{}) *PubSub

NewPubSub creates a running PubSub actor.

type PubSubMessageJoin

type PubSubMessageJoin Subscriber

PubSubMessageJoin is essentially Subscriber.

type PubSubMessageLeave

type PubSubMessageLeave struct {
	ChannelName  string
	SubscriberID int64
}

PubSubMessageLeave is basically Subscriber without MessageChannel.

type Subscriber

type Subscriber struct {
	ChannelName  string
	SubscriberID int64
	// The drop pattern
	// See https://www.ardanlabs.com/blog/2017/10/the-behavior-of-channels.html
	MessageChannel chan *redis.Message
}

type SubscriberID

type SubscriberID struct {
	Counter int64
}

func (*SubscriberID) Next

func (i *SubscriberID) Next() int64

type Subscription

type Subscription struct {
	MessageChannel chan *redis.Message
	Cancel         func()
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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