common

package
v0.0.0-...-50e54af Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(value interface{}) ([]byte, error)

func NewLockKey

func NewLockKey(key string) (lockKey string)

拼接锁key

func Unmarshal

func Unmarshal(b []byte, value interface{}) error

Types

type CacheIndex

type CacheIndex interface {
}

func NewCacheIndex

func NewCacheIndex(redis Rediser) CacheIndex

type LocalCache

type LocalCache interface {
	Set(key string, data []byte)
	Get(key string) ([]byte, bool)
	Del(key string)
}

type LockType

type LockType int
const (
	Writer LockType = 1
	Read   LockType = 2
)

type RedisLock

type RedisLock interface {
	// 加锁, 返回加锁是否成功
	TryLock(key string, val interface{}, ttl time.Duration, ctx context.Context) (bool, []byte, error)
	// 解锁
	UnLock(ctx context.Context, key string, val interface{}) error
	// 等待释放锁
	WaitUnLock(ctx context.Context, key string) (err error)
	// 续约
	RenewLock(ctx context.Context, key string, value interface{}, ttl time.Duration) (err error)
	// 加锁, 如果有锁,等待锁释放再添加锁
	WaitLock(key string, val interface{}, ttl time.Duration, ctx context.Context) (bool, error)
}

func NewRedisLock

func NewRedisLock(redis Rediser) RedisLock

type Rediser

type Rediser interface {
	redis.Cmdable
}

type TinyLFU

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

func NewTinyLFU

func NewTinyLFU(size int, ttl time.Duration) *TinyLFU

func (*TinyLFU) Del

func (c *TinyLFU) Del(key string)

func (*TinyLFU) Get

func (c *TinyLFU) Get(key string) ([]byte, bool)

func (*TinyLFU) Set

func (c *TinyLFU) Set(key string, b []byte)

func (*TinyLFU) UseRandomizedTTL

func (c *TinyLFU) UseRandomizedTTL(offset time.Duration)

Jump to

Keyboard shortcuts

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