redisx

package
v0.0.0-...-3f0fe96 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

pkg/redisx/redisx.go

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotInitialized = errors.New("redis not initialized")
)

Functions

func Client

func Client() (redis.UniversalClient, error)

func Close

func Close() error

func Del

func Del(ctx context.Context, keys ...string) (int64, error)

func Exists

func Exists(ctx context.Context, keys ...string) (int64, error)

func GetJSON

func GetJSON(ctx context.Context, key string, out any) error

func GetString

func GetString(ctx context.Context, key string) (string, error)

func HGet

func HGet(ctx context.Context, key, field string) (string, error)

func HSet

func HSet(ctx context.Context, key string, values ...any) error

func IncrBy

func IncrBy(ctx context.Context, key string, n int64) (int64, error)

func Init

func Init(cfg Config) error

func MustClient

func MustClient() redis.UniversalClient

MustClient 与 RDB 等价:返回已初始化的客户端(未初始化将 panic)

func RDB

func RDB() redis.UniversalClient

RDB 返回已初始化的原生 redis.UniversalClient(未初始化将 panic)

func Set

func Set(ctx context.Context, key string, val any, ttl time.Duration) error

func SetJSON

func SetJSON(ctx context.Context, key string, v any, ttl time.Duration) error

SetJSON JSON 存取(常用)

func TTL

func TTL(ctx context.Context, key string) (time.Duration, error)

func TryClient

func TryClient() (redis.UniversalClient, bool)

TryClient 返回客户端和是否已初始化的布尔值(不 panic 的尝试式获取)

Types

type Config

type Config struct {
	Mode         string   // "", "single", "cluster"
	Addr         string   // 单点
	Addrs        []string // 集群
	Password     string
	DB           int
	PoolSize     int
	DialTimeout  time.Duration
	ReadTimeout  time.Duration
	WriteTimeout time.Duration
}

Jump to

Keyboard shortcuts

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