redis

package module
v0.0.0-...-70609dd Latest Latest
Warning

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

Go to latest
Published: May 26, 2023 License: MIT Imports: 7 Imported by: 0

README

redis

介绍

对redis三方库再次封装,为项目隔离三方库

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Del

func Del(keys ...string)

Del 删除缓存 key: 可以传一个值 或多个

func Expire

func Expire(key string, timeout int) (bool, error)

Expire 指定缓存失效时间 key: 键 timeout: 时间(秒)

func Get

func Get(key string) (string, error)

Get 普通缓存获取 key 键 return 值

func GetExpire

func GetExpire(key string) (int, error)

GetExpire 根据key 获取过期时间 key: 键 不能为null return: 时间(秒) 返回0代表为永久有效

func GetIndex

func GetIndex(key string, index int) (string, error)

GetIndex 通过索引 获取list中的值 key 键 index 索引 index>=0时, 0 表头,1 第二个元素,依次类推;index<0时,-1,表尾,-2倒数第二个元素,依次类推

func GetList

func GetList(key string, start, stop int64) ([]string, error)

GetList 通过索引 获取list中的值 key 键 start stop 开始结束索引

func GetListSize

func GetListSize(key string) (int64, error)

GetListSize 获取list缓存的长度 key 键

func GetStruct

func GetStruct(key string, target interface{}) error

GetStruct 普通缓存获取 key 键 target 参数地址 return 值

func HDel

func HDel(key string, item ...string)

HDel 删除hash表中的值 key 键 item 项 可以使多个

func HGet

func HGet(key string, item string) (string, error)

HGet HashGet key 键 不能为null item 项 不能为null return 值

func HGetAll

func HGetAll(key string) (map[string]string, error)

HGetAll 获取hashKey对应的所有键值 key 键 return 对应的多个键值

func HHasKey

func HHasKey(key string, item string) (bool, error)

HHasKey 判断hash表中是否有该项的值 key 键 item 项 return true 存在 false不存在

func HIncr

func HIncr(key string, item string, by int64) (int64, error)

HIncr hash递增 如果不存在,就会创建一个 并把新增后的值返回 key 键 item 项 by 要增加几

func HMGet

func HMGet(key string, item ...string) ([]interface{}, error)

HMGet HashMGet key 键 不能为null item 项 不能为null return 值

func HMSet

func HMSet(key string, fields map[string]interface{}) error

HMSet HashSet key 键 map 对应多个键值

func HSet

func HSet(key string, item string, value interface{}) error

HSet 向一张hash表中放入数据,如果不存在将创建 key 键 item 项 value 值

func HasKey

func HasKey(key string) (bool, error)

HasKey 判断key是否存在 key 键 return true 存在 false不存在

func Incr

func Incr(key string) (int64, error)

Incr 递增 key 键

func IncrBy

func IncrBy(key string, delta int) (int64, error)

IncrBy 递增 key 键 delta 要减少几(小于0)

func InitRedisClient

func InitRedisClient(opts Options)

InitRedisClient 初始化redis

func LPop

func LPop(key string) (string, error)

LPop 从list左pop一个元素 key 键

func LRemove

func LRemove(key string, count int, value interface{}) (int64, error)

LRemove 移除N个值为value key 键 count 移除多少个 value 值

func RPush

func RPush(key string, values ...interface{}) (int64, error)

RPush 将value放入list右缓存 key 键 values 值

func SGet

func SGet(key string) ([]string, error)

SGet 根据key获取Set中的所有值 key 键

func SIsMember

func SIsMember(key string, value interface{}) (bool, error)

SIsMember 根据value从一个set中查询,是否存在

key 键

value 值

func SRemove

func SRemove(key string, values ...interface{}) (int64, error)

SRemove 移除值为value的 key 键 values 值 可以是多个

func Set

func Set(key string, value interface{}) error

Set 普通缓存放入 key 键 value 值

func SetExpire

func SetExpire(key string, value interface{}, expire int) error

SetExpire 普通缓存放入并设置时间 key 键 value 值 expire 时间(秒) time要大于0 如果time小于等于0 将设置无限期

func SetNX

func SetNX(key string, value interface{}) error

SetNX 放入缓存并设置时间 key 键 value 值

func SetNXExpire

func SetNXExpire(key string, value interface{}, expire int) error

SetNXExpire 放入缓存并设置时间 key 键 value 值 expire 时间(秒) time要大于0 如果time小于等于0 将设置无限期

func SetStruct

func SetStruct(key string, value interface{}) error

SetStruct 普通缓存放入 key value 转为json string

func SetStructExpire

func SetStructExpire(key string, value interface{}, expire int) error

SetStructExpire 普通缓存放入 key value 转为json string expire 过期时间,秒

Types

type Options

type Options struct {
	// redis 连接模式,standalone、sentinel、cluster
	Mode string
	// 服务器地址
	Host string
	// 服务器连接密码
	Password string
	// 数据库索引(默认为0)
	Database int
	// 连接超时时间(毫秒)
	Timeout int
	// 连接池配置
	Pool Pool
}

func NewDefaultOptions

func NewDefaultOptions() Options

type Pool

type Pool struct {
	// 连接池最大阻塞等待时间(使用负值表示没有限制)
	MaxWait int
	// 连接池中的最大连接
	MaxIdle int
	// 连接池中的最小连接
	MinIdle int
}

type RedisLock

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

func New

func New(key string, expire int) *RedisLock

New 获取锁对象 key expire 时间(秒) time要大于0 如果time小于等于0 将设置无限期

func (*RedisLock) TryLock

func (s *RedisLock) TryLock() (bool, error)

TryLock 获取锁

func (*RedisLock) UnLock

func (s *RedisLock) UnLock() bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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