redis

package
v0.0.0-...-e964040 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// RandomExpiry 0-24h 随机过期时间
	RandomExpiry = func() time.Duration {
		return time.Duration(rand.Intn(86400)) * time.Second
	}
)

Functions

func Client

func Client() *rkv

Client .

func Close

func Close() error

Close .

func Init

func Init(opts ...func(o *Options)) error

Init .

func NewClient

func NewClient(opts ...func(o *Options)) (*rkv, error)

NewClient .

Types

type ClientType

type ClientType string
const (
	RedisClient  ClientType = "client"
	RedisCluster ClientType = "cluster"
)

type DelOptions

type DelOptions struct {
	Context context.Context
}

DelOptions .

type ExpireOptions

type ExpireOptions struct {
	Context context.Context
	// TTL key 过期时间
	TTL time.Duration
	// Expiry key 过期时间。TTL 和 Expiry 同时设置时,以 Expiry 为准
	Expiry time.Time
}

ExpireOptions .

type GetOptions

type GetOptions struct {
	Context context.Context
	// Marshaler value 编码方式
	Marshaler codec.Marshaler
}

GetOptions .

type Input

type Input struct {
	Key string      `json:"key"`
	Val interface{} `json:"val"`
}

Input .

type Key

type Key func(key string) string

Key 添加 key 的前缀或后缀

func KeyPrefix

func KeyPrefix(prefix string) Key

KeyPrefix .

func KeySuffix

func KeySuffix(suffix string) Key

KeySuffix .

func (Key) Key

func (k Key) Key(key string) string

Key .

type Mutex

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

Mutex redis 分布式锁

func (Mutex) Close

func (r Mutex) Close() error

func (Mutex) Del

func (r Mutex) Del(key string, opts ...func(o *DelOptions)) error

Del .

func (Mutex) Expire

func (r Mutex) Expire(key string, opts ...func(o *ExpireOptions)) error

Expire .

func (Mutex) Get

func (r Mutex) Get(key string, opts ...func(o *GetOptions)) (Output, error)

Get .

func (Mutex) IsExists

func (r Mutex) IsExists(key string, opts ...func(o *GetOptions)) bool

IsExists .

func (*Mutex) Lock

func (m *Mutex) Lock()

Lock .

func (Mutex) Mutex

func (r Mutex) Mutex(key string, opts ...func(o *MutexOptions)) *Mutex

Mutex .

func (Mutex) Set

func (r Mutex) Set(rec *Input, opts ...func(o *SetOptions)) error

Set .

func (*Mutex) Unlock

func (m *Mutex) Unlock()

Unlock .

type MutexOptions

type MutexOptions struct {
	Context context.Context
	// Mark 分布式锁标记
	Mark string
	// Heartbeat 尝试获取锁的时间间隔
	Heartbeat time.Duration
	// TTL 超时时间
	TTL time.Duration
}

MutexOptions .

type Options

type Options struct {
	Context context.Context
	// Type client or cluster
	Type     ClientType
	Addrs    []string
	Username string
	Password string
	// Timeout second
	Timeout time.Duration
	// MaxRetries 命令执行失败时的重试次数
	MaxRetries int
}

Options .

type Output

type Output interface {
	Key() string
	RawMessage() []byte
	TTL() time.Duration
	Expiry() time.Time
	Unmarshal(v interface{}) error
}

type SetOptions

type SetOptions struct {
	Context context.Context
	// TTL key 过期时间
	TTL time.Duration
	// Expiry key 过期时间。TTL 和 Expiry 同时设置时,以 Expiry 为准
	Expiry time.Time
	// Marshaler value 编码方式
	Marshaler codec.Marshaler
}

SetOptions .

Jump to

Keyboard shortcuts

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