tools

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2023 License: MIT Imports: 6 Imported by: 0

README

tiny_redis_tools

go-tiny-tools

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RedisClient

type RedisClient interface {
	Expire(ctx context.Context, key string, expiration time.Duration) *redis.BoolCmd
	Del(ctx context.Context, key ...string) *redis.IntCmd
	SetNX(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.BoolCmd
	Eval(ctx context.Context, script string, keys []string, args ...interface{}) *redis.Cmd
}

type RedisLock

type RedisLock struct {
	Client RedisClient
	Key    string
	// contains filtered or unexported fields
}

func NewRedisLock

func NewRedisLock(client RedisClient, key string) (*RedisLock, error)

NewRedisLock new a redis distribute lock

func (*RedisLock) SpinLock

func (rl *RedisLock) SpinLock(ctx context.Context, retryTimes int) (bool, error)

SpinLock Loop `retryTimes` times to call TryLock

func (*RedisLock) TryLock

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

TryLock attempt to lock, return true if the lock is successful, otherwise false

func (*RedisLock) Unlock

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

Unlock release the lock

type RedisTools

type RedisTools struct {
	Client RedisClient
}

func NewTools

func NewTools(client RedisClient) *RedisTools

func (*RedisTools) Cad

func (r *RedisTools) Cad(ctx context.Context, key string, value interface{}) (bool, error)

Cad compare and delete

func (*RedisTools) Cas

func (r *RedisTools) Cas(ctx context.Context, key string, oldValue interface{}, newValue interface{}) (bool, error)

Cas compare and swap

func (*RedisTools) CasEx

func (r *RedisTools) CasEx(ctx context.Context, key string, oldValue interface{},
	newValue interface{}, expire time.Duration) (bool, error)

CasEx compare and swap with timeout, If the timeout is 0, the timeout is not set, If the timeout is -1, keep timeout (redis >= 6.0).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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