redis

package
v1.6.8 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package redis 对于redis进行封装

Package redis 对于redis进行封装

Package redis 对于redis进行封装

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLogHook

func NewLogHook(cfg *LogConfig) redis.Hook

NewLogHook is 初始化日志hook

func WrapRedisErr

func WrapRedisErr(err error) error

WrapRedisErr 包装redis错误

Types

type Client

type Client struct {
	*redis.Client
}

Client 对redis client进行封装

func NewClient

func NewClient(cfg *Config, ops ...Option) (c *Client, err error)

NewClient 初始化redisClient

func (*Client) GetObject

func (c *Client) GetObject(ctx context.Context, key string, obj any) error

GetObject 反序列化成obj对象

func (*Client) ScanKeys

func (c *Client) ScanKeys(ctx context.Context, match string) ([]string, error)

ScanKeys 扫描所有符合key

func (*Client) SetObjectEx

func (c *Client) SetObjectEx(ctx context.Context, key string, val any, expire time.Duration) error

SetObjectEx 设置一个对象,并且加入过期时间

type Config

type Config struct {
	Host             string     `json:"host"`
	Port             int        `json:"port"`
	DB               int        `json:"db"`
	Username         string     `json:"username,omitempty"`
	Password         string     `json:"password,omitempty"`
	KeyPrefix        string     `json:"key_prefix,omitempty"` // 这个值只提供给反序列化使用,对client实际无意义
	DisableLogHook   bool       `json:"disable_log_hook,omitempty"`
	DisableErrorHook bool       `json:"disable_error_hook,omitempty"`
	LogConfig        *LogConfig `json:"log_level,dive,omitempty"`
}

Config 表示redis配置项

type ErrorHook

type ErrorHook struct {
}

ErrorHook 错误hook

func NewErrorHook

func NewErrorHook() *ErrorHook

NewErrorHook 初始化错误hook

func (*ErrorHook) DialHook

func (r *ErrorHook) DialHook(next redis.DialHook) redis.DialHook

DialHook 实现Dial钩子

func (*ErrorHook) ProcessHook

func (r *ErrorHook) ProcessHook(next redis.ProcessHook) redis.ProcessHook

ProcessHook 实现处理钩子

func (*ErrorHook) ProcessPipelineHook

func (r *ErrorHook) ProcessPipelineHook(next redis.ProcessPipelineHook) redis.ProcessPipelineHook

ProcessPipelineHook 实现流水线钩子

type LogConfig

type LogConfig struct {
	Level      string `json:"level,omitempty"`
	MaxValSize int    `json:"max_val_size,omitempty"`
}

type LoggerHook

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

LoggerHook is 日志

func (*LoggerHook) DialHook

func (r *LoggerHook) DialHook(next redis.DialHook) redis.DialHook

DialHook 实现dial钩子

func (*LoggerHook) ProcessHook

func (r *LoggerHook) ProcessHook(next redis.ProcessHook) redis.ProcessHook

ProcessHook 实现处理钩子

func (*LoggerHook) ProcessPipelineHook

func (r *LoggerHook) ProcessPipelineHook(next redis.ProcessPipelineHook) redis.ProcessPipelineHook

ProcessPipelineHook 实现流水线钩子

type Option

type Option func(*redis.Options)

Jump to

Keyboard shortcuts

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