redigo

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2025 License: MIT Imports: 10 Imported by: 1

README

redigo

redis go client

Documentation

Index

Constants

View Source
const (
	RedisOK = "OK"
)

Variables

View Source
var (
	ErrKeyExists             = errors.New("key already exists")
	ErrKeyNotExists          = errors.New("key does not exist")
	ErrInvalidResponse       = errors.New("invalid response from server")
	ErrLockAcquisitionFailed = errors.New("failed to acquire lock")
	ErrLockNotHeld           = errors.New("lock not held by this instance")
)

Functions

This section is empty.

Types

type ListOption

type ListOption func(*listOptions)

func WithBlock

func WithBlock() ListOption

func WithRright

func WithRright() ListOption

func WithUnwind

func WithUnwind() ListOption

type Lock

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

Lock represents a distributed lock

type Option

type Option func(*redigoOptions)

func WithAddress

func WithAddress(address string) Option

func WithClientName

func WithClientName(clientName string) Option

func WithConnTimeout

func WithConnTimeout(connTimeout time.Duration) Option

func WithDB

func WithDB(db int) Option

func WithIdleTimeout

func WithIdleTimeout(idleTimeout time.Duration) Option

func WithMaxActive

func WithMaxActive(maxActive int) Option

func WithMaxConnLifetime

func WithMaxConnLifetime(maxConnLifetime time.Duration) Option

func WithMaxIdle

func WithMaxIdle(maxIdle int) Option

func WithPassword

func WithPassword(password string) Option

func WithSkipVerify

func WithSkipVerify(skipVerify bool) Option

func WithTLSConfig

func WithTLSConfig(tlsConfig *tls.Config) Option

func WithUseTLS

func WithUseTLS(useTLS bool) Option

func WithWait

func WithWait(wait bool) Option

type Redigo

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

func NewRedigo

func NewRedigo(opts ...Option) *Redigo

func (*Redigo) BlockLock

func (r *Redigo) BlockLock(key string, expiry time.Duration) (func() error, error)

BlockLock acquires a distributed lock in blocking mode It returns an unlock function and an error if failed to acquire lock

func (*Redigo) Decr

func (r *Redigo) Decr(key string, v ...int64) (reply any, err error)

func (*Redigo) Del

func (r *Redigo) Del(key string) (int64, error)

func (*Redigo) Do

func (r *Redigo) Do(cmd string, args ...any) (any, error)

func (*Redigo) Exists

func (r *Redigo) Exists(key string) (bool, error)

func (*Redigo) Expire

func (r *Redigo) Expire(key string, expiration time.Duration) error

func (*Redigo) Get

func (r *Redigo) Get(key string, v any) error

func (*Redigo) Incr

func (r *Redigo) Incr(key string, v any) (reply any, err error)

Incr increment the value of a key by 1 if v is nil, otherwise v must be an integer or float number

func (*Redigo) ListLen

func (r *Redigo) ListLen(key string) (n int64, err error)

func (*Redigo) ListPop

func (r *Redigo) ListPop(key string, n int, v any, opts ...ListOption) (err error)

阻塞模式(BRPOP/BLPOP) n表示超时时间(s), 否则n表示取值个数

func (*Redigo) ListPush

func (r *Redigo) ListPush(key string, v any, opts ...ListOption) (ret int64, err error)

func (*Redigo) ListRange

func (r *Redigo) ListRange(key string, start, stop int64, v any) (err error)

func (*Redigo) Set

func (r *Redigo) Set(key string, v any, opts ...SetOption) error

func (*Redigo) TTL

func (r *Redigo) TTL(key string) (int64, error)

func (*Redigo) TryLock

func (r *Redigo) TryLock(key string, expiry time.Duration, timeout time.Duration) (func() error, error)

TryLock tries to acquire a distributed lock with a timeout It returns an unlock function and an error if failed to acquire lock within timeout

type SetOption

type SetOption func(*setOptions)

func WithEX

func WithEX(expire int64) SetOption

WithEX set EX option

func WithNX

func WithNX() SetOption

WithNX set NX option

func WithPX

func WithPX(px int64) SetOption

WithPX set PX option

func WithXX

func WithXX() SetOption

WithXX set XX option

Jump to

Keyboard shortcuts

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