utils

package
v0.0.0-...-cc9b1f3 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLockName

func GetLockName(prefix string, collectionNum int32, key string) string

GetLockName returns a lock name with the prefix

Types

type LocalLock

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

LocalLock is used for local locking in a single server

func GetLocalLock

func GetLocalLock(ctx iface.OrdaContext, lockName string) *LocalLock

GetLocalLock returns a LocalLock with the specified name

func (*LocalLock) TryLock

func (its *LocalLock) TryLock() bool

TryLock tries to a local lock, and returns true if it succeeds; otherwise false

func (*LocalLock) Unlock

func (its *LocalLock) Unlock() bool

Unlock unlocks the local lock, and returns true if it succeeds; otherwise false

type Lock

type Lock interface {
	TryLock() bool
	Unlock() bool
}

Lock defines the lock interfaces

type RedisLock

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

RedisLock is used for distributed locking among multiple servers

func GetRedisLock

func GetRedisLock(ctx iface.OrdaContext, lockName string, rs *redsync.Redsync) *RedisLock

GetRedisLock returns a RedisLock with the specified name

func (*RedisLock) TryLock

func (its *RedisLock) TryLock() bool

TryLock tries to lock by redis, and returns true if it succeeds; otherwise false

func (*RedisLock) Unlock

func (its *RedisLock) Unlock() bool

Unlock unlocks the redis lock, and returns true if it succeeds; otherwise false

Jump to

Keyboard shortcuts

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