redis

package
v0.0.8-20250724 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

redis包:基于Redis的分布式缓存实现 提供键值存储、哈希表操作、队列操作和事务支持

Redis是一个高性能的内存数据结构存储,支持多种数据结构 本包实现了Cache接口,提供统一的缓存操作API

主要特性: - 高性能的内存存储 - 支持持久化 - 原生队列操作支持 - 丰富的数据结构 - 事务支持(Pipeline) - 集群支持 - 分布式缓存

作者: gophertool

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRedisClient

func NewRedisClient(config config.Cache) (_interface.Cache, error)

Types

type RedisDb

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

RedisDb Redis缓存实现结构体

func (*RedisDb) BeginTx

func (r *RedisDb) BeginTx() (_interface.Tx, error)

func (*RedisDb) Close

func (r *RedisDb) Close()

func (*RedisDb) Delete

func (r *RedisDb) Delete(key string) error

func (*RedisDb) Exists

func (r *RedisDb) Exists(key string) (bool, error)

func (*RedisDb) Expire

func (r *RedisDb) Expire(key string, ttl time.Duration) error

func (*RedisDb) Get

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

Get 获取指定key的值 参数:

key - 键名

返回值:

string - 键对应的值
error - 操作错误,键不存在时返回ErrKeyNotFound

func (*RedisDb) HDel

func (r *RedisDb) HDel(key, field string) error

HDel 删除哈希表中的一个或多个field 参数:

key - 哈希表键名
field - 字段名

返回值:

error - 操作错误

func (*RedisDb) HGet

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

HGet 获取哈希表中指定field的值 参数:

key - 哈希表键名
field - 字段名

返回值:

string - 字段对应的值
error - 操作错误,字段不存在时返回ErrKeyNotFound

func (*RedisDb) HGetAll

func (r *RedisDb) HGetAll(key string) (map[string]string, error)

HGetAll 获取哈希表中所有的field和value 参数:

key - 哈希表键名

返回值:

map[string]string - 所有字段和值的映射
error - 操作错误

func (*RedisDb) HSet

func (r *RedisDb) HSet(key, field, value string, ttl time.Duration) error

HSet 设置哈希表中的field-value,并设置过期时间 参数:

key - 哈希表键名
field - 字段名
value - 字段值
ttl - 过期时间

返回值:

error - 操作错误

func (*RedisDb) LPop

func (r *RedisDb) LPop(key string) (string, error)

LPop 弹出列表最左边的元素 参数:

key - 列表键名

返回值:

string - 弹出的元素值
error - 操作错误,列表为空时返回ErrKeyNotFound

func (*RedisDb) LPush

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

LPush 将元素插入到列表左边 参数:

key - 列表键名
value - 要插入的值

返回值:

error - 操作错误

func (*RedisDb) Len

func (r *RedisDb) Len(key string) (int64, error)

func (*RedisDb) Pop

func (r *RedisDb) Pop(key string) (string, error)

func (*RedisDb) PopAll

func (r *RedisDb) PopAll(key string) ([]string, error)

func (*RedisDb) Push

func (r *RedisDb) Push(key string, value string) error

func (*RedisDb) RPop

func (r *RedisDb) RPop(key string) (string, error)

RPop 弹出列表最右边的元素 参数:

key - 列表键名

返回值:

string - 弹出的元素值
error - 操作错误,列表为空时返回ErrKeyNotFound

func (*RedisDb) RPush

func (r *RedisDb) RPush(key string, value string) error

RPush 将元素插入到列表右边 参数:

key - 列表键名
value - 要插入的值

返回值:

error - 操作错误

func (*RedisDb) Set

func (r *RedisDb) Set(key string, value string, ttl time.Duration) error

type RedisTx

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

func (*RedisTx) Commit

func (tx *RedisTx) Commit() error

func (*RedisTx) Delete

func (tx *RedisTx) Delete(key string) error

func (*RedisTx) Expire

func (tx *RedisTx) Expire(key string, ttl time.Duration) error

func (*RedisTx) HDel

func (tx *RedisTx) HDel(key, field string) error

func (*RedisTx) HSet

func (tx *RedisTx) HSet(key, field, value string, ttl time.Duration) error

func (*RedisTx) Rollback

func (tx *RedisTx) Rollback() error

func (*RedisTx) Set

func (tx *RedisTx) Set(key string, value string, ttl time.Duration) error

Jump to

Keyboard shortcuts

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