redismodule

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(ctx context.Context, key RedisKey) (string, error)

func GetAny

func GetAny(ctx context.Context, key RedisKey, object any) error

func GetAnyWithJson

func GetAnyWithJson(ctx context.Context, key RedisKey, object any) error

func GetBytes

func GetBytes(ctx context.Context, key RedisKey) ([]byte, error)

func LockWithDeadline

func LockWithDeadline(ctx context.Context, key string, lockTtl time.Duration, retryDeadline time.Time, retryInterval int, executable func()) error

LockWithDeadline 持续尝试获取锁 request lockTtl 获得锁之后的持续时长(超时自动释放)

retryDeadline 重试持续时间
retryInterval 重试间隔(millisecond)

func LockWithMaxRetry

func LockWithMaxRetry(ctx context.Context, key string, lockTtl time.Duration, retryMax, retryInterval int, executable func()) error

LockWithMaxRetry 持续尝试获取锁 request lockTtl 获得锁之后的持续时长(超时自动释放)

retryMax 尝试获取锁最大重试次数
intervalMil 重试间隔(millisecond)

func MGet

func MGet(ctx context.Context, keys ...RedisKey) ([]string, error)

func MGetAny

func MGetAny(ctx context.Context, object any, keys ...RedisKey) error

func MSet

func MSet(ctx context.Context, data map[RedisKey]string) error

MSet 批量设置字符串

func MSetBytes

func MSetBytes(ctx context.Context, data map[RedisKey][]byte) error

func RawClient

func RawClient() redis.UniversalClient

RawClient 获取原始RedisClient进行操作

func RawLockClient

func RawLockClient() *redislock.Client

func Set

func Set(ctx context.Context, key RedisKey, value string, expiration ...time.Duration) error

Set 设置字符串

func SetAny

func SetAny(ctx context.Context, key RedisKey, value interface{}, expiration ...time.Duration) error

SetAny 原始RedisClient Set指令 适用于设置基本类型&实现BinaryMarshaler的复杂结构体

func SetAnyWithJson

func SetAnyWithJson(ctx context.Context, key RedisKey, value any, expiration ...time.Duration) error

SetAnyWithJson 设置其他类型值 设置任何类型,将被以json格式进行编码存储

func SetBytes

func SetBytes(ctx context.Context, key RedisKey, value []byte, expiration ...time.Duration) error

SetBytes 设置字节

func TryLock

func TryLock(key string, lockTtl time.Duration, executable func()) error

TryLock 取锁并执行executable函数 request lockTtl: 获得锁之后的持续时长(超时自动释放)

func TryLockWithContext

func TryLockWithContext(ctx context.Context, key string, lockTtl time.Duration, executable func()) error

TryLockWithContext 取锁并执行executable函数

Types

type RedisKey

type RedisKey string

type RedisModule

type RedisModule struct {
	RedisConfig       *redis.UniversalOptions
	RedisModuleConfig *declaration.ModuleConfig

	// instance *redis.Client
	RedisInterceptor func(instance interface{})
}

func (*RedisModule) ModuleConfig

func (r *RedisModule) ModuleConfig() *declaration.ModuleConfig

func (*RedisModule) Register

func (r *RedisModule) Register() (interface{}, error)

func (*RedisModule) Unregister

func (r *RedisModule) Unregister(maxWaitSeconds uint) (gracefully bool, err error)

Jump to

Keyboard shortcuts

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