redis

package module
v0.1.2 Latest Latest
Warning

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

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

README

go-redisson

go-redisson

redis client based on github.com/go-redis/redis/v8 .

Documentation

Index

Constants

View Source
const (
	LockScript      = "if redis.call('exists', KEYS[1]) == 0  then return redis.call('setex', KEYS[1], unpack(ARGV)) else return '-1' end"
	UnlockScript    = "if redis.call('get', KEYS[1]) == ARGV[1]  then return redis.call('del', KEYS[1]) or true end"
	RenewLockScript = "if redis.call('get', KEYS[1]) == ARGV[1]  then return redis.call('expire', KEYS[1],ARGV[2]) or true end"
	LockPrefix      = "lock:"
)
View Source
const (
	ConnTypeCluster  = "cluster"
	ConnTypeAlone    = "alone"
	ConnTypeSentinel = "sentinel"
)

Variables

View Source
var (
	ErrConnTypeUnknown = exception.New(-1, "unknown connect type")
	ErrPing            = exception.New(-2, "redis conn error")
	ErrNoReady         = exception.New(-3, "redis is not ready,please init it first")
)
View Source
var (
	ErrExitsLock           = exception.New(-4, "lock exits")
	ErrAcquiredLock        = exception.New(-5, "acquire lock error")
	ErrAcquiredLockTimeout = exception.New(-6, "acquire lock timeout error")
)

Functions

func InitNamedRedis

func InitNamedRedis(ctx context.Context, name string, c *conf.Config) (err error)

func InitOnceRedis

func InitOnceRedis(ctx context.Context, c *conf.Config) (err error)

func IsRedisReady

func IsRedisReady() bool

Types

type Redis

type Redis struct {
	gredis.UniversalClient
	*conf.Config
}

func GetNamedRedis

func GetNamedRedis(name string) *Redis

func GetRedis

func GetRedis() *Redis

func New

func New(ctx context.Context, c *conf.Config) (*Redis, error)

func (*Redis) GetLockScripter

func (r *Redis) GetLockScripter(ctx context.Context) *gredis.Script

func (*Redis) GetRenewScripter

func (r *Redis) GetRenewScripter(ctx context.Context) *gredis.Script

func (*Redis) GetUnlockScripter

func (r *Redis) GetUnlockScripter(ctx context.Context) *gredis.Script

func (*Redis) LoadLockScript

func (r *Redis) LoadLockScript(ctx context.Context) (*gredis.Script, error)

func (*Redis) LoadRenewScript

func (r *Redis) LoadRenewScript(ctx context.Context) (*gredis.Script, error)

func (*Redis) LoadUnLockScript

func (r *Redis) LoadUnLockScript(ctx context.Context) (*gredis.Script, error)

func (*Redis) Lock

func (r *Redis) Lock(ctx context.Context, lockName string, lockTime int64, acquireTime int) (string, error)

*

  • 获取锁 *
  • param: string lockName
  • param: int lockTime
  • param: int acquireTime
  • return: string

func (*Redis) LockSingle

func (r *Redis) LockSingle(ctx context.Context, lockName string, lockTime int64) (identifier string, err error)

*

  • 简单获取锁 *
  • param: string lockName
  • param: int lockTime
  • return: string
  • return: error

func (*Redis) LockWithId

func (r *Redis) LockWithId(ctx context.Context, lockName string, identifier string, lockTime int64, acquireTime int) (string, error)

*

  • 获取锁 *
  • param: string lockName
  • param: int lockTime
  • param: int acquireTime
  • return: string

func (*Redis) RenewLock

func (r *Redis) RenewLock(ctx context.Context, lockName, lockId string, renameTime int) (err error)

*

  • 延长锁 *
  • param: string lockName
  • param: string lockId
  • param: int renameTime
  • return: error

func (*Redis) Unlock

func (r *Redis) Unlock(ctx context.Context, lockName, lockId string) (err error)

*

  • 释放锁 *
  • param: string lockName
  • param: string lockId
  • return: error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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