bizredis

package
v0.0.0-...-e6d59a1 Latest Latest
Warning

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

Go to latest
Published: May 11, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DurationFromNow

func DurationFromNow(future time.Time) time.Duration

func NewKey

func NewKey(raw string, prefix string) *key

func NewRedis

func NewRedis(conf BizRedisConf) *redisClient

Types

type BasicCacher

type BasicCacher interface {
	Prefix() string

	Has(key string) bool
	Get(key string, defaultValue ...interface{}) interface{}
	Pull(key string, defaultValue ...interface{}) interface{}
	Put(key string, value interface{}, future time.Time) bool
	Add(key string, value interface{}, future time.Time) bool
	Increment(key string, value int64) (incremented int64, success bool)
	Decrement(key string, value int64) (decremented int64, success bool)
	Forever(key string, value interface{}) bool
	Forget(key string) bool

	Close() error
}

type BizRedisConf

type BizRedisConf struct {
	Host     string
	Port     int
	Password string `json:",optional"`
	Db       int
	Prefix   string `json:",optional"`
}

type Locker

type Locker interface {
	Acquire() (bool, error)                       // Acquire acquires the lock.
	AcquireCtx(ctx context.Context) (bool, error) // AcquireCtx acquires the lock with the given ctx.
	Release() (bool, error)                       // Release releases the lock.
	ReleaseCtx(ctx context.Context) (bool, error) // ReleaseCtx releases the lock with the given ctx.
	SetExpire(seconds int)                        // SetExpire sets the expiration.
}

type RedisClient

type RedisClient interface {
	Client() *redis.Client
	BasicCacher
	RedisScripter
}

type RedisLock

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

A RedisLock is a redis lock.

func NewRedisLock

func NewRedisLock(store RedisScripter, key string) *RedisLock

NewRedisLock returns a RedisLock.

func (*RedisLock) Acquire

func (rl *RedisLock) Acquire() (bool, error)

Acquire acquires the lock.

func (*RedisLock) AcquireCtx

func (rl *RedisLock) AcquireCtx(ctx context.Context) (bool, error)

AcquireCtx acquires the lock with the given ctx.

func (*RedisLock) Release

func (rl *RedisLock) Release() (bool, error)

Release releases the lock.

func (*RedisLock) ReleaseCtx

func (rl *RedisLock) ReleaseCtx(ctx context.Context) (bool, error)

ReleaseCtx releases the lock with the given ctx.

func (*RedisLock) SetExpire

func (rl *RedisLock) SetExpire(seconds int)

SetExpire sets the expiration.

type RedisNode

type RedisNode interface {
	red.Cmdable
}

RedisNode interface represents a redis node.

type RedisScripter

type RedisScripter interface {
	ScriptLoad(script string) (string, error)                                                          // ScriptLoad is the implementation of redis script load command.
	ScriptLoadCtx(ctx context.Context, script string) (string, error)                                  // ScriptLoadCtx is the implementation of redis script load command.
	ScriptRun(script *Script, keys []string, args ...any) (any, error)                                 // ScriptRun is the implementation of *redis.Script run command.
	ScriptRunCtx(ctx context.Context, script *Script, keys []string, args ...any) (val any, err error) // ScriptRunCtx is the implementation of *redis.Script run command.
}

type Script

type Script = red.Script

Script is an alias of redis.Script.

func NewScript

func NewScript(script string) *Script

NewScript returns a new Script instance.

Jump to

Keyboard shortcuts

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