redis

package module
v0.0.0-...-e25a370 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: Apache-2.0 Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-locks/distlock 的 Redis 驱动。客户端使用 letsfire/redigo 实现,同时支持 alone cluster sentinel 3种部署模式。本驱动支持互斥锁 mutex 和读写锁 rwmutex。更多使用案例详见 examples

代码实例

Alone模式

var mode = alone.New(
	alone.Addr("192.168.0.110:6379"),
)
var redriver = New(redigo.New(mode))

Sentinel模式

var mode = sentinel.New(
	sentinel.Addrs([]string{"192.168.0.110:26379"}),
)
var redriver = New(redigo.New(mode))

Cluster模式

var mode = cluster.New(
	cluster.Nodes([]string{
        "192.168.0.110:30001", "192.168.0.110:30002", "192.168.0.110:30003",
        "192.168.0.110:30004", "192.168.0.110:30005", "192.168.0.110:30006",
    }),
)
var redriver = New(redigo.New(mode))

所有模式都支持指定多个实例,在过半实例上获取成功才算加锁成功,解决单点故障问题,如下示例

// 至少在2个节点上加锁成功才算获取到锁
var mode1 = alone.New(
	alone.Addr("192.168.0.110:6379"),
)
var mode2 = alone.New(
	alone.Addr("192.168.0.111:6379"),
)
var mode3 = alone.New(
	alone.Addr("192.168.0.112:6379"),
)
var redriver = New(redigo.New(mode1), redigo.New(mode2), redigo.New(mode3))

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MaxReaders            = 1 << 30
	MinWatchRetryInterval = time.Millisecond
	MaxWatchRetryInterval = time.Second * 16
)

Functions

func New

func New(redigo ...*redigo.Client) *redisDriver

Types

This section is empty.

Jump to

Keyboard shortcuts

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