locker

package module
v0.0.0-...-7f364cc Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2019 License: MIT Imports: 7 Imported by: 0

README

go-locker

a very simple distributed locker for golang (use redis)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GoRedisEvalFunc

func GoRedisEvalFunc(ctx context.Context, script string, keys []string, args ...interface{}) (ret int, err error)

GoRedisEvalFunc ...eval func warpper for go-redis

func InitRedis

func InitRedis(ctx context.Context, opts *redis.ClusterOptions)

InitRedis init redis client (go-redis)

func SetRedis

func SetRedis(ctx context.Context, r redis.Cmdable)

SetRedis set redis client (go-redis)

Types

type EvalFunc

type EvalFunc func(ctx context.Context, script string, keys []string, values ...interface{}) (ret int, err error)

EvalFunc ...redis eval func

type Locker

type Locker interface {
	// Lock ...
	Lock() bool
	// Refresh ...
	// Refresh() error
	// Unlock ...
	Unlock() bool
	// GetValue return value of locker, i.e token for unlock
	GetValue() string
}

Locker .....

type LogFunc

type LogFunc func(ctx context.Context, args ...interface{})

LogFunc ...

type NewContextFunc

type NewContextFunc func(ctx context.Context) context.Context

NewContextFunc ...

type RedisLocker

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

RedisLocker ...

func NewRedisLocker

func NewRedisLocker(ctx context.Context, key string, val string, expire time.Duration) *RedisLocker

NewRedisLocker ...

func (*RedisLocker) GetValue

func (r *RedisLocker) GetValue() string

GetValue ...

func (*RedisLocker) Lock

func (r *RedisLocker) Lock() (locked bool)

Lock ...

func (*RedisLocker) SetDoEvalFunc

func (r *RedisLocker) SetDoEvalFunc(f EvalFunc)

SetDoEvalFunc 设置eval方法,请自行包装,适配各种redis library

func (*RedisLocker) SetLogErrorFunc

func (r *RedisLocker) SetLogErrorFunc(f LogFunc)

SetLogErrorFunc 设置输出错误日志的方法

func (*RedisLocker) SetLogFunc

func (r *RedisLocker) SetLogFunc(f LogFunc)

SetLogFunc 设置输出普通日志的方法

func (*RedisLocker) Unlock

func (r *RedisLocker) Unlock() (unlocked bool)

Unlock ...

Jump to

Keyboard shortcuts

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