redis

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2020 License: MIT Imports: 10 Imported by: 0

README

单元测试可以使用 https://github.com/alicebob/miniredis, 可以开启一个本地的模拟redis

Documentation

Index

Constants

View Source
const Nil = redis.Nil

Nil redis 返回为空

Variables

View Source
var RedisClient *redis.Client

RedisClient redis 客户端

Functions

func Init

func Init() *redis.Client

Init 实例化一个redis client

func InitTestRedis added in v1.0.3

func InitTestRedis()

InitTestRedis 实例化一个可以用于单元测试的redis

Types

type IdAlloc added in v1.2.0

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

IdAlloc id生成器

func (*IdAlloc) GetCurrentID added in v1.2.0

func (ia *IdAlloc) GetCurrentID() (int64, error)

GetCurrentID 获取当前id

func (*IdAlloc) GetKey added in v1.2.0

func (ia *IdAlloc) GetKey() string

GetKey 获取key, 由业务前缀+功能前缀+具体场景id组成

func (*IdAlloc) GetNewID added in v1.2.0

func (ia *IdAlloc) GetNewID(step int64) (int64, error)

GetNewID 生成id

type Lock added in v1.1.1

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

Lock 定义lock结构体

func New added in v1.1.1

func New(conn *redis.Client, key string, defaultTimeout time.Duration) *Lock

New 实例化

func NewLock added in v1.1.1

func NewLock(conn *redis.Client, key string, defaultTimeout time.Duration) *Lock

NewLock 实例化lock

func (*Lock) GenToken added in v1.1.1

func (l *Lock) GenToken() string

GenToken 生成token

func (*Lock) GetKey added in v1.1.1

func (l *Lock) GetKey() string

GetKey 获取key

func (*Lock) Lock added in v1.1.1

func (l *Lock) Lock(token string) (bool, error)

Lock 加锁

func (*Lock) Unlock added in v1.1.1

func (l *Lock) Unlock(token string) error

Unlock 解锁 token 一致才会执行删除,避免误删,这里用了lua脚本进行事务处理

Jump to

Keyboard shortcuts

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