redis

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DefaultHost = "localhost:6379"
	Nil         = redis.Nil
)
View Source
const Locked = "1"

Variables

View Source
var LockTime = 15 * time.Second

Functions

func ClusterEnable

func ClusterEnable() bool

func DatabaseNumber

func DatabaseNumber() int

func IsLockFailure added in v0.0.7

func IsLockFailure(err error) bool

func IsNil

func IsNil(err error) bool

func Lock

func Lock(ctx context.Context, key string, expiration time.Duration) (bool, error)

func Ping

func Ping(ctx context.Context) error

func Primary

func Primary() redis.UniversalClient

func PrimaryEndpoint

func PrimaryEndpoint() string

func ReadOnly

func ReadOnly(ctx context.Context, f func(ctx context.Context, c redis.Cmdable) error, db ...int) (err error)

func Reader

func Reader() redis.Cmdable

func ReaderEndpoint

func ReaderEndpoint() string

func Refresh

func Refresh(ctx context.Context, b ...Builder) error

func ServerName added in v0.0.4

func ServerName() string

func Setup

func Setup(ctx context.Context, b Builder) error

func TlsEnable added in v0.0.4

func TlsEnable() bool

func Universal

func Universal(ctx context.Context, f func(ctx context.Context, c redis.Cmdable) error, db ...int) (err error)

func WaitForActivation

func WaitForActivation(ctx context.Context, waitMax ...int) error

func WithLock

func WithLock(ctx context.Context, key string, f func() error, tryMax ...int) error

Types

type Builder

type Builder interface {
	Build(ctx context.Context, db ...int) (*PrimaryClient, *ReaderClient, error)
}

type DefaultBuilder

type DefaultBuilder struct {
	ClusterEnable bool
	PrimaryHost   string
	ReaderHost    string
	TlsConfig     *tls.Config
}

func (*DefaultBuilder) Build

func (b *DefaultBuilder) Build(ctx context.Context, db ...int) (primary *PrimaryClient, reader *ReaderClient, err error)

type Env

type Env struct {
	RedisPrimaryEndpoint string `envar:"REDIS_PRIMARY_ENDPOINT;default=localhost:6379"`
	RedisReaderEndpoint  string `envar:"REDIS_READER_ENDPOINT"`
	RedisClusterEnable   bool   `envar:"REDIS_CLUSTER_ENABLE"`
	RedisDatabaseNumber  int    `envar:"REDIS_DATABASE_NUMBER;default=0"`
	TlsEnable            bool   `envar:"REDIS_TLS_ENABLE"`
	RedisServerName      string `envar:"REDIS_SERVER_NAME"`
}

type EnvBuilder

type EnvBuilder struct{}

func (*EnvBuilder) Build

func (b *EnvBuilder) Build(ctx context.Context, db ...int) (primary *PrimaryClient, reader *ReaderClient, err error)

type LockFailure added in v0.0.7

type LockFailure struct{}

func (*LockFailure) Error added in v0.0.7

func (err *LockFailure) Error() string

type MockBuilder

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

func (*MockBuilder) Build

func (b *MockBuilder) Build(ctx context.Context, db ...int) (primary *PrimaryClient, reader *ReaderClient, err error)

func (*MockBuilder) Mock

func (b *MockBuilder) Mock() redismock.ClientMock

type PrimaryClient

type PrimaryClient struct {
	Client redis.UniversalClient
	Db     int
}

func (PrimaryClient) Reset

func (c PrimaryClient) Reset(ctx context.Context, cmdable redis.StatefulCmdable) error

type ReaderClient

type ReaderClient struct {
	Client redis.Cmdable
	Db     int
}

func (ReaderClient) Reset

func (c ReaderClient) Reset(ctx context.Context, cmdable redis.StatefulCmdable) error

Jump to

Keyboard shortcuts

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