Categorygithub.com/sandwich-go/distributedlocker
modulepackage
0.2.0-alpha.5
Repository: https://github.com/sandwich-go/distributedlocker.git
Documentation: pkg.go.dev

# README

distributedlocker

分布式锁

例子

package main

import (
	"context"
	"fmt"
	"github.com/sandwich-go/distributedlocker"
	"github.com/sandwich-go/distributedlocker/redis"
	"github.com/sandwich-go/redisson"
)

func main() {
	distributedlocker.MustNewDefaultLockerBuilder(redis.NewRedisson(&redisson.Conf{Resp: redisson.RESP2, Addrs: []string{"127.0.0.1:6379"}}))

	ctx := context.Background()
	key0 := "123"
	
	mu0 := distributedlocker.NewRWMutex(key0)
	if err := mu0.RLock(ctx); err != nil {
		fmt.Println(err)
		return
	}
	
	mu1 := distributedlocker.NewRWMutex(key0)
	if err := mu1.RLock(ctx); err != nil {
		fmt.Println(err)
		return
	}

	if err := mu0.RUnLock(ctx); err != nil {
		fmt.Println(err)
		return
	}

	if err := mu1.RUnLock(ctx); err != nil {
		fmt.Println(err)
		return
	}

	mu2 := distributedlocker.NewRWMutex(key0)
	if err := mu2.Lock(ctx); err != nil {
		fmt.Println(err)
		return
	}
	if err := mu2.UnLock(ctx); err != nil {
		fmt.Println(err)
		return
	}

	key1 := "456"
	mu3 := distributedlocker.NewMutex(key1)
	if err := mu3.Lock(ctx); err != nil {
		fmt.Println(err)
		return
	}
	if err := mu3.UnLock(ctx); err != nil {
		fmt.Println(err)
		return
	}
}

# Functions

No description provided by the author
InstallOptionsWatchDog the installed func will called when NewOptions called.
No description provided by the author
No description provided by the author
No description provided by the author
NewOptions new Options.
No description provided by the author
No description provided by the author
No description provided by the author
go:generate optionGen --option_return_previous=false --usage_tag_name=usage.
SetLogger is used to set the logger for critical errors.
WithAutoRenew 是否自动续期.
WithDriftFactor 有效时间因子.
WithExpiration 过期时间.
WithMaxRetryInterval 最大重试时间,不能大于250ms.
WithMinRetryInterval 最小重试时间,不能小于50ms.
WithPrefix key的前缀.
WithRetryTimes acquire lock重试次数.
WithTimeoutFactor 超时时间因子.

# Variables

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

Options should use NewOptions to initialize it.

# Interfaces

No description provided by the author
No description provided by the author
Logger is used to log critical error messages.
No description provided by the author
OptionsInterface visitor + ApplyOption interface for Options.
OptionsVisitor visitor interface for Options.
No description provided by the author

# Type aliases

Option option func.