rdb

package
v1.0.51 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package rdb Redis工具.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrLock   = errors.New("is lock")
	ErrExpire = errors.New("expire time too long")
)

Functions

This section is empty.

Types

type InstanceNum added in v0.5.41

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

InstanceNum 实例数量.

func NewInstanceNum added in v0.5.41

func NewInstanceNum(client redis.Cmdable) *InstanceNum

NewInstanceNum 新建实例数量.

func NewInstanceNumByKey added in v0.5.41

func NewInstanceNumByKey(client redis.Cmdable, key string) *InstanceNum

func (*InstanceNum) Num added in v0.5.42

func (p *InstanceNum) Num() int

Num 实例数量.

func (*InstanceNum) Register added in v0.5.41

func (p *InstanceNum) Register(observer chan<- uint64)

Register 订阅主题.

func (*InstanceNum) Run added in v0.5.41

func (p *InstanceNum) Run()

Run 运行.

使用 redis INCR 命令计算一秒内增加的数量得出实例数量.

type Locker added in v0.5.40

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

Locker 分布式锁.

Example

nolint: testableexamples

client := redis.NewClient(&redis.Options{
	Addr:     "192.168.1.11:6379",
	Password: "",
	DB:       0,
})
locker := rdb.NewLocker(client)

_ = locker.Lock("test", func() error {
	// do something
	return nil
})
Output:

func NewLocker added in v0.5.40

func NewLocker(client redis.Cmdable, times ...time.Duration) *Locker

NewLocker 新建分布式锁. times[0] 锁时间, times[1] 续期间隔.

func (*Locker) Lock added in v0.5.40

func (p *Locker) Lock(key string, yield func() error) error

Lock 锁成功则执行,执行完毕解锁.

Directories

Path Synopsis
nolint
nolint

Jump to

Keyboard shortcuts

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