redis

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const APP = "redis"

Variables

View Source
var Cli *redis.Client

Functions

func Delete

func Delete(keys ...string) error

Delete 删除key

func Eval

func Eval(script string, keys []string, args ...interface{}) error

func ExistKey

func ExistKey(key string) bool

ExistKey key是否存在

func ExpireTime

func ExpireTime(key string, t time.Duration) error

ExpireTime 设置key过期时间

func Get

func Get(key string) (string, error)

Get 获取string

func GetExpire

func GetExpire(key string) (time.Duration, error)

GetExpire 获得 key 的过期时间

func HDel

func HDel(key string, fields ...string) (int64, error)

HDel 删除哈希表中的一个或多个字段

func HExists

func HExists(key, field string) (bool, error)

HExists 检查哈希表中给定字段是否存在

func HGet

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

HGet 获取hash字段值

func HGetAll

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

HGetAll 获取所有key 转成map

func HKeys

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

HKeys 获取哈希表中所有的字段

func HLen

func HLen(key string) (int64, error)

HLen 获取哈希表中字段的数量

func HSet

func HSet(key, field string, value any) error

HSet 设置单个哈希表字段

func HSetMap

func HSetMap(key string, fields map[string]any) error

HSetMap 设置map对象位hash表

func HSetMapExpire

func HSetMapExpire(key string, fields map[string]any, expireTime time.Duration) error

HSetMapExpire 设置map对象位hash表

func HVals

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

HVals 获取哈希表中所有字段的值

func LIndex

func LIndex(key string, index int64) (string, error)

LIndex 获取 Redis 的 list 中指定值的元素

func LPop

func LPop(key string) (string, error)

LPop 获取 Redis 的 list 删除左边的元素

func LPush

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

LPush 将元素插入 Redis 的 list 头部

func LRange

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

LRange 获取 Redis 的 list 中指定范围的元素

func New

func New(rds *Redis) (*redis.Client, error)

func Publish

func Publish(channel, message string)

Publish 发布消息

func RPop

func RPop(key string) (string, error)

RPop 获取 Redis 的 list 删除右边的元素

func RPush

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

RPush 将元素插入 Redis 的 list 尾部

func RemoveExpire

func RemoveExpire(key string) error

RemoveExpire 删除key过期时间

func Rename

func Rename(oldKey, newKey string) (bool, error)

Rename 更改key的名字

func SAdd

func SAdd(key string, members ...interface{}) error

SAdd 无序集合添加元素

func SIsMember

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

SIsMember 无序集合判断是否属于该集合

func SMembers

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

SMembers 无序集合获取所有成员

func SRem

func SRem(key string, members ...interface{}) error

SRem 无序集合删除成员

func Set

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

Set 设置string

func SetExpire

func SetExpire(key string, value interface{}, expireTime time.Duration) error

SetExpire 设置string

func Subscribe

func Subscribe(channel string, cb func(string)) *redis.PubSub

Subscribe 订阅消息

func ZAdd

func ZAdd(key string, members ...*redis.Z) error

ZAdd 添加元素

func ZRange

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

ZRange 获取范围内元素

func ZRank

func ZRank(key string, member string) (int64, error)

ZRank 有序集合中指定成员的序号

func ZRem

func ZRem(key string, members ...interface{}) error

ZRem 删除

Types

type Redis

type Redis struct {
	Addr               string        `mapstructure:"addr" default:"" yaml:"addr" json:"addr"`                                                   // Redis 服务器的地址
	Password           string        `mapstructure:"password" default:"" yaml:"password" json:"password"`                                       // Redis 服务器的密码
	DB                 int           `mapstructure:"db" default:"" yaml:"db" json:"db"`                                                         // Redis 服务器的数据库编号
	MaxRetries         int           `mapstructure:"max-retries" default:"3" yaml:"max-retries" json:"max-retries"`                             // Redis 客户端重试连接的最大次数
	DialTimeout        time.Duration `mapstructure:"dial-timeout" default:"5" yaml:"dial-timeout"  json:"dial-timeout"`                         // 连接 Redis 服务器的超时时间
	ReadTimeout        time.Duration `mapstructure:"read-timeout" default:"3" yaml:"read-timeout"  json:"read-timeout"`                         // 从 Redis 服务器读取数据的超时时间
	WriteTimeout       time.Duration `mapstructure:"write-timeout" default:"3" yaml:"write-timeout"  json:"write-timeout"`                      // 向 Redis 服务器写入数据的超时时间
	PoolSize           int           `mapstructure:"pool-size" default:"10" yaml:"pool-size" json:"pool-size" `                                 // 连接池的最大连接数
	MinIdleConns       int           `mapstructure:"min-idle-conns" default:"0" yaml:"min-idle-conns"  json:"min-idle-conns"`                   // 连接池的最小空闲连接数
	MaxConnAge         time.Duration `mapstructure:"max-conn-age" default:"0" yaml:"max-conn-age"  json:"max-conn-age"`                         // 连接池中连接的最大寿命,超过这个时间将被关闭
	PoolTimeout        time.Duration `mapstructure:"pool-timeout" default:"4" yaml:"pool-timeout"  json:"pool-timeout"`                         // 从连接池获取连接的超时时间
	IdleTimeout        time.Duration `mapstructure:"idle-timeout" default:"5" yaml:"idle-timeout"  json:"idle-timeout"`                         // 连接池中空闲连接的超时时间
	IdleCheckFrequency time.Duration `mapstructure:"idle-check-frequency" default:"1" yaml:"idle-check-frequency"  json:"idle-check-frequency"` // 连接池中空闲连接的检查频率
}

Jump to

Keyboard shortcuts

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