redis

package
v1.0.4-snapshot Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitRedis

func InitRedis(ctx context.Context)

InitRedis 创建新的Redis客户端

Types

type AppConfigLoadedEventListener

type AppConfigLoadedEventListener struct{}

func (*AppConfigLoadedEventListener) GetOrder

func (ace *AppConfigLoadedEventListener) GetOrder() int

func (*AppConfigLoadedEventListener) OnApplicationEvent

func (ace *AppConfigLoadedEventListener) OnApplicationEvent(ctx context.Context, event *listener.AppConfigLoadedEvent)

type AppShutDownEventListener

type AppShutDownEventListener struct{}

func (*AppShutDownEventListener) GetOrder

func (l *AppShutDownEventListener) GetOrder() int

func (*AppShutDownEventListener) OnApplicationEvent

func (l *AppShutDownEventListener) OnApplicationEvent(ctx context.Context, event *listener.AppShutdownEvent)

type Client

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

Client Redis客户端结构体

func GetRedis

func GetRedis(ctx context.Context) *Client

GetRedis 获取Redis客户端

func (*Client) Close

func (r *Client) Close() error

Close 关闭Redis连接

func (*Client) Del

func (r *Client) Del(key string) error

Del 删除键

func (*Client) Get

func (r *Client) Get(key string) (string, error)

Get 获取键的值

func (*Client) HGet

func (r *Client) HGet(key, field string) (string, error)

HGet 获取哈希表字段值

func (*Client) HSet

func (r *Client) HSet(key, field, value string) error

HSet 设置哈希表字段

func (*Client) LPush

func (r *Client) LPush(key, value string) error

LPush 向列表左侧添加元素

func (*Client) LRange

func (r *Client) LRange(key string, start, end int64) ([]string, error)

LRange 获取列表指定范围内的元素

func (*Client) Set

func (r *Client) Set(key, value string, expiration time.Duration) error

Set 设置键值对

func (*Client) SetNX

func (r *Client) SetNX(key, value string, expiration time.Duration) (bool, error)

SetNX 设置键值对,如果键不存在则设置成功

type DistributedLock

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

DistributedLock 分布式锁结构体

func NewDistributedLock

func NewDistributedLock(key string, expiration time.Duration) *DistributedLock

NewDistributedLock 创建分布式锁实例

func (*DistributedLock) Lock

func (l *DistributedLock) Lock(ctx context.Context) (bool, error)

Lock 获取分布式锁

func (*DistributedLock) TryLock

func (l *DistributedLock) TryLock(ctx context.Context) (bool, error)

TryLock 获取分布式锁

func (*DistributedLock) Unlock

func (l *DistributedLock) Unlock(ctx context.Context) error

Unlock 释放分布式锁 ctx: 上下文 返回:错误信息

Jump to

Keyboard shortcuts

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