redis

package
v0.0.0-...-f83813f Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: Apache-2.0 Imports: 10 Imported by: 2

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) WithConnContext

func (h *Handle) WithConnContext(ctx context.Context, do func(ctx context.Context, conn Redis_6_0_Cmdable) 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(ctx context.Context, 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(ctx context.Context, 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 Redis_6_0_Cmdable

type Redis_6_0_Cmdable interface {
	Del(ctx context.Context, keys ...string) *goredis.IntCmd

	Get(ctx context.Context, key string) *goredis.StringCmd

	Set(ctx context.Context, key string, value interface{}, expiration time.Duration) *goredis.StatusCmd
	SetEx(ctx context.Context, key string, value interface{}, expiration time.Duration) *goredis.StatusCmd
	SetNX(ctx context.Context, key string, value interface{}, expiration time.Duration) *goredis.BoolCmd
	SetXX(ctx context.Context, key string, value interface{}, expiration time.Duration) *goredis.BoolCmd

	Expire(ctx context.Context, key string, expiration time.Duration) *goredis.BoolCmd
	ExpireAt(ctx context.Context, key string, tm time.Time) *goredis.BoolCmd

	Incr(ctx context.Context, key string) *goredis.IntCmd
	IncrBy(ctx context.Context, key string, value int64) *goredis.IntCmd

	PExpireAt(ctx context.Context, key string, tm time.Time) *goredis.BoolCmd

	XAdd(ctx context.Context, a *goredis.XAddArgs) *goredis.StringCmd

	HDel(ctx context.Context, key string, fields ...string) *goredis.IntCmd
	HSet(ctx context.Context, key string, values ...interface{}) *goredis.IntCmd
	HGetAll(ctx context.Context, key string) *goredis.MapStringStringCmd

	LPush(ctx context.Context, key string, values ...interface{}) *goredis.IntCmd
	BRPop(ctx context.Context, timeout time.Duration, keys ...string) *goredis.StringSliceCmd

	// HyperLogLog.
	PFCount(ctx context.Context, keys ...string) *goredis.IntCmd
	PFAdd(ctx context.Context, key string, els ...interface{}) *goredis.IntCmd

	// For lua script
	Eval(ctx context.Context, script string, keys []string, args ...interface{}) *goredis.Cmd
	EvalSha(ctx context.Context, sha1 string, keys []string, args ...interface{}) *goredis.Cmd
	EvalRO(ctx context.Context, script string, keys []string, args ...interface{}) *goredis.Cmd
	EvalShaRO(ctx context.Context, sha1 string, keys []string, args ...interface{}) *goredis.Cmd
	ScriptExists(ctx context.Context, hashes ...string) *goredis.BoolSliceCmd
	ScriptLoad(ctx context.Context, script string) *goredis.StringCmd
}

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