rediscli

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect

func Connect(addr string, options ...Option)

Connect 连接redis

func Del added in v0.10.0

func Del(ctx context.Context, key string) (err error)

Del 删除key

func Get

func Get[T RedisValueTypes](ctx context.Context, key string) (val T, isNotExist bool, err error)

Get 获取key的值

func GetKeyEventExpired

func GetKeyEventExpired(db int) string

GetKeyEventExpired 需要修改redis.conf配置项,启用notify-keyspace-events = "EX"

func HashDel

func HashDel(ctx context.Context, key string, val string) (err error)

HashDel 删除Hash字段

func HashGetAll

func HashGetAll(ctx context.Context, key string) (result map[string]string, isNotExist bool, err error)

HashGetAll 获取Hash的所有字段和值

func HashGetString

func HashGetString(ctx context.Context, key, field string) (result string, isNotExist bool, err error)

HashGetString 获取Hash字段的值

func HashSet

func HashSet(ctx context.Context, key string, val map[string]any, expiration time.Duration) (err error)

HashSet 设置Hash

func HashUpdate

func HashUpdate(ctx context.Context, key string, val ...any) (err error)

HashUpdate 更新Hash字段

func IsRedisNilErr added in v0.10.0

func IsRedisNilErr(err error) bool

IsRedisNilErr 判断是否为redis.Nil

func SetEx

func SetEx(ctx context.Context, key string, val any, exp time.Duration) (err error)

SetEx 设置key和值,并设置过期时间

func Subscribe

func Subscribe(ctx context.Context, key string) (subscribe *redis.PubSub)

Subscribe 订阅一个key

Types

type Option

type Option func(*Options)

func WithDB

func WithDB(db int) Option

WithDB 设置数据库

func WithUserAndPass added in v0.11.0

func WithUserAndPass(user, pwd string) Option

WithUserAndPass 设置用户名和密码

type Options

type Options struct {
	Username string
	Password string
	DB       int
}

type RedisValueTypes

type RedisValueTypes interface {
	int | int64 | string | bool | []byte
}

Jump to

Keyboard shortcuts

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