redis

package
v1.8.7 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const RedisNil = redis.Nil

RedisNil means nil reply, .e.g. when key does not exist.

Variables

View Source
var ErrNotImplemented = errors.New("Not implemented")

ErrNotImplemented not implemented error

Functions

func AppendArg

func AppendArg(b []byte, v interface{}) []byte

func SetTrace

func SetTrace(t bool)

func String

func String(b []byte) string

Types

type Client

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

Client a struct representing the redis client

func New

func New(config *Config) *Client

New 新连接

func NewClient

func NewClient(opts Options) *Client

NewClient 新客户端

func (*Client) Append

func (r *Client) Append(ctx context.Context, key, value string) *redis.IntCmd

Append 如果 key 已经存在并且是一个字符串, APPEND 命令将 value 追加到 key 原来的值的末尾。 如果 key 不存在, APPEND 就简单地将给定 key 设为 value ,就像执行 SET key value 一样。

func (*Client) BLPop

func (r *Client) BLPop(ctx context.Context, timeout time.Duration, keys ...string) *redis.StringSliceCmd

BLPop 是列表的阻塞式(blocking)弹出原语。 它是 LPop 命令的阻塞版本,当给定列表内没有任何元素可供弹出的时候,连接将被 BLPop 命令阻塞,直到等待超时或发现可弹出元素为止。 当给定多个 key 参数时,按参数 key 的先后顺序依次检查各个列表,弹出第一个非空列表的头元素。

func (*Client) BRPop

func (r *Client) BRPop(ctx context.Context, timeout time.Duration, keys ...string) *redis.StringSliceCmd

BRPop 是列表的阻塞式(blocking)弹出原语。 它是 RPOP 命令的阻塞版本,当给定列表内没有任何元素可供弹出的时候,连接将被 BRPOP 命令阻塞,直到等待超时或发现可弹出元素为止。 当给定多个 key 参数时,按参数 key 的先后顺序依次检查各个列表,弹出第一个非空列表的尾部元素。 关于阻塞操作的更多信息,请查看 BLPOP 命令, BRPOP 除了弹出元素的位置和 BLPOP 不同之外,其他表现一致。

func (*Client) BRPopLPush

func (r *Client) BRPopLPush(ctx context.Context, source, destination string, timeout time.Duration) *redis.StringCmd

BRPopLPush 是 RPOPLPUSH 的阻塞版本,当给定列表 source 不为空时, BRPOPLPUSH 的表现和 RPOPLPUSH 一样。 当列表 source 为空时, BRPOPLPUSH 命令将阻塞连接,直到等待超时,或有另一个客户端对 source 执行 LPUSH 或 RPUSH 命令为止。

func (*Client) BZPopMax

func (r *Client) BZPopMax(ctx context.Context, timeout time.Duration, keys ...string) *redis.ZWithKeyCmd

BZPopMax 是有序集合命令 ZPOPMAX带有阻塞功能的版本。

func (*Client) BZPopMin

func (r *Client) BZPopMin(ctx context.Context, timeout time.Duration, keys ...string) *redis.ZWithKeyCmd

BZPopMin 是有序集合命令 ZPOPMIN带有阻塞功能的版本。

func (*Client) BgRewriteAOF

func (r *Client) BgRewriteAOF(ctx context.Context) *redis.StatusCmd

BgRewriteAOF 异步重写附加文件

func (*Client) BgSave

func (r *Client) BgSave(ctx context.Context) *redis.StatusCmd

BgSave 将数据集异步保存到磁盘

func (*Client) BitCount

func (r *Client) BitCount(ctx context.Context, key string, bitCount *redis.BitCount) *redis.IntCmd

BitCount 计算给定字符串中,被设置为 1 的比特位的数量。 一般情况下,给定的整个字符串都会被进行计数,通过指定额外的 start 或 end 参数,可以让计数只在特定的位上进行。 start 和 end 参数的设置和 GETRANGE 命令类似,都可以使用负数值:比如 -1 表示最后一个位,而 -2 表示倒数第二个位,以此类推。 不存在的 key 被当成是空字符串来处理,因此对一个不存在的 key 进行 BITCOUNT 操作,结果为 0 。

func (*Client) BitField

func (r *Client) BitField(ctx context.Context, key string, args ...interface{}) *redis.IntSliceCmd

BitField -> BitCount

func (*Client) BitOpAnd

func (r *Client) BitOpAnd(ctx context.Context, destKey string, keys ...string) *redis.IntCmd

BitOpAnd -> BitCount

func (*Client) BitOpNot

func (r *Client) BitOpNot(ctx context.Context, destKey string, key string) *redis.IntCmd

BitOpNot -> BitCount

func (*Client) BitOpOr

func (r *Client) BitOpOr(ctx context.Context, destKey string, keys ...string) *redis.IntCmd

BitOpOr -> BitCount

func (*Client) BitOpXor

func (r *Client) BitOpXor(ctx context.Context, destKey string, keys ...string) *redis.IntCmd

BitOpXor -> BitCount

func (*Client) BitPos

func (r *Client) BitPos(ctx context.Context, key string, bit int64, pos ...int64) *redis.IntCmd

BitPos -> BitCount

func (*Client) ClientGetName

func (r *Client) ClientGetName(ctx context.Context) *redis.StringCmd

ClientGetName returns the name of the connection.

func (*Client) ClientID

func (r *Client) ClientID(ctx context.Context) *redis.IntCmd

ClientID Returns the client ID for the current connection

func (*Client) ClientKill

func (r *Client) ClientKill(ctx context.Context, ipPort string) *redis.StatusCmd

ClientKill 杀掉客户端的连接

func (*Client) ClientKillByFilter

func (r *Client) ClientKillByFilter(ctx context.Context, keys ...string) *redis.IntCmd

ClientKillByFilter is new style synx, while the ClientKill is old CLIENT KILL <option> [value] ... <option> [value]

func (*Client) ClientList

func (r *Client) ClientList(ctx context.Context) *redis.StringCmd

ClientList 获取客户端连接列表

func (*Client) ClientPause

func (r *Client) ClientPause(ctx context.Context, dur time.Duration) *redis.BoolCmd

ClientPause 停止处理来自客户端的命令一段时间

func (*Client) ClusterAddSlots

func (r *Client) ClusterAddSlots(ctx context.Context, slots ...int) *redis.StatusCmd

ClusterAddSlots Assign new hash slots to receiving node

func (*Client) ClusterAddSlotsRange

func (r *Client) ClusterAddSlotsRange(ctx context.Context, min, max int) *redis.StatusCmd

ClusterAddSlotsRange -> ClusterAddSlots

func (*Client) ClusterCountFailureReports

func (r *Client) ClusterCountFailureReports(ctx context.Context, nodeID string) *redis.IntCmd

ClusterCountFailureReports Return the number of failure reports active for a given node

func (*Client) ClusterCountKeysInSlot

func (r *Client) ClusterCountKeysInSlot(ctx context.Context, slot int) *redis.IntCmd

ClusterCountKeysInSlot Return the number of local keys in the specified hash slot

func (*Client) ClusterDelSlots

func (r *Client) ClusterDelSlots(ctx context.Context, slots ...int) *redis.StatusCmd

ClusterDelSlots Set hash slots as unbound in receiving node

func (*Client) ClusterDelSlotsRange

func (r *Client) ClusterDelSlotsRange(ctx context.Context, min, max int) *redis.StatusCmd

ClusterDelSlotsRange -> ClusterDelSlots

func (*Client) ClusterFailover

func (r *Client) ClusterFailover(ctx context.Context) *redis.StatusCmd

ClusterFailover Forces a replica to perform a manual failover of its master.

func (*Client) ClusterForget

func (r *Client) ClusterForget(ctx context.Context, nodeID string) *redis.StatusCmd

ClusterForget Remove a node from the nodes table

func (*Client) ClusterGetKeysInSlot

func (r *Client) ClusterGetKeysInSlot(ctx context.Context, slot int, count int) *redis.StringSliceCmd

ClusterGetKeysInSlot Return local key names in the specified hash slot

func (*Client) ClusterInfo

func (r *Client) ClusterInfo(ctx context.Context) *redis.StringCmd

ClusterInfo Provides info about Redis Cluster node state

func (*Client) ClusterKeySlot

func (r *Client) ClusterKeySlot(ctx context.Context, key string) *redis.IntCmd

ClusterKeySlot Returns the hash slot of the specified key

func (*Client) ClusterMeet

func (r *Client) ClusterMeet(ctx context.Context, host, port string) *redis.StatusCmd

ClusterMeet Force a node cluster to handshake with another node

func (*Client) ClusterNodes

func (r *Client) ClusterNodes(ctx context.Context) *redis.StringCmd

ClusterNodes Get Cluster config for the node

func (*Client) ClusterReplicate

func (r *Client) ClusterReplicate(ctx context.Context, nodeID string) *redis.StatusCmd

ClusterReplicate Reconfigure a node as a replica of the specified master node

func (*Client) ClusterResetHard

func (r *Client) ClusterResetHard(ctx context.Context) *redis.StatusCmd

ClusterResetHard Reset a Redis Cluster node

func (*Client) ClusterResetSoft

func (r *Client) ClusterResetSoft(ctx context.Context) *redis.StatusCmd

ClusterResetSoft Reset a Redis Cluster node

func (*Client) ClusterSaveConfig

func (r *Client) ClusterSaveConfig(ctx context.Context) *redis.StatusCmd

ClusterSaveConfig Forces the node to save cluster state on disk

func (*Client) ClusterSlaves

func (r *Client) ClusterSlaves(ctx context.Context, nodeID string) *redis.StringSliceCmd

ClusterSlaves List replica nodes of the specified master node

func (*Client) ClusterSlots

func (r *Client) ClusterSlots(ctx context.Context) *redis.ClusterSlotsCmd

ClusterSlots 获取集群节点的映射数组

func (*Client) Command

func (r *Client) Command(ctx context.Context) *redis.CommandsInfoCmd

Command 返回有关所有Redis命令的详细信息的Array回复

func (*Client) ConfigGet

func (r *Client) ConfigGet(ctx context.Context, parameter string) *redis.SliceCmd

ConfigGet 获取指定配置参数的值

func (*Client) ConfigResetStat

func (r *Client) ConfigResetStat(ctx context.Context) *redis.StatusCmd

ConfigResetStat 重置 INFO 命令中的某些统计数据

func (*Client) ConfigRewrite

func (r *Client) ConfigRewrite(ctx context.Context) *redis.StatusCmd

ConfigRewrite 对启动 Redis 服务器时所指定的 redis.conf 配置文件进行改写

func (*Client) ConfigSet

func (r *Client) ConfigSet(ctx context.Context, parameter, value string) *redis.StatusCmd

ConfigSet 修改 redis 配置参数,无需重启

func (*Client) DBSize

func (r *Client) DBSize(ctx context.Context) *redis.IntCmd

DBSize 返回当前数据库的 key 的数量

func (*Client) DebugObject

func (r *Client) DebugObject(ctx context.Context, key string) *redis.StringCmd

DebugObject 获取 key 的调试信息

func (*Client) Decr

func (r *Client) Decr(ctx context.Context, key string) *redis.IntCmd

Decr 将 key 中储存的数字值减一。 如果 key 不存在,那么 key 的值会先被初始化为 0 ,然后再执行 DECR 操作。 如果值包含错误的类型,或字符串类型的值不能表示为数字,那么返回一个错误。 本操作的值限制在 64 位(bit)有符号数字表示之内。 关于递增(increment) / 递减(decrement)操作的更多信息,请参见 INCR 命令。 执行 DECR 命令之后 key 的值。

func (*Client) DecrBy

func (r *Client) DecrBy(ctx context.Context, key string, value int64) *redis.IntCmd

DecrBy 将 key 所储存的值减去减量 decrement 。 如果 key 不存在,那么 key 的值会先被初始化为 0 ,然后再执行 DECRBY 操作。 如果值包含错误的类型,或字符串类型的值不能表示为数字,那么返回一个错误。 本操作的值限制在 64 位(bit)有符号数字表示之内。 关于更多递增(increment) / 递减(decrement)操作的更多信息,请参见 INCR 命令。 减去 decrement 之后, key 的值。

func (*Client) Del

func (r *Client) Del(ctx context.Context, keys ...string) *redis.IntCmd

Del 删除给定的一个或多个 key 。 不存在的 key 会被忽略。

func (*Client) Dump

func (r *Client) Dump(ctx context.Context, key string) *redis.StringCmd

Dump 序列化给定 key ,并返回被序列化的值,使用 RESTORE 命令可以将这个值反序列化为 Redis 键。 如果 key 不存在,那么返回 nil 。 否则,返回序列化之后的值。

func (*Client) Echo

func (r *Client) Echo(ctx context.Context, message interface{}) *redis.StringCmd

Echo 批量字符串回复

func (*Client) Eval

func (r *Client) Eval(ctx context.Context, script string, keys []string, args ...interface{}) *redis.Cmd

Eval 执行 Lua 脚本。

func (*Client) EvalSha

func (r *Client) EvalSha(ctx context.Context, sha1 string, keys []string, args ...interface{}) *redis.Cmd

EvalSha 执行 Lua 脚本。

func (*Client) Exists

func (r *Client) Exists(ctx context.Context, key ...string) *redis.IntCmd

Exists 检查给定 key 是否存在。 若 key 存在,返回 1 ,否则返回 0 。

func (*Client) Expire

func (r *Client) Expire(ctx context.Context, key string, expiration time.Duration) *redis.BoolCmd

Expire 为给定 key 设置生存时间,当 key 过期时(生存时间为 0 ),它会被自动删除。 设置成功返回 1 。 当 key 不存在或者不能为 key 设置生存时间时(比如在低于 2.1.3 版本的 Redis 中你尝试更新 key 的生存时间),返回 0 。

func (*Client) ExpireAt

func (r *Client) ExpireAt(ctx context.Context, key string, tm time.Time) *redis.BoolCmd

ExpireAt EXPIREAT 的作用和 EXPIRE 类似,都用于为 key 设置生存时间。 命令用于以 UNIX 时间戳(unix timestamp)格式设置 key 的过期时间

func (*Client) FlushAll

func (r *Client) FlushAll(ctx context.Context) *redis.StatusCmd

FlushAll 删除所有数据库的所有key

func (*Client) FlushAllAsync

func (r *Client) FlushAllAsync(ctx context.Context) *redis.StatusCmd

FlushAllAsync 异步删除所有数据库的所有key

func (*Client) FlushDB

func (r *Client) FlushDB(ctx context.Context) *redis.StatusCmd

FlushDB 删除当前数据库的所有key

func (*Client) FlushDBAsync

func (r *Client) FlushDBAsync(ctx context.Context) *redis.StatusCmd

FlushDBAsync 异步删除当前数据库的所有key

func (*Client) GeoAdd

func (r *Client) GeoAdd(ctx context.Context, key string, geoLocation ...*redis.GeoLocation) *redis.IntCmd

GeoAdd 将指定的地理空间位置(纬度、经度、名称)添加到指定的key中

func (*Client) GeoDist

func (r *Client) GeoDist(ctx context.Context, key string, member1, member2, unit string) *redis.FloatCmd

GeoDist 返回两个给定位置之间的距离

func (*Client) GeoHash

func (r *Client) GeoHash(ctx context.Context, key string, members ...string) *redis.StringSliceCmd

GeoHash 返回一个或多个位置元素的 Geohash 表示

func (*Client) GeoPos

func (r *Client) GeoPos(ctx context.Context, key string, members ...string) *redis.GeoPosCmd

GeoPos 从key里返回所有给定位置元素的位置(经度和纬度)

func (*Client) GeoRadius

func (r *Client) GeoRadius(ctx context.Context, key string, longitude, latitude float64, query *redis.GeoRadiusQuery) *redis.GeoLocationCmd

GeoRadius 以给定的经纬度为中心, 找出某一半径内的元素

func (*Client) GeoRadiusByMember

func (r *Client) GeoRadiusByMember(ctx context.Context, key, member string, query *redis.GeoRadiusQuery) *redis.GeoLocationCmd

GeoRadiusByMember -> GeoRadius

func (*Client) GeoRadiusByMemberStore

func (r *Client) GeoRadiusByMemberStore(ctx context.Context, key, member string, query *redis.GeoRadiusQuery) *redis.IntCmd

GeoRadiusByMemberStore 找出位于指定范围内的元素,中心点是由给定的位置元素决定

func (*Client) GeoRadiusStore

func (r *Client) GeoRadiusStore(ctx context.Context, key string, longitude, latitude float64, query *redis.GeoRadiusQuery) *redis.IntCmd

GeoRadiusStore -> GeoRadius

func (*Client) Get

func (r *Client) Get(ctx context.Context, key string) *redis.StringCmd

Get 返回 key 所关联的字符串值。 如果 key 不存在那么返回特殊值 nil 。 假如 key 储存的值不是字符串类型,返回一个错误,因为 GET 只能用于处理字符串值。 当 key 不存在时,返回 nil ,否则,返回 key 的值。 如果 key 不是字符串类型,那么返回一个错误。

func (*Client) GetBit

func (r *Client) GetBit(ctx context.Context, key string, offset int64) *redis.IntCmd

GetBit 对 key 所储存的字符串值,获取指定偏移量上的位(bit)。 当 offset 比字符串值的长度大,或者 key 不存在时,返回 0 。 字符串值指定偏移量上的位(bit)。

func (*Client) GetClient

func (r *Client) GetClient() redis.Cmdable

GetClient 返回客户端

func (*Client) GetRange

func (r *Client) GetRange(ctx context.Context, key string, start, end int64) *redis.StringCmd

GetRange 返回 key 中字符串值的子字符串,字符串的截取范围由 start 和 end 两个偏移量决定(包括 start 和 end 在内)。 负数偏移量表示从字符串最后开始计数, -1 表示最后一个字符, -2 表示倒数第二个,以此类推。 GETRANGE 通过保证子字符串的值域(range)不超过实际字符串的值域来处理超出范围的值域请求。 返回截取得出的子字符串。

func (*Client) GetSet

func (r *Client) GetSet(ctx context.Context, key string, value interface{}) *redis.StringCmd

GetSet 将给定 key 的值设为 value ,并返回 key 的旧值(old value)。 当 key 存在但不是字符串类型时,返回一个错误。 返回给定 key 的旧值。 当 key 没有旧值时,也即是, key 不存在时,返回 nil 。

func (*Client) HDel

func (r *Client) HDel(ctx context.Context, key string, fields ...string) *redis.IntCmd

HDel 删除哈希表 key 中的一个或多个指定域,不存在的域将被忽略。

func (*Client) HExists

func (r *Client) HExists(ctx context.Context, key, field string) *redis.BoolCmd

HExists 查看哈希表 key 中,给定域 field 是否存在。

func (*Client) HGet

func (r *Client) HGet(ctx context.Context, key, field string) *redis.StringCmd

HGet 返回哈希表 key 中给定域 field 的值。

func (*Client) HGetAll

func (r *Client) HGetAll(ctx context.Context, key string) *redis.StringStringMapCmd

HGetAll 返回哈希表 key 中,所有的域和值。 在返回值里,紧跟每个域名(field name)之后是域的值(value),所以返回值的长度是哈希表大小的两倍。

func (*Client) HIncrBy

func (r *Client) HIncrBy(ctx context.Context, key, field string, incr int64) *redis.IntCmd

HIncrBy 为哈希表 key 中的域 field 的值加上增量 increment 。 增量也可以为负数,相当于对给定域进行减法操作。 如果 key 不存在,一个新的哈希表被创建并执行 HINCRBY 命令。 如果域 field 不存在,那么在执行命令前,域的值被初始化为 0 。 对一个储存字符串值的域 field 执行 HINCRBY 命令将造成一个错误。 本操作的值被限制在 64 位(bit)有符号数字表示之内。

func (*Client) HIncrByFloat

func (r *Client) HIncrByFloat(ctx context.Context, key, field string, incr float64) *redis.FloatCmd

HIncrByFloat 为哈希表 key 中的域 field 加上浮点数增量 increment 。 如果哈希表中没有域 field ,那么 HINCRBYFLOAT 会先将域 field 的值设为 0 ,然后再执行加法操作。 如果键 key 不存在,那么 HINCRBYFLOAT 会先创建一个哈希表,再创建域 field ,最后再执行加法操作。

func (*Client) HKeys

func (r *Client) HKeys(ctx context.Context, key string) *redis.StringSliceCmd

HKeys 返回哈希表 key 中的所有域。

func (*Client) HLen

func (r *Client) HLen(ctx context.Context, key string) *redis.IntCmd

HLen 返回哈希表 key 中域的数量。

func (*Client) HMGet

func (r *Client) HMGet(ctx context.Context, key string, fields ...string) *redis.SliceCmd

HMGet 返回哈希表 key 中,一个或多个给定域的值。 如果给定的域不存在于哈希表,那么返回一个 nil 值。 因为不存在的 key 被当作一个空哈希表来处理,所以对一个不存在的 key 进行 HMGET 操作将返回一个只带有 nil 值的表。

func (*Client) HMSet

func (r *Client) HMSet(ctx context.Context, key string, value ...interface{}) *redis.BoolCmd

HMSet 同时将多个 field-value (域-值)对设置到哈希表 key 中。 此命令会覆盖哈希表中已存在的域。 如果 key 不存在,一个空哈希表被创建并执行 HMSET 操作。

func (*Client) HScan

func (r *Client) HScan(ctx context.Context, key string, cursor uint64, match string, count int64) *redis.ScanCmd

HScan 详细信息请参考 SCAN 命令。

func (*Client) HSet

func (r *Client) HSet(ctx context.Context, key string, value ...interface{}) *redis.IntCmd

HSet 将哈希表 key 中的域 field 的值设为 value 。 如果 key 不存在,一个新的哈希表被创建并进行 HSET 操作。 如果域 field 已经存在于哈希表中,旧值将被覆盖。

func (*Client) HSetNX

func (r *Client) HSetNX(ctx context.Context, key, field string, value interface{}) *redis.BoolCmd

HSetNX 将哈希表 key 中的域 field 的值设置为 value ,当且仅当域 field 不存在。 若域 field 已经存在,该操作无效。 如果 key 不存在,一个新哈希表被创建并执行 HSETNX 命令。

func (*Client) HVals

func (r *Client) HVals(ctx context.Context, key string) *redis.StringSliceCmd

HVals 返回哈希表 key 中所有域的值。

func (*Client) Incr

func (r *Client) Incr(ctx context.Context, key string) *redis.IntCmd

Incr 将 key 中储存的数字值增一。 如果 key 不存在,那么 key 的值会先被初始化为 0 ,然后再执行 INCR 操作。 如果值包含错误的类型,或字符串类型的值不能表示为数字,那么返回一个错误。 本操作的值限制在 64 位(bit)有符号数字表示之内。 执行 INCR 命令之后 key 的值。

func (*Client) IncrBy

func (r *Client) IncrBy(ctx context.Context, key string, value int64) *redis.IntCmd

IncrBy 将 key 所储存的值加上增量 increment 。 如果 key 不存在,那么 key 的值会先被初始化为 0 ,然后再执行 INCRBY 命令。 如果值包含错误的类型,或字符串类型的值不能表示为数字,那么返回一个错误。 本操作的值限制在 64 位(bit)有符号数字表示之内。 关于递增(increment) / 递减(decrement)操作的更多信息,参见 INCR 命令。 加上 increment 之后, key 的值。

func (*Client) IncrByFloat

func (r *Client) IncrByFloat(ctx context.Context, key string, value float64) *redis.FloatCmd

IncrByFloat 为 key 中所储存的值加上浮点数增量 increment 。 如果 key 不存在,那么 INCRBYFLOAT 会先将 key 的值设为 0 ,再执行加法操作。 如果命令执行成功,那么 key 的值会被更新为(执行加法之后的)新值,并且新值会以字符串的形式返回给调用者。

func (*Client) Info

func (r *Client) Info(ctx context.Context, section ...string) *redis.StringCmd

Info 获取 Redis 服务器的各种信息和统计数值

func (*Client) IsCluster

func (r *Client) IsCluster() bool

IsCluster 判断是否集群

func (*Client) Keys

func (r *Client) Keys(ctx context.Context, pattern string) *redis.StringSliceCmd

Keys 查找所有符合给定模式 pattern 的 key 。

func (*Client) LIndex

func (r *Client) LIndex(ctx context.Context, key string, index int64) *redis.StringCmd

LIndex 返回列表 key 中,下标为 index 的元素。 下标(index)参数 start 和 stop 都以 0 为底,也就是说,以 0 表示列表的第一个元素,以 1 表示列表的第二个元素,以此类推。 你也可以使用负数下标,以 -1 表示列表的最后一个元素, -2 表示列表的倒数第二个元素,以此类推。 如果 key 不是列表类型,返回一个错误。

func (*Client) LInsert

func (r *Client) LInsert(ctx context.Context, key, op string, pivot, value interface{}) *redis.IntCmd

LInsert 将值 value 插入到列表 key 当中,位于值 pivot 之前或之后。 当 pivot 不存在于列表 key 时,不执行任何操作。 当 key 不存在时, key 被视为空列表,不执行任何操作。 如果 key 不是列表类型,返回一个错误。

func (*Client) LInsertAfter

func (r *Client) LInsertAfter(ctx context.Context, key string, pivot, value interface{}) *redis.IntCmd

LInsertAfter 同 LInsert

func (*Client) LInsertBefore

func (r *Client) LInsertBefore(ctx context.Context, key string, pivot, value interface{}) *redis.IntCmd

LInsertBefore 同 LInsert

func (*Client) LLen

func (r *Client) LLen(ctx context.Context, key string) *redis.IntCmd

LLen 返回列表 key 的长度。 如果 key 不存在,则 key 被解释为一个空列表,返回 0 . 如果 key 不是列表类型,返回一个错误。

func (*Client) LPop

func (r *Client) LPop(ctx context.Context, key string) *redis.StringCmd

LPop 移除并返回列表 key 的头元素。

func (*Client) LPush

func (r *Client) LPush(ctx context.Context, key string, values ...interface{}) *redis.IntCmd

LPush 将一个或多个值 value 插入到列表 key 的表头 如果有多个 value 值,那么各个 value 值按从左到右的顺序依次插入到表头 如果 key 不存在,一个空列表会被创建并执行 LPush 操作。 当 key 存在但不是列表类型时,返回一个错误。

func (*Client) LPushX

func (r *Client) LPushX(ctx context.Context, key string, value interface{}) *redis.IntCmd

LPushX 将值 value 插入到列表 key 的表头,当且仅当 key 存在并且是一个列表。 和 LPUSH 命令相反,当 key 不存在时, LPUSHX 命令什么也不做。

func (*Client) LRange

func (r *Client) LRange(ctx context.Context, key string, start, stop int64) *redis.StringSliceCmd

LRange 返回列表 key 中指定区间内的元素,区间以偏移量 start 和 stop 指定。 下标(index)参数 start 和 stop 都以 0 为底,也就是说,以 0 表示列表的第一个元素,以 1 表示列表的第二个元素,以此类推。 你也可以使用负数下标,以 -1 表示列表的最后一个元素, -2 表示列表的倒数第二个元素,以此类推。

func (*Client) LRem

func (r *Client) LRem(ctx context.Context, key string, count int64, value interface{}) *redis.IntCmd

LRem 根据参数 count 的值,移除列表中与参数 value 相等的元素。

func (*Client) LSet

func (r *Client) LSet(ctx context.Context, key string, index int64, value interface{}) *redis.StatusCmd

LSet 将列表 key 下标为 index 的元素的值设置为 value 。 当 index 参数超出范围,或对一个空列表( key 不存在)进行 LSET 时,返回一个错误。 关于列表下标的更多信息,请参考 LINDEX 命令。

func (*Client) LTrim

func (r *Client) LTrim(ctx context.Context, key string, start, stop int64) *redis.StatusCmd

LTrim 对一个列表进行修剪(trim),就是说,让列表只保留指定区间内的元素,不在指定区间之内的元素都将被删除。 举个例子,执行命令 LTRIM list 0 2 ,表示只保留列表 list 的前三个元素,其余元素全部删除。 下标(index)参数 start 和 stop 都以 0 为底,也就是说,以 0 表示列表的第一个元素,以 1 表示列表的第二个元素,以此类推。 你也可以使用负数下标,以 -1 表示列表的最后一个元素, -2 表示列表的倒数第二个元素,以此类推。 当 key 不是列表类型时,返回一个错误。

func (*Client) LastSave

func (r *Client) LastSave(ctx context.Context) *redis.IntCmd

LastSave 返回最近一次 Redis 成功将数据保存到磁盘上的时间,以 UNIX 时间戳格式表示

func (*Client) MGet

func (r *Client) MGet(ctx context.Context, keys ...string) *redis.SliceCmd

MGet 返回所有(一个或多个)给定 key 的值。 如果给定的 key 里面,有某个 key 不存在,那么这个 key 返回特殊值 nil 。因此,该命令永不失败。 一个包含所有给定 key 的值的列表。

func (*Client) MGetByPipeline

func (r *Client) MGetByPipeline(ctx context.Context, keys ...string) ([]string, error)

MGetByPipeline gets multiple values from keys,Pipeline is used when redis is a cluster,This means higher IO performance params: keys ...string return: []string, error

func (*Client) MSet

func (r *Client) MSet(ctx context.Context, values ...interface{}) *redis.StatusCmd

MSet 同时设置一个或多个 key-value 对。

func (*Client) MSetNX

func (r *Client) MSetNX(ctx context.Context, values ...interface{}) *redis.BoolCmd

MSetNX 同时设置一个或多个 key-value 对,当且仅当所有给定 key 都不存在。 即使只有一个给定 key 已存在, MSETNX 也会拒绝执行所有给定 key 的设置操作。 MSETNX 是原子性的,因此它可以用作设置多个不同 key 表示不同字段(field)的唯一性逻辑对象(unique logic object),所有字段要么全被设置,要么全不被设置。

func (*Client) MemoryUsage

func (r *Client) MemoryUsage(ctx context.Context, key string, samples ...int) *redis.IntCmd

MemoryUsage Estimate the memory usage of a key

func (*Client) Migrate

func (r *Client) Migrate(ctx context.Context, host, port, key string, db int, timeout time.Duration) *redis.StatusCmd

Migrate 将 key 原子性地从当前实例传送到目标实例的指定数据库上,一旦传送成功, key 保证会出现在目标实例上,而当前实例上的 key 会被删除。

func (*Client) Move

func (r *Client) Move(ctx context.Context, key string, db int) *redis.BoolCmd

Move 将当前数据库的 key 移动到给定的数据库 db 当中。 如果当前数据库(源数据库)和给定数据库(目标数据库)有相同名字的给定 key ,或者 key 不存在于当前数据库,那么 MOVE 没有任何效果。

func (*Client) ObjectEncoding

func (r *Client) ObjectEncoding(ctx context.Context, key string) *redis.StringCmd

ObjectEncoding 返回给定 key 锁储存的值所使用的内部表示(representation)。

func (*Client) ObjectIdleTime

func (r *Client) ObjectIdleTime(ctx context.Context, key string) *redis.DurationCmd

ObjectIdleTime 返回给定 key 自储存以来的空转时间(idle, 没有被读取也没有被写入),以秒为单位。

func (*Client) ObjectRefCount

func (r *Client) ObjectRefCount(ctx context.Context, key string) *redis.IntCmd

ObjectRefCount 返回给定 key 引用所储存的值的次数。此命令主要用于除错。

func (*Client) PExpire

func (r *Client) PExpire(ctx context.Context, key string, expiration time.Duration) *redis.BoolCmd

PExpire 毫秒为单位设置 key 的生存时间

func (*Client) PExpireAt

func (r *Client) PExpireAt(ctx context.Context, key string, tm time.Time) *redis.BoolCmd

PExpireAt 这个命令和 expireat 命令类似,但它以毫秒为单位设置 key 的过期 unix 时间戳,而不是像 expireat 那样,以秒为单位。 如果生存时间设置成功,返回 1 。 当 key 不存在或没办法设置生存时间时,返回 0

func (*Client) PFAdd

func (r *Client) PFAdd(ctx context.Context, key string, els ...interface{}) *redis.IntCmd

PFAdd 将指定元素添加到HyperLogLog

func (*Client) PFCount

func (r *Client) PFCount(ctx context.Context, keys ...string) *redis.IntCmd

PFCount 返回HyperlogLog观察到的集合的近似基数。

func (*Client) PFMerge

func (r *Client) PFMerge(ctx context.Context, dest string, keys ...string) *redis.StatusCmd

PFMerge N个不同的HyperLogLog合并为一个。

func (*Client) PSubscribe added in v1.6.21

func (r *Client) PSubscribe(ctx context.Context, channels ...string) *redis.PubSub

PSubscribe subscribes the client to the given patterns. Patterns can be omitted to create empty subscription.

func (*Client) PTTL

func (r *Client) PTTL(ctx context.Context, key string) *redis.DurationCmd

PTTL 这个命令类似于 TTL 命令,但它以毫秒为单位返回 key 的剩余生存时间,而不是像 TTL 命令那样,以秒为单位。 当 key 不存在时,返回 -2 。 当 key 存在但没有设置剩余生存时间时,返回 -1 。 否则,以毫秒为单位,返回 key 的剩余生存时间。

func (*Client) Persist

func (r *Client) Persist(ctx context.Context, key string) *redis.BoolCmd

Persist 移除给定 key 的生存时间,将这个 key 从『易失的』(带生存时间 key )转换成『持久的』(一个不带生存时间、永不过期的 key )。 当生存时间移除成功时,返回 1 . 如果 key 不存在或 key 没有设置生存时间,返回 0 。

func (*Client) Ping

func (r *Client) Ping(ctx context.Context) *redis.StatusCmd

Ping 使用客户端向 Redis 服务器发送一个 PING ,如果服务器运作正常的话,会返回一个 PONG 。 通常用于测试与服务器的连接是否仍然生效,或者用于测量延迟值。 如果连接正常就返回一个 PONG ,否则返回一个连接错误。

func (*Client) Pipeline

func (r *Client) Pipeline() redis.Pipeliner

Pipeline 获取管道

func (*Client) Pipelined

func (r *Client) Pipelined(ctx context.Context, fn func(redis.Pipeliner) error) ([]redis.Cmder, error)

Pipelined 管道

func (*Client) Prefix

func (r *Client) Prefix(key string) string

Prefix 返回前缀+键

func (*Client) PubSubChannels

func (r *Client) PubSubChannels(ctx context.Context, pattern string) *redis.StringSliceCmd

PubSubChannels 订阅一个或多个符合给定模式的频道。

func (*Client) PubSubNumPat

func (r *Client) PubSubNumPat(ctx context.Context) *redis.IntCmd

PubSubNumPat 用于获取redis订阅或者发布信息的状态

func (*Client) PubSubNumSub

func (r *Client) PubSubNumSub(ctx context.Context, channels ...string) *redis.StringIntMapCmd

PubSubNumSub 查看订阅与发布系统状态。

func (*Client) Publish

func (r *Client) Publish(ctx context.Context, channel string, message interface{}) *redis.IntCmd

Publish 将信息发送到指定的频道。

func (*Client) Quit

func (r *Client) Quit(ctx context.Context) *redis.StatusCmd

Quit 关闭连接

func (*Client) RPop

func (r *Client) RPop(ctx context.Context, key string) *redis.StringCmd

RPop 移除并返回列表 key 的尾元素。

func (*Client) RPopLPush

func (r *Client) RPopLPush(ctx context.Context, source, destination string) *redis.StringCmd

RPopLPush 命令 RPOPLPUSH 在一个原子时间内,执行以下两个动作: 将列表 source 中的最后一个元素(尾元素)弹出,并返回给客户端。 将 source 弹出的元素插入到列表 destination ,作为 destination 列表的的头元素。 举个例子,你有两个列表 source 和 destination , source 列表有元素 a, b, c , destination 列表有元素 x, y, z ,执行 RPOPLPUSH source destination 之后, source 列表包含元素 a, b , destination 列表包含元素 c, x, y, z ,并且元素 c 会被返回给客户端。 如果 source 不存在,值 nil 被返回,并且不执行其他动作。 如果 source 和 destination 相同,则列表中的表尾元素被移动到表头,并返回该元素,可以把这种特殊情况视作列表的旋转(rotation)操作。

func (*Client) RPush

func (r *Client) RPush(ctx context.Context, key string, values ...interface{}) *redis.IntCmd

RPush 将一个或多个值 value 插入到列表 key 的表尾(最右边)。 如果有多个 value 值,那么各个 value 值按从左到右的顺序依次插入到表尾:比如对一个空列表 mylist 执行 RPUSH mylist a b c ,得出的结果列表为 a b c ,等同于执行命令 RPUSH mylist a 、 RPUSH mylist b 、 RPUSH mylist c 。 如果 key 不存在,一个空列表会被创建并执行 RPUSH 操作。 当 key 存在但不是列表类型时,返回一个错误。

func (*Client) RPushX

func (r *Client) RPushX(ctx context.Context, key string, value interface{}) *redis.IntCmd

RPushX 将值 value 插入到列表 key 的表尾,当且仅当 key 存在并且是一个列表。 和 RPUSH 命令相反,当 key 不存在时, RPUSHX 命令什么也不做。

func (*Client) RandomKey

func (r *Client) RandomKey(ctx context.Context) *redis.StringCmd

RandomKey 从当前数据库中随机返回(不删除)一个 key 。

func (*Client) ReadOnly

func (r *Client) ReadOnly(ctx context.Context) *redis.StatusCmd

ReadOnly Enables read queries for a connection to a cluster replica node

func (*Client) ReadWrite

func (r *Client) ReadWrite(ctx context.Context) *redis.StatusCmd

ReadWrite Disables read queries for a connection to a cluster replica node

func (*Client) Rename

func (r *Client) Rename(ctx context.Context, key, newkey string) *redis.StatusCmd

Rename 将 key 改名为 newkey 。 当 key 和 newkey 相同,或者 key 不存在时,返回一个错误。 当 newkey 已经存在时, RENAME 命令将覆盖旧值。

func (*Client) RenameNX

func (r *Client) RenameNX(ctx context.Context, key, newkey string) *redis.BoolCmd

RenameNX 当且仅当 newkey 不存在时,将 key 改名为 newkey 。 当 key 不存在时,返回一个错误。

func (*Client) Restore

func (r *Client) Restore(ctx context.Context, key string, ttl time.Duration, value string) *redis.StatusCmd

Restore 反序列化给定的序列化值,并将它和给定的 key 关联。 参数 ttl 以毫秒为单位为 key 设置生存时间;如果 ttl 为 0 ,那么不设置生存时间。 RESTORE 在执行反序列化之前会先对序列化值的 RDB 版本和数据校验和进行检查,如果 RDB 版本不相同或者数据不完整的话,那么 RESTORE 会拒绝进行反序列化,并返回一个错误。

func (*Client) RestoreReplace

func (r *Client) RestoreReplace(ctx context.Context, key string, ttl time.Duration, value string) *redis.StatusCmd

RestoreReplace -> Restore

func (*Client) SAdd

func (r *Client) SAdd(ctx context.Context, key string, members ...interface{}) *redis.IntCmd

SAdd 将一个或多个 member 元素加入到集合 key 当中,已经存在于集合的 member 元素将被忽略。 假如 key 不存在,则创建一个只包含 member 元素作成员的集合。 当 key 不是集合类型时,返回一个错误。

func (*Client) SCard

func (r *Client) SCard(ctx context.Context, key string) *redis.IntCmd

SCard 返回集合 key 的基数(集合中元素的数量)。

func (*Client) SDiff

func (r *Client) SDiff(ctx context.Context, keys ...string) *redis.StringSliceCmd

SDiff 返回一个集合的全部成员,该集合是所有给定集合之间的差集。 不存在的 key 被视为空集。

func (*Client) SDiffStore

func (r *Client) SDiffStore(ctx context.Context, destination string, keys ...string) *redis.IntCmd

SDiffStore 这个命令的作用和 SDIFF 类似,但它将结果保存到 destination 集合,而不是简单地返回结果集。 如果 destination 集合已经存在,则将其覆盖。 destination 可以是 key 本身。

func (*Client) SInter

func (r *Client) SInter(ctx context.Context, keys ...string) *redis.StringSliceCmd

SInter 返回一个集合的全部成员,该集合是所有给定集合的交集。 不存在的 key 被视为空集。 当给定集合当中有一个空集时,结果也为空集(根据集合运算定律)。

func (*Client) SInterStore

func (r *Client) SInterStore(ctx context.Context, destination string, keys ...string) *redis.IntCmd

SInterStore 这个命令类似于 SINTER 命令,但它将结果保存到 destination 集合,而不是简单地返回结果集。 如果 destination 集合已经存在,则将其覆盖。 destination 可以是 key 本身。

func (*Client) SIsMember

func (r *Client) SIsMember(ctx context.Context, key string, member interface{}) *redis.BoolCmd

SIsMember 判断 member 元素是否集合 key 的成员。

func (*Client) SMembers

func (r *Client) SMembers(ctx context.Context, key string) *redis.StringSliceCmd

SMembers 返回集合 key 中的所有成员。 不存在的 key 被视为空集合。

func (*Client) SMembersMap

func (r *Client) SMembersMap(ctx context.Context, key string) *redis.StringStructMapCmd

SMembersMap -> SMembers

func (*Client) SMove

func (r *Client) SMove(ctx context.Context, source, destination string, member interface{}) *redis.BoolCmd

SMove 将 member 元素从 source 集合移动到 destination 集合。 SMOVE 是原子性操作。 如果 source 集合不存在或不包含指定的 member 元素,则 SMOVE 命令不执行任何操作,仅返回 0 。否则, member 元素从 source 集合中被移除,并添加到 destination 集合中去。 当 destination 集合已经包含 member 元素时, SMOVE 命令只是简单地将 source 集合中的 member 元素删除。 当 source 或 destination 不是集合类型时,返回一个错误。

func (*Client) SPop

func (r *Client) SPop(ctx context.Context, key string) *redis.StringCmd

SPop 移除并返回集合中的一个随机元素。 如果只想获取一个随机元素,但不想该元素从集合中被移除的话,可以使用 SRANDMEMBER 命令。

func (*Client) SPopN

func (r *Client) SPopN(ctx context.Context, key string, count int64) *redis.StringSliceCmd

SPopN -> SPop

func (*Client) SRandMember

func (r *Client) SRandMember(ctx context.Context, key string) *redis.StringCmd

SRandMember 如果命令执行时,只提供了 key 参数,那么返回集合中的一个随机元素。 从 Redis 2.6 版本开始, SRANDMEMBER 命令接受可选的 count 参数: 如果 count 为正数,且小于集合基数,那么命令返回一个包含 count 个元素的数组,数组中的元素各不相同。如果 count 大于等于集合基数,那么返回整个集合。 如果 count 为负数,那么命令返回一个数组,数组中的元素可能会重复出现多次,而数组的长度为 count 的绝对值。 该操作和 SPOP 相似,但 SPOP 将随机元素从集合中移除并返回,而 SRANDMEMBER 则仅仅返回随机元素,而不对集合进行任何改动。

func (*Client) SRandMemberN

func (r *Client) SRandMemberN(ctx context.Context, key string, count int64) *redis.StringSliceCmd

SRandMemberN -> SRandMember

func (*Client) SRem

func (r *Client) SRem(ctx context.Context, key string, members ...interface{}) *redis.IntCmd

SRem 移除集合 key 中的一个或多个 member 元素,不存在的 member 元素会被忽略。 当 key 不是集合类型,返回一个错误。

func (*Client) SScan

func (r *Client) SScan(ctx context.Context, key string, cursor uint64, match string, count int64) *redis.ScanCmd

SScan 详细信息请参考 SCAN 命令。

func (*Client) SUnion

func (r *Client) SUnion(ctx context.Context, keys ...string) *redis.StringSliceCmd

SUnion 返回一个集合的全部成员,该集合是所有给定集合的并集。 不存在的 key 被视为空集。

func (*Client) SUnionStore

func (r *Client) SUnionStore(ctx context.Context, destination string, keys ...string) *redis.IntCmd

SUnionStore 这个命令类似于 SUNION 命令,但它将结果保存到 destination 集合,而不是简单地返回结果集。 如果 destination 已经存在,则将其覆盖。 destination 可以是 key 本身。

func (*Client) Save

func (r *Client) Save(ctx context.Context) *redis.StatusCmd

Save 异步保存数据到硬盘

func (*Client) Scan

func (r *Client) Scan(ctx context.Context, cursor uint64, match string, count int64) *redis.ScanCmd

Scan 命令及其相关的 SSCAN 命令、 HSCAN 命令和 ZSCAN 命令都用于增量地迭代(incrementally iterate)一集元素

func (*Client) ScriptExists

func (r *Client) ScriptExists(ctx context.Context, hashes ...string) *redis.BoolSliceCmd

ScriptExists 查看指定的脚本是否已经被保存在缓存当中。

func (*Client) ScriptFlush

func (r *Client) ScriptFlush(ctx context.Context) *redis.StatusCmd

ScriptFlush 从脚本缓存中移除所有脚本。

func (*Client) ScriptKill

func (r *Client) ScriptKill(ctx context.Context) *redis.StatusCmd

ScriptKill 杀死当前正在运行的 Lua 脚本。

func (*Client) ScriptLoad

func (r *Client) ScriptLoad(ctx context.Context, script string) *redis.StringCmd

ScriptLoad 将脚本 script 添加到脚本缓存中,但并不立即执行这个脚本。

func (*Client) Set

func (r *Client) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.StatusCmd

Set 将字符串值 value 关联到 key 。 如果 key 已经持有其他值, SET 就覆写旧值,无视类型。 对于某个原本带有生存时间(TTL)的键来说, 当 SET 命令成功在这个键上执行时, 这个键原有的 TTL 将被清除。

func (*Client) SetBit

func (r *Client) SetBit(ctx context.Context, key string, offset int64, value int) *redis.IntCmd

SetBit 对 key 所储存的字符串值,设置或清除指定偏移量上的位(bit)。 位的设置或清除取决于 value 参数,可以是 0 也可以是 1 。 当 key 不存在时,自动生成一个新的字符串值。 字符串会进行伸展(grown)以确保它可以将 value 保存在指定的偏移量上。当字符串值进行伸展时,空白位置以 0 填充。 offset 参数必须大于或等于 0 ,小于 2^32 (bit 映射被限制在 512 MB 之内)。

func (*Client) SetEX added in v1.7.4

func (r *Client) SetEX(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.StatusCmd

func (*Client) SetNX

func (r *Client) SetNX(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.BoolCmd

SetNX 将 key 的值设为 value ,当且仅当 key 不存在。 若给定的 key 已经存在,则 SETNX 不做任何动作。 SETNX 是『SET if Not eXists』(如果不存在,则 SET)的简写。

func (*Client) SetRange

func (r *Client) SetRange(ctx context.Context, key string, offset int64, value string) *redis.IntCmd

SetRange 用 value 参数覆写(overwrite)给定 key 所储存的字符串值,从偏移量 offset 开始。 不存在的 key 当作空白字符串处理。

func (*Client) SetXX

func (r *Client) SetXX(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.BoolCmd

SetXX -> SetNX

func (*Client) Shutdown

func (r *Client) Shutdown(ctx context.Context) *redis.StatusCmd

Shutdown 关闭服务器

func (*Client) ShutdownNoSave

func (r *Client) ShutdownNoSave(ctx context.Context) *redis.StatusCmd

ShutdownNoSave 不保存数据到硬盘,并关闭服务器

func (*Client) ShutdownSave

func (r *Client) ShutdownSave(ctx context.Context) *redis.StatusCmd

ShutdownSave 异步保存数据到硬盘,并关闭服务器

func (*Client) SlaveOf

func (r *Client) SlaveOf(ctx context.Context, host, port string) *redis.StatusCmd

SlaveOf 将当前服务器转变为指定服务器的从属服务器(slave server)

func (*Client) Sort

func (r *Client) Sort(ctx context.Context, key string, sort *redis.Sort) *redis.StringSliceCmd

Sort 返回或保存给定列表、集合、有序集合 key 中经过排序的元素。 排序默认以数字作为对象,值被解释为双精度浮点数,然后进行比较。

func (*Client) SortInterfaces

func (r *Client) SortInterfaces(ctx context.Context, key string, sort *redis.Sort) *redis.SliceCmd

SortInterfaces -> Sort

func (*Client) SortStore

func (r *Client) SortStore(ctx context.Context, key, store string, sort *redis.Sort) *redis.IntCmd

SortStore -> Sort

func (*Client) StrLen

func (r *Client) StrLen(ctx context.Context, key string) *redis.IntCmd

StrLen 返回 key 所储存的字符串值的长度。 当 key 储存的不是字符串值时,返回一个错误。

func (*Client) Subscribe added in v1.6.21

func (r *Client) Subscribe(ctx context.Context, channels ...string) *redis.PubSub

Subscribe subscribes the client to the specified channels. Channels can be omitted to create empty subscription.

func (*Client) TTL

func (r *Client) TTL(ctx context.Context, key string) *redis.DurationCmd

TTL 以秒为单位,返回给定 key 的剩余生存时间(TTL, time to live)。 当 key 不存在时,返回 -2 。 当 key 存在但没有设置剩余生存时间时,返回 -1 。 否则,以秒为单位,返回 key 的剩余生存时间。

func (*Client) Time

func (r *Client) Time(ctx context.Context) *redis.TimeCmd

Time 返回当前服务器时间

func (*Client) Touch

func (r *Client) Touch(ctx context.Context, keys ...string) *redis.IntCmd

Touch 更改键的上次访问时间。返回指定的现有键的数量。

func (*Client) TxPipeline

func (r *Client) TxPipeline() redis.Pipeliner

TxPipeline 获取管道

func (*Client) TxPipelined

func (r *Client) TxPipelined(ctx context.Context, fn func(redis.Pipeliner) error) ([]redis.Cmder, error)

TxPipelined 管道

func (*Client) Type

func (r *Client) Type(ctx context.Context, key string) *redis.StatusCmd

Type 返回 key 所储存的值的类型。

func (r *Client) Unlink(ctx context.Context, keys ...string) *redis.IntCmd

Unlink 这个命令非常类似于DEL:它删除指定的键。就像DEL键一样,如果它不存在,它将被忽略。但是,该命令在不同的线程中执行实际的内存回收,所以它不会阻塞,而DEL是。这是命令名称的来源:命令只是将键与键空间断开连接。实际删除将在以后异步发生。

func (*Client) XAck

func (r *Client) XAck(ctx context.Context, stream, group string, ids ...string) *redis.IntCmd

XAck command

func (*Client) XAdd

func (r *Client) XAdd(ctx context.Context, a *redis.XAddArgs) *redis.StringCmd

XAdd 将指定的流条目追加到指定key的流中。 如果key不存在,作为运行这个命令的副作用,将使用流的条目自动创建key。

func (*Client) XClaim

func (r *Client) XClaim(ctx context.Context, a *redis.XClaimArgs) *redis.XMessageSliceCmd

XClaim command

func (*Client) XClaimJustID

func (r *Client) XClaimJustID(ctx context.Context, a *redis.XClaimArgs) *redis.StringSliceCmd

XClaimJustID command

func (*Client) XDel

func (r *Client) XDel(ctx context.Context, stream string, ids ...string) *redis.IntCmd

XDel 从指定流中移除指定的条目,并返回成功删除的条目的数量,在传递的ID不存在的情况下, 返回的数量可能与传递的ID数量不同。

func (*Client) XGroupCreate

func (r *Client) XGroupCreate(ctx context.Context, stream, group, start string) *redis.StatusCmd

XGroupCreate command

func (*Client) XGroupCreateMkStream

func (r *Client) XGroupCreateMkStream(ctx context.Context, stream, group, start string) *redis.StatusCmd

XGroupCreateMkStream command

func (*Client) XGroupDelConsumer

func (r *Client) XGroupDelConsumer(ctx context.Context, stream, group, consumer string) *redis.IntCmd

XGroupDelConsumer command

func (*Client) XGroupDestroy

func (r *Client) XGroupDestroy(ctx context.Context, stream, group string) *redis.IntCmd

XGroupDestroy command

func (*Client) XGroupSetID

func (r *Client) XGroupSetID(ctx context.Context, stream, group, start string) *redis.StatusCmd

XGroupSetID command

func (*Client) XInfoGroups

func (r *Client) XInfoGroups(ctx context.Context, key string) *redis.XInfoGroupsCmd

XInfoGroups command

func (*Client) XLen

func (r *Client) XLen(ctx context.Context, stream string) *redis.IntCmd

XLen 返回流中的条目数。如果指定的key不存在,则此命令返回0,就好像该流为空。 但是请注意,与其他的Redis类型不同,零长度流是可能的,所以你应该调用TYPE 或者 EXISTS 来检查一个key是否存在。 一旦内部没有任何的条目(例如调用XDEL后),流不会被自动删除,因为可能还存在与其相关联的消费者组。

func (*Client) XPending

func (r *Client) XPending(ctx context.Context, stream, group string) *redis.XPendingCmd

XPending command

func (*Client) XPendingExt

func (r *Client) XPendingExt(ctx context.Context, a *redis.XPendingExtArgs) *redis.XPendingExtCmd

XPendingExt command

func (*Client) XRange

func (r *Client) XRange(ctx context.Context, stream, start, stop string) *redis.XMessageSliceCmd

XRange 此命令返回流中满足给定ID范围的条目。范围由最小和最大ID指定。所有ID在指定的两个ID之间或与其中一个ID相等(闭合区间)的条目将会被返回。

func (*Client) XRangeN

func (r *Client) XRangeN(ctx context.Context, stream, start, stop string, count int64) *redis.XMessageSliceCmd

XRangeN -> XRange

func (*Client) XRead

func (r *Client) XRead(ctx context.Context, a *redis.XReadArgs) *redis.XStreamSliceCmd

XRead 从一个或者多个流中读取数据,仅返回ID大于调用者报告的最后接收ID的条目。此命令有一个阻塞选项,用于等待可用的项目,类似于BRPOP或者BZPOPMIN等等。

func (*Client) XReadGroup

func (r *Client) XReadGroup(ctx context.Context, a *redis.XReadGroupArgs) *redis.XStreamSliceCmd

XReadGroup command

func (*Client) XReadStreams

func (r *Client) XReadStreams(ctx context.Context, streams ...string) *redis.XStreamSliceCmd

XReadStreams -> XRead

func (*Client) XRevRange

func (r *Client) XRevRange(ctx context.Context, stream string, start, stop string) *redis.XMessageSliceCmd

XRevRange 此命令与XRANGE完全相同,但显著的区别是以相反的顺序返回条目,并以相反的顺序获取开始-结束参数:在XREVRANGE中,你需要先指定结束ID,再指定开始ID,该命令就会从结束ID侧开始生成两个ID之间(或完全相同)的所有元素。

func (*Client) XRevRangeN

func (r *Client) XRevRangeN(ctx context.Context, stream string, start, stop string, count int64) *redis.XMessageSliceCmd

XRevRangeN -> XRevRange

func (*Client) XTrim

func (r *Client) XTrim(ctx context.Context, key string, maxLen int64) *redis.IntCmd

XTrim command

func (*Client) XTrimApprox

func (r *Client) XTrimApprox(ctx context.Context, key string, maxLen int64) *redis.IntCmd

XTrimApprox command

func (*Client) ZAdd

func (r *Client) ZAdd(ctx context.Context, key string, members ...*redis.Z) *redis.IntCmd

ZAdd 将一个或多个 member 元素及其 score 值加入到有序集 key 当中。 如果某个 member 已经是有序集的成员,那么更新这个 member 的 score 值,并通过重新插入这个 member 元素,来保证该 member 在正确的位置上。 score 值可以是整数值或双精度浮点数。 如果 key 不存在,则创建一个空的有序集并执行 ZADD 操作。 当 key 存在但不是有序集类型时,返回一个错误。

func (*Client) ZAddCh

func (r *Client) ZAddCh(ctx context.Context, key string, members ...*redis.Z) *redis.IntCmd

ZAddCh -> ZAdd

func (*Client) ZAddNX

func (r *Client) ZAddNX(ctx context.Context, key string, members ...*redis.Z) *redis.IntCmd

ZAddNX -> ZAdd

func (*Client) ZAddNXCh

func (r *Client) ZAddNXCh(ctx context.Context, key string, members ...*redis.Z) *redis.IntCmd

ZAddNXCh -> ZAdd

func (*Client) ZAddXX

func (r *Client) ZAddXX(ctx context.Context, key string, members ...*redis.Z) *redis.IntCmd

ZAddXX -> ZAdd

func (*Client) ZAddXXCh

func (r *Client) ZAddXXCh(ctx context.Context, key string, members ...*redis.Z) *redis.IntCmd

ZAddXXCh -> ZAdd

func (*Client) ZCard

func (r *Client) ZCard(ctx context.Context, key string) *redis.IntCmd

ZCard 返回有序集 key 的基数。

func (*Client) ZCount

func (r *Client) ZCount(ctx context.Context, key, min, max string) *redis.IntCmd

ZCount 返回有序集 key 中, score 值在 min 和 max 之间(默认包括 score 值等于 min 或 max )的成员的数量。 关于参数 min 和 max 的详细使用方法,请参考 ZRANGEBYSCORE 命令。

func (*Client) ZIncr

func (r *Client) ZIncr(ctx context.Context, key string, member *redis.Z) *redis.FloatCmd

ZIncr Redis `ZADD key INCR score member` command.

func (*Client) ZIncrBy

func (r *Client) ZIncrBy(ctx context.Context, key string, increment float64, member string) *redis.FloatCmd

ZIncrBy 为有序集 key 的成员 member 的 score 值加上增量 increment 。 可以通过传递一个负数值 increment ,让 score 减去相应的值,比如 ZINCRBY key -5 member ,就是让 member 的 score 值减去 5 。 当 key 不存在,或 member 不是 key 的成员时, ZINCRBY key increment member 等同于 ZADD key increment member 。 当 key 不是有序集类型时,返回一个错误。 score 值可以是整数值或双精度浮点数。

func (*Client) ZIncrNX

func (r *Client) ZIncrNX(ctx context.Context, key string, member *redis.Z) *redis.FloatCmd

ZIncrNX Redis `ZADD key NX INCR score member` command.

func (*Client) ZIncrXX

func (r *Client) ZIncrXX(ctx context.Context, key string, member *redis.Z) *redis.FloatCmd

ZIncrXX Redis `ZADD key XX INCR score member` command.

func (*Client) ZInterStore

func (r *Client) ZInterStore(ctx context.Context, key string, store *redis.ZStore) *redis.IntCmd

ZInterStore 计算给定的一个或多个有序集的交集,其中给定 key 的数量必须以 numkeys 参数指定,并将该交集(结果集)储存到 destination 。 默认情况下,结果集中某个成员的 score 值是所有给定集下该成员 score 值之和. 关于 WEIGHTS 和 AGGREGATE 选项的描述,参见 ZUNIONSTORE 命令。

func (*Client) ZLexCount

func (r *Client) ZLexCount(ctx context.Context, key, min, max string) *redis.IntCmd

ZLexCount -> ZCount

func (*Client) ZPopMax

func (r *Client) ZPopMax(ctx context.Context, key string, count ...int64) *redis.ZSliceCmd

ZPopMax 删除并返回有序集合key中的最多count个具有最高得分的成员。

func (*Client) ZPopMin

func (r *Client) ZPopMin(ctx context.Context, key string, count ...int64) *redis.ZSliceCmd

ZPopMin 删除并返回有序集合key中的最多count个具有最低得分的成员。

func (*Client) ZRange

func (r *Client) ZRange(ctx context.Context, key string, start, stop int64) *redis.StringSliceCmd

ZRange 返回有序集 key 中,指定区间内的成员。 其中成员的位置按 score 值递增(从小到大)来排序。

func (*Client) ZRangeByLex

func (r *Client) ZRangeByLex(ctx context.Context, key string, opt *redis.ZRangeBy) *redis.StringSliceCmd

ZRangeByLex -> ZRangeByScore

func (*Client) ZRangeByScore

func (r *Client) ZRangeByScore(ctx context.Context, key string, opt *redis.ZRangeBy) *redis.StringSliceCmd

ZRangeByScore 返回有序集 key 中,所有 score 值介于 min 和 max 之间(包括等于 min 或 max )的成员。有序集成员按 score 值递增(从小到大)次序排列。

func (*Client) ZRangeByScoreWithScores

func (r *Client) ZRangeByScoreWithScores(ctx context.Context, key string, opt *redis.ZRangeBy) *redis.ZSliceCmd

ZRangeByScoreWithScores -> ZRangeByScore

func (*Client) ZRangeWithScores

func (r *Client) ZRangeWithScores(ctx context.Context, key string, start, stop int64) *redis.ZSliceCmd

ZRangeWithScores -> ZRange

func (*Client) ZRank

func (r *Client) ZRank(ctx context.Context, key, member string) *redis.IntCmd

ZRank 返回有序集 key 中成员 member 的排名。其中有序集成员按 score 值递增(从小到大)顺序排列。 排名以 0 为底,也就是说, score 值最小的成员排名为 0 。 使用 ZREVRANK 命令可以获得成员按 score 值递减(从大到小)排列的排名。

func (*Client) ZRem

func (r *Client) ZRem(ctx context.Context, key string, members ...interface{}) *redis.IntCmd

ZRem 移除有序集 key 中的一个或多个成员,不存在的成员将被忽略。 当 key 存在但不是有序集类型时,返回一个错误。

func (*Client) ZRemRangeByLex

func (r *Client) ZRemRangeByLex(ctx context.Context, key, min, max string) *redis.IntCmd

ZRemRangeByLex -> ZRemRangeByScore

func (*Client) ZRemRangeByRank

func (r *Client) ZRemRangeByRank(ctx context.Context, key string, start, stop int64) *redis.IntCmd

ZRemRangeByRank 移除有序集 key 中,指定排名(rank)区间内的所有成员。 区间分别以下标参数 start 和 stop 指出,包含 start 和 stop 在内。 下标参数 start 和 stop 都以 0 为底,也就是说,以 0 表示有序集第一个成员,以 1 表示有序集第二个成员,以此类推。 你也可以使用负数下标,以 -1 表示最后一个成员, -2 表示倒数第二个成员,以此类推

func (*Client) ZRemRangeByScore

func (r *Client) ZRemRangeByScore(ctx context.Context, key, min, max string) *redis.IntCmd

ZRemRangeByScore 移除有序集 key 中,所有 score 值介于 min 和 max 之间(包括等于 min 或 max )的成员。 自版本2.1.6开始, score 值等于 min 或 max 的成员也可以不包括在内,详情请参见 ZRANGEBYSCORE 命令。

func (*Client) ZRevRange

func (r *Client) ZRevRange(ctx context.Context, key string, start, stop int64) *redis.StringSliceCmd

ZRevRange 返回有序集 key 中,指定区间内的成员。 其中成员的位置按 score 值递减(从大到小)来排列。 具有相同 score 值的成员按字典序的逆序(reverse lexicographical order)排列。 除了成员按 score 值递减的次序排列这一点外, ZREVRANGE 命令的其他方面和 ZRANGE 命令一样。

func (*Client) ZRevRangeByLex

func (r *Client) ZRevRangeByLex(ctx context.Context, key string, opt *redis.ZRangeBy) *redis.StringSliceCmd

ZRevRangeByLex -> ZRevRangeByScore

func (*Client) ZRevRangeByScore

func (r *Client) ZRevRangeByScore(ctx context.Context, key string, opt *redis.ZRangeBy) *redis.StringSliceCmd

ZRevRangeByScore 返回有序集 key 中, score 值介于 max 和 min 之间(默认包括等于 max 或 min )的所有的成员。有序集成员按 score 值递减(从大到小)的次序排列。 具有相同 score 值的成员按字典序的逆序(reverse lexicographical order )排列。 除了成员按 score 值递减的次序排列这一点外, ZREVRANGEBYSCORE 命令的其他方面和 ZRANGEBYSCORE 命令一样。

func (*Client) ZRevRangeByScoreWithScores

func (r *Client) ZRevRangeByScoreWithScores(ctx context.Context, key string, opt *redis.ZRangeBy) *redis.ZSliceCmd

ZRevRangeByScoreWithScores -> ZRevRangeByScore

func (*Client) ZRevRangeWithScores

func (r *Client) ZRevRangeWithScores(ctx context.Context, key string, start, stop int64) *redis.ZSliceCmd

ZRevRangeWithScores -> ZRevRange

func (*Client) ZRevRank

func (r *Client) ZRevRank(ctx context.Context, key, member string) *redis.IntCmd

ZRevRank 返回有序集 key 中成员 member 的排名。其中有序集成员按 score 值递减(从大到小)排序。 排名以 0 为底,也就是说, score 值最大的成员排名为 0 。 使用 ZRANK 命令可以获得成员按 score 值递增(从小到大)排列的排名。

func (*Client) ZScan

func (r *Client) ZScan(ctx context.Context, key string, cursor uint64, match string, count int64) *redis.ScanCmd

ZScan 详细信息请参考 SCAN 命令。

func (*Client) ZScore

func (r *Client) ZScore(ctx context.Context, key, member string) *redis.FloatCmd

ZScore 返回有序集 key 中,成员 member 的 score 值。 如果 member 元素不是有序集 key 的成员,或 key 不存在,返回 nil 。

func (*Client) ZUnionStore

func (r *Client) ZUnionStore(ctx context.Context, dest string, store *redis.ZStore) *redis.IntCmd

ZUnionStore 计算给定的一个或多个有序集的并集,其中给定 key 的数量必须以 numkeys 参数指定,并将该并集(结果集)储存到 destination 。 默认情况下,结果集中某个成员的 score 值是所有给定集下该成员 score 值之 和 。

type ClientType

type ClientType string

ClientType type to define a redis client connector

const (
	// ClientNormal for standard instance client
	ClientNormal ClientType = "normal"
	// ClientCluster for official redis cluster
	ClientCluster ClientType = "cluster"
)

type Config

type Config struct {
	Type      bool     //是否集群
	Hosts     []string //IP
	Password  string   //密码
	Database  int      //数据库
	PoolSize  int      //连接池大小
	KeyPrefix string
}

Config 配置

type OpenTelemetryHook

type OpenTelemetryHook struct{}

func (OpenTelemetryHook) AfterProcess

func (OpenTelemetryHook) AfterProcess(ctx context.Context, cmd redis.Cmder) error

func (OpenTelemetryHook) AfterProcessPipeline

func (OpenTelemetryHook) AfterProcessPipeline(ctx context.Context, cmds []redis.Cmder) error

func (OpenTelemetryHook) BeforeProcess

func (OpenTelemetryHook) BeforeProcess(ctx context.Context, cmd redis.Cmder) (context.Context, error)

func (OpenTelemetryHook) BeforeProcessPipeline

func (OpenTelemetryHook) BeforeProcessPipeline(ctx context.Context, cmds []redis.Cmder) (context.Context, error)

type Options

type Options struct {
	Type ClientType
	// Host address with port number
	// For normal client will only used the first value
	Hosts []string

	// The network type, either tcp or unix.
	// Default is tcp.
	// Only for normal client
	Network string

	// Database to be selected after connecting to the server.
	Database int
	// Automatically adds a prefix to all keys
	KeyPrefix string

	// The maximum number of retries before giving up. Command is retried
	// on network errors and MOVED/ASK redirects.
	// Default is 16.
	// In normal client this is the MaxRetries option
	MaxRedirects int

	// Enables read queries for a connection to a Redis Cluster slave node.
	ReadOnly bool

	// Enables routing read-only queries to the closest master or slave node.
	// If set will change this client to read-only mode
	RouteByLatency bool

	// Following options are copied from Options struct.
	Password string

	// Dial timeout for establishing new connections.
	// Default is 5 seconds.
	DialTimeout time.Duration
	// Timeout for socket reads. If reached, commands will fail
	// with a timeout instead of blocking.
	// Default is 3 seconds.
	ReadTimeout time.Duration
	// Timeout for socket writes. If reached, commands will fail
	// with a timeout instead of blocking.
	// Default is 3 seconds.
	WriteTimeout time.Duration

	// PoolSize applies per cluster node and not for the whole cluster.
	// Maximum number of socket connections.
	// Default is 10 connections.
	PoolSize int
	// Amount of time client waits for connection if all connections
	// are busy before returning an error.
	// Default is ReadTimeout + 1 second.
	PoolTimeout time.Duration
	// Amount of time after which client closes idle connections.
	// Should be less than server's timeout.
	// Default is to not close idle connections.
	IdleTimeout time.Duration
	// Frequency of idle checks.
	// Default is 1 minute.
	// When minus value is set, then idle check is disabled.
	IdleCheckFrequency time.Duration

	// TLS Config to use. When set TLS will be negotiated.
	// Only for normal client
	TLSConfig *tls.Config
}

Options options to initiate your client

func (Options) GetClusterConfig

func (o Options) GetClusterConfig() *redis.ClusterOptions

GetClusterConfig translates current configuration into a *redis.ClusterOptions

func (Options) GetNormalConfig

func (o Options) GetNormalConfig() *redis.Options

GetNormalConfig translates current configuration into a *redis.Options struct

type Proxy

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

Proxy 代理

func NewProxy

func NewProxy() *Proxy

NewProxy 代理池

func (*Proxy) NameSpace

func (proxy *Proxy) NameSpace(group string) *Client

NameSpace 获取分组

func (*Proxy) SetNameSpace

func (proxy *Proxy) SetNameSpace(group string, client *Client)

SetNameSpace 设置组

type RWType

type RWType string

Client Reader and Writer

const (
	// OnlyRead serves as a search suffix for configuration parameters
	OnlyRead RWType = "READER"
	// OnlyWrite serves as a search suffix for configuration parameters
	OnlyWrite RWType = "WRITER"
	// ReadAndWrite serves as a search suffix for configuration parameters
	ReadAndWrite RWType = ""
)

func (*RWType) FmtSuffix

func (rw *RWType) FmtSuffix(key string) string

FmtSuffix get fmtstring of key+ "_" + suffix

func (*RWType) IsReadOnly

func (rw *RWType) IsReadOnly() bool

IsReadOnly will return Is it read-only

Jump to

Keyboard shortcuts

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