Documentation ¶
Overview ¶
redis组件 特别说明:该组件要求redis版本使用7.0.0以上,引入了redis7.0的一些新特性,否则有些方法会不支持
Redis 位图 ¶
Redis Database相关操作 ¶
生命周期相关
地理位置(本质是有序集合)
哈希表
Redis HyperLogLog ¶
列表
scan迭代,针对全数据库的键,返回的每个元素都是一个数据库键
集合
字符串
Redis transaction 事务管理 ¶
有序集合
Index ¶
- type Client
- type Config
- type Rbit
- func (b *Rbit) Bitcount(key string, start, end int) (int, error)
- func (b *Rbit) BitcountIndex(key string, start, end int, indexType string) (int, error)
- func (b *Rbit) Bitop(operation, destkey string, keys []string) (int, error)
- func (b *Rbit) Bitpos(key string, bit, start, end int) (int, error)
- func (b *Rbit) BitposIndex(key string, bit, start, end int, indexType string) (int, error)
- func (b *Rbit) Getbit(key string, offset int) (int, error)
- func (b *Rbit) Setbit(key string, offset, value int) (int, error)
- type Rdb
- func (c *Rdb) Copy(source, destination string) (reply int, err error)
- func (c *Rdb) Dbsize() (int, error)
- func (c *Rdb) Del(keys []string) (reply int, err error)
- func (c *Rdb) Exists(keys []string) (reply int, err error)
- func (c *Rdb) FlushAll(mode string)
- func (c *Rdb) FlushDb(mode string)
- func (c *Rdb) Move(key string, destinationDb int) (reply int, err error)
- func (c *Rdb) Rename(key, newKey string) (reply string, err error)
- func (c *Rdb) RenameNx(key, newKey string) (reply string, err error)
- func (c *Rdb) Select(index int) (string, error)
- func (c *Rdb) Touch(keys []string) (reply int, err error)
- func (c *Rdb) Type(key string) (reply string, err error)
- func (c *Rdb) Unlink(keys []string) (reply int, err error)
- type Rexpire
- func (c *Rexpire) Expire(key string, seconds int, options string) (reply int, err error)
- func (c *Rexpire) ExpireAt(key string, timestamp int, options string) (reply int, err error)
- func (c *Rexpire) ExpireTime(key string) (reply int, err error)
- func (c *Rexpire) Persist(key string) (reply int, err error)
- func (c *Rexpire) Pexpire(key string, milliseconds int, options string) (reply int, err error)
- func (c *Rexpire) PexpireAt(key string, miltimestamp int64, options string) (reply int, err error)
- func (c *Rexpire) PexpireTime(key string) (reply int64, err error)
- func (c *Rexpire) Ttl(key string) (reply int, err error)
- type Rgeo
- func (c *Rgeo) GeoAdd(key string, points [][3]string, elementCondition string, isCh bool) (int, error)
- func (c *Rgeo) GeoDist(key string, members [2]string, unit string) (string, error)
- func (c *Rgeo) GeoHash(key string, members []string) (map[string]string, error)
- func (c *Rgeo) GeoPos(key string, members []string) (arr []map[string]string, err error)
- func (c *Rgeo) GeoSearchFromLonlatHasWith(key string, poi [2]string, byType []string, sort string, count [2]int) ([]map[string]string, error)
- func (c *Rgeo) GeoSearchFromLonlatNoWith(key string, poi [2]string, byType []string, sort string, count [2]int) ([]string, error)
- func (c *Rgeo) GeoSearchFromLonlatStore(destination, source string, poi [2]string, byType []string, sort string, ...) (int, error)
- func (c *Rgeo) GeoSearchFromMemberHasWith(key, member string, byType []string, sort string, count [2]int) ([]map[string]string, error)
- func (c *Rgeo) GeoSearchFromMemberNoWith(key, member string, byType []string, sort string, count [2]int) ([]string, error)
- func (c *Rgeo) GeoSearchFromMemberStore(destination, source, member string, byType []string, sort string, count [2]int, ...) (int, error)
- type Rhash
- func (c *Rhash) Hdel(key string, fields []string) (reply int, err error)
- func (c *Rhash) Hexists(key, field string) (reply int, err error)
- func (c *Rhash) Hget(key, field string) (reply string, err error)
- func (c *Rhash) HgetAll(key string) (reply map[string]string, err error)
- func (c *Rhash) HincrBy(key, field string, increment int) (reply int, err error)
- func (c *Rhash) HincrByFloat(key, field string, increment float64) (reply float64, err error)
- func (c *Rhash) Hkeys(key string) (reply []string, err error)
- func (c *Rhash) Hlen(key string) (reply int, err error)
- func (c *Rhash) Hmget(key string, fields []string) (reply []string, err error)
- func (c *Rhash) Hset(key string, fieldValues [][2]string) (reply int, err error)
- func (c *Rhash) HsetNx(key, field, value string) (reply int, err error)
- func (c *Rhash) HstrLen(key, field string) (reply int, err error)
- func (c *Rhash) Hvals(key string) (reply []string, err error)
- func (c *Rhash) ScanAll(key string, pattern string, count int) [][2]string
- func (c *Rhash) ScanDel(key string, pattern string, count int) (nums int)
- func (c *Rhash) ScanOnce(key string, cursor int, pattern string, count int) (int, [][2]string, error)
- type Rhyper
- type Rlist
- func (c *Rlist) Lindex(key string, index int) (string, error)
- func (c *Rlist) Linsert(key, condition, pivot, element string) (int, error)
- func (c *Rlist) Llen(key string) (int, error)
- func (c *Rlist) Lmove(source, destination, wherefrom, whereto string) (string, error)
- func (c *Rlist) Lmpop(keys []string, condition string, count int) (keyName string, arr []string, err error)
- func (c *Rlist) Lpop(key string, count int) ([]string, error)
- func (c *Rlist) Lpos(key, element string, rank, count, maxlen int) ([]int, error)
- func (c *Rlist) Lpush(key string, elements []string) (int, error)
- func (c *Rlist) Lpushx(key string, elements []string) (int, error)
- func (c *Rlist) Lrange(key string, start, stop int) ([]string, error)
- func (c *Rlist) Lrem(key string, count int, element string) (int, error)
- func (c *Rlist) Lset(key string, index int, element string) (string, error)
- func (c *Rlist) Ltrim(key string, start, stop int) (string, error)
- func (c *Rlist) Rpop(key string, count int) ([]string, error)
- func (c *Rlist) Rpush(key string, elements []string) (int, error)
- func (c *Rlist) Rpushx(key string, elements []string) (int, error)
- type Rscan
- type Rset
- func (c *Rset) Sadd(key string, members []string) (int, error)
- func (c *Rset) ScanAll(key string, pattern string, count int) (arr []string)
- func (c *Rset) ScanDel(key string, pattern string, count int) (nums int)
- func (c *Rset) ScanOnce(key string, cursor int, pattern string, count int) (int, []string, error)
- func (c *Rset) Scard(key string) (int, error)
- func (c *Rset) Sdiff(key string, diffKeys []string) ([]string, error)
- func (c *Rset) SdiffStore(key string, diffKeys []string, destination string) (int, error)
- func (c *Rset) Sinter(keys []string) ([]string, error)
- func (c *Rset) SinterCard(keys []string, limit int) (int, error)
- func (c *Rset) SinterStore(keys []string, destination string) (int, error)
- func (c *Rset) Sismember(key, member string) (int, error)
- func (c *Rset) Smembers(key string) ([]string, error)
- func (c *Rset) Smismember(key string, members []string) ([]int, error)
- func (c *Rset) Smove(source, destination, member string) (int, error)
- func (c *Rset) Spop(key string, count int) ([]string, error)
- func (c *Rset) Srandmember(key string, count int) ([]string, error)
- func (c *Rset) Srem(key string, members []string) (int, error)
- func (c *Rset) Sunion(keys []string) ([]string, error)
- func (c *Rset) SunionStore(keys []string, destination string) ([]string, error)
- type Rstring
- func (c *Rstring) Append(key, value string) (reply int, err error)
- func (c *Rstring) Decr(key string) (reply int, err error)
- func (c *Rstring) DecrBy(key string, decrement int) (reply int, err error)
- func (c *Rstring) Get(key string) (reply string, err error)
- func (c *Rstring) GetDel(key string) (reply string, err error)
- func (c *Rstring) GetEx(key, expireType string, timeout int64) (reply string, err error)
- func (c *Rstring) GetRange(key string, start, end int) (reply string, err error)
- func (c *Rstring) GetSet(key, value string) (reply string, err error)
- func (c *Rstring) Incr(key string) (reply int, err error)
- func (c *Rstring) IncrBy(key string, increment int) (reply int, err error)
- func (c *Rstring) IncrByFloat(key string, increment float64) (reply float64, err error)
- func (c *Rstring) Mget(keys []string) (reply []string, err error)
- func (c *Rstring) Mset(keyValues [][2]string) (reply string, err error)
- func (c *Rstring) MsetNx(keyValues [][2]string) (reply int, err error)
- func (c *Rstring) PsetEx(key, value string, milliseconds int) (reply string, err error)
- func (c *Rstring) Set(key, value, condition, expireType string, timeout int64) (reply string, err error)
- func (c *Rstring) SetEx(key, value string, seconds int) (reply string, err error)
- func (c *Rstring) SetGet(key, value, condition, expireType string, timeout int64) (reply string, err error)
- func (c *Rstring) SetNx(key, value string) (reply int, err error)
- func (c *Rstring) SetRange(key, value string, offset int) (reply int, err error)
- func (c *Rstring) Strlen(key string) (reply int, err error)
- type Rtransaction
- type Rzset
- func (c *Rzset) ScanAll(key string, pattern string, count int) (arr [][2]string)
- func (c *Rzset) ScanDel(key string, pattern string, count int) (nums int)
- func (c *Rzset) ScanOnce(key string, cursor int, pattern string, count int) (int, [][2]string, error)
- func (c *Rzset) Zadd(key string, scoreElements [][2]string, elementCondition, scoreCondition string, ...) (int, error)
- func (c *Rzset) ZaddIncr(key, score, element string, elementCondition, scoreCondition string, isCh bool) (string, error)
- func (c *Rzset) Zcard(key string) (int, error)
- func (c *Rzset) Zcount(key, min, max string) (int, error)
- func (c *Rzset) Zdiff(key string, diffKeys []string) ([]string, error)
- func (c *Rzset) ZdiffStore(key string, diffKeys []string, destination string) (int, error)
- func (c *Rzset) ZdiffWithScore(key string, diffKeys []string) (arr [][2]string, err error)
- func (c *Rzset) Zincrby(key, increment, member string) (string, error)
- func (c *Rzset) Zinter(keys, weights []string, aggregate string) ([]string, error)
- func (c *Rzset) ZinterCard(keys []string, limit int) (int, error)
- func (c *Rzset) ZinterStore(destination string, keys, weights []string, aggregate string) (int, error)
- func (c *Rzset) ZinterWithScore(keys, weights []string, aggregate string) (arr [][2]string, err error)
- func (c *Rzset) Zlexcount(key, min, max string) (string, error)
- func (c *Rzset) Zmpop(keys []string, condition string, count int) (keyName string, arr [][2]string, err error)
- func (c *Rzset) Zmscore(key string, members []string) (map[string]string, error)
- func (c *Rzset) ZpopMax(key string, count int) (arr [][2]string, err error)
- func (c *Rzset) ZpopMin(key string, count int) (arr [][2]string, err error)
- func (c *Rzset) ZrandMember(key string, count int) ([]string, error)
- func (c *Rzset) ZrandMemberWithScore(key string, count int) (arr [][2]string, err error)
- func (c *Rzset) Zrange(key, start, stop, byType string, isRev bool, limit []int) ([]string, error)
- func (c *Rzset) ZrangeStore(dst, src, min, max, byType string, isRev bool, limit []int) (int, error)
- func (c *Rzset) ZrangeWithScore(key, start, stop, byType string, isRev bool, limit []int) (arr [][2]string, err error)
- func (c *Rzset) Zrank(key, member string) (int, error)
- func (c *Rzset) ZrankWithScore(key, member string) ([]string, error)
- func (c *Rzset) Zrem(key string, members []string) (int, error)
- func (c *Rzset) ZremRangeByLex(key, min, max string) (int, error)
- func (c *Rzset) ZremRangeByRank(key string, min, max int) (int, error)
- func (c *Rzset) ZremRangeByScore(key, min, max string) (int, error)
- func (c *Rzset) Zrevrank(key, member string) (int, error)
- func (c *Rzset) ZrevrankWithScore(key, member string) ([]string, error)
- func (c *Rzset) Zscore(key, member string) (string, error)
- func (c *Rzset) Zunion(keys, weights []string, aggregate string) ([]string, error)
- func (c *Rzset) ZunionStore(destination string, keys, weights []string, aggregate string) (int, error)
- func (c *Rzset) ZunionWithScore(keys, weights []string, aggregate string) (arr [][2]string, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Config ¶
type Rbit ¶
type Rbit struct {
// contains filtered or unexported fields
}
func (*Rbit) Bitcount ¶
BITCOUNT 计算给定key存储字符串中,被设置为 1 的比特位的数量,不存在的key会被当做空字符串处理,返回0 key: string start: int 起始位置,可以为负数 end: int 结束位置,可以为负数 return: int link: https://redis.io/commands/bitcount/
func (*Rbit) BitcountIndex ¶
BITCOUNT 计算给定key存储字符串中,被设置为 1 的比特位的数量,不存在的key会被当做空字符串处理,返回0 since: 7.0.0 key: string start: int 起始位置,可以为负数 end: int 结束位置,可以为负数 indexType: string 索引方式 取值:BYTE | BIT return: int link: https://redis.io/commands/bitcount/
func (*Rbit) Bitop ¶
BITOP 对一个或多个保存二进制位的字符串 key 进行位元操作,并将结果保存到 destkey 上。 operation: string 操作类型,取值: AND | OR | XOR | NOT destkey: string 结果保存目标键
AND: 对一个或多个 key 求逻辑并,并将结果保存到 destkey OR: 对一个或多个 key 求逻辑或,并将结果保存到 destkey XOR: 对一个或多个 key 求逻辑异或,并将结果保存到 destkey NOT: 对给定 key 求逻辑非,并将结果保存到 destkey
keys: []string 指定键集 return: int 保存到 destkey 的字符串的长度,和输入 key 中最长的字符串长度相等。 link: https://redis.io/commands/bitop/
func (*Rbit) Bitpos ¶
BITPOS 返回位图中第一个值为 指定bit 的二进制位的位置。 key: string bit: int 指定bit位 (0 | 1) start: int 起始位置 可以为负数 end: int 结束位置 可以为负数 return: int link: https://redis.io/commands/bitpos/
func (*Rbit) BitposIndex ¶
BITPOS 返回位图中第一个值为 指定bit 的二进制位的位置。 key: string bit: int 指定bit位 (0 | 1) start: int 起始位置 可以为负数 end: int 结束位置 可以为负数 indexType: string 索引方式 取值:BYTE | BIT return: int link: https://redis.io/commands/bitpos/
func (*Rbit) Getbit ¶
GETBIT 对 key 所储存的字符串值,获取指定偏移量上的位(bit)。当 offset 比字符串值的长度大,或者 key 不存在时,返回 0 key: string 指定键名 offset: int 偏移量 return: int link: https://redis.io/commands/getbit/
func (*Rbit) Setbit ¶
SETBIT 对 key 所储存的字符串值,设置或清除指定偏移量上的位(bit), 位的设置或清除取决于 value 参数, 可以是 0 也可以是 1, 当 key 不存在时,自动生成一个新的字符串值。 key: string 指定键名 offset: int 偏移量 value: int (0 | 1) return: int 返回指定偏移量原来储存的位 link: https://redis.io/commands/setbit/
type Rdb ¶
type Rdb struct {
// contains filtered or unexported fields
}
func (*Rdb) Copy ¶
将存储在源键中的值复制到目标键, redis版本不低于6.2.0可用 source: string 源键 destination: string 目标键 return:
reply: int 0: 拷贝失败 1: 拷贝成功
func (*Rdb) Del ¶
移除指定的key,同步删除,阻塞式,删除小体量简单数据时推荐优先使用该方式 keys: []string 键名数组 return: reply int 成功移除的键的数量
func (*Rdb) Move ¶
将指定key从当前数据库中移动到目标数据库中 key: string 键名 destinationDb: int 目标数据库 return:
reply: int 0: 移动失败 1: 移动成功
func (*Rdb) Rename ¶
将指定key重命名,如果newKey是已经存在的key,则实际上会先执行隐式Del操作, 所以如果这个newKey包含比较大的值,则可能引起高延迟。 key: string 指定键名 newKey: string 新的键名 return:
reply: string
func (*Rdb) RenameNx ¶
将指定key重命名,仅当newKey不存在时才执行,如果指定key不存在,则会返回错误 所以如果这个newKey包含比较大的值,则可能引起高延迟。 key: string 指定键名 newKey: string 新的键名 return:
reply: int 0: newKey当前已经存在 1: 重命名成功
type Rexpire ¶
type Rexpire struct {
// contains filtered or unexported fields
}
func (*Rexpire) Expire ¶
设置指定key的生命周期 key: string 键名 seconds: int 生存时间 单位s options: string NX|XX|GT|LT, 对应值的含义查阅https://redis.io/commands/expire/ return:
reply: int 0: 设置失败 1: 设置成功
func (*Rexpire) ExpireAt ¶
设置指定key的过期时间点 key: string 键名 timestamp: int 秒级时间戳 options: string NX|XX|GT|LT, 对应值的含义查阅https://redis.io/commands/expireat/ return:
reply: int 0: 设置失败 1: 设置成功
func (*Rexpire) ExpireTime ¶
返回指定key的失效时间秒级时间戳,7.0.0版本以上可用 key: string 键名 return:
reply: int Unix timestamp in seconds -1: key存在但未设置过过期时间 -2: key不存在
func (*Rexpire) Pexpire ¶
设置指定key的生命周期 key: string 键名 milliseconds: int 生存时间 单位ms options: string NX|XX|GT|LT, 7.0.0版本以上支持, 对应值的含义查阅https://redis.io/commands/pexpire/ return:
reply: int 0: 设置失败 1: 设置成功
func (*Rexpire) PexpireAt ¶
设置指定key的过期时间点 key: string 键名 miltimestamp: int64 毫秒级时间戳 options: string NX|XX|GT|LT, 7.0.0版本以上支持,对应值的含义查阅https://redis.io/commands/pexpireat/ return:
reply: int 0: 设置失败 1: 设置成功
func (*Rexpire) PexpireTime ¶
返回指定key的失效时间秒级时间戳,7.0.0版本以上支持 key: string 键名 return:
reply: int64 Unix timestamp in seconds -1: key存在但未设置过过期时间 -2: key不存在
type Rgeo ¶
type Rgeo struct {
// contains filtered or unexported fields
}
func (*Rgeo) GeoAdd ¶
func (c *Rgeo) GeoAdd(key string, points [][3]string, elementCondition string, isCh bool) (int, error)
GEOADD, 将指定的地理空间项(经度、纬度、名称)添加到指定的键 since: 6.2.0 key: string 键名 elementCondition: string , 取值 XX | NX, 不指定传空
XX:只更新已经存在的元素。 不要添加新元素。 NX:只添加新元素。 不要更新已经存在的元素。
isCh: bool, 指定该参数时,会将返回值修改,由原先的返回新添加的元素个数,变为返回变更的元素+新添加的元素总数 points: [][3]string{longitude, latitude, name}数组 return: reply int link: https://redis.io/commands/geoadd/
func (*Rgeo) GeoDist ¶
GEODIST, 返回的地理空间索引中两个成员之间的距离。 key: string 键名 members: [2]string{member1,member2} unit: string 单位,默认为M
M for 米. KM for 公里. MI for 英里. FT for 英尺.
return:
reply: string
func (*Rgeo) GeoHash ¶
GEOHASH, 返回给定的N个元素在集合中的有效的 Geohash 字符串 key: string 键名 members: []string 指定元素数组 return:
reply: map[string]string, 格式 map[member]hash
func (*Rgeo) GeoPos ¶
GEOPOS, 返回给定的N个成员的经纬度位置信息 key: string 键名 members: []string 指定成员数组 return:
reply: []map[string]string, 格式 []map[string]string{"member":"", "longitude":"","latitude"}, ...}
func (*Rgeo) GeoSearchFromLonlatHasWith ¶
func (c *Rgeo) GeoSearchFromLonlatHasWith(key string, poi [2]string, byType []string, sort string, count [2]int) ([]map[string]string, error)
GEOSEARCH, 此方法通过FROMLONLAT方式搜索,同时指定所有WITH选项,即使用给定的经纬度 since: 7.0.0 key: string 键名 poi: [2]string{longitude, latitude} 指定经纬度作为中心点 byType: []string 指定搜索范围,两种方式取其一
BYRADIUS: []string, 根据给定的<radius>在圆形区域内搜索, 传值格式:[]string{"BYRADIUS", radius, unit} BYBOX: []string, 在轴对齐的矩形内搜索, 传值格式:[]string{"BYBOX", width, height, unit}
sort: string, 排序方式,取值:ASC | DESC
ASC:相对于中心点,从最近到最远进行排序。 DESC:相对于中心点,从最远到最近进行排序。
count: [2]int, 默认返回所有匹配项。 使用COUNT参数将结果限制为前 N 个匹配项
不使用ANY选项时:传值格式[2]int{count,0} 使用ANY选项时:传值格式[2]int{count,1}
特别说明:使用 ANY 选项时,一旦找到足够的匹配项,命令就会返回。 这意味着返回的结果可能不是最接近指定点的结果,但服务器为生成它们所投入的努力要少得多。 WITH选项说明: WITHCOORD: 同时返回匹配项的经度和纬度。 WITHDIST: 同样返回成员距指定中心点的距离。 返回的距离与为半径或高度和宽度参数指定的单位相同 WITHHASH: 以 52 位无符号整数的形式返回成员的原始 geohash 编码排序集score return:
reply: []map[string]string, map格式{"member":"", "dist":"","hash":"","longitude":"","latitude":""}
func (*Rgeo) GeoSearchFromLonlatNoWith ¶
func (c *Rgeo) GeoSearchFromLonlatNoWith(key string, poi [2]string, byType []string, sort string, count [2]int) ([]string, error)
GEOSEARCH, 此方法通过FROMLONLAT方式搜索,同时不指定任何WITH选项,即使用给定的经纬度 since: 7.0.0 key: string 键名 poi: [2]string{longitude, latitude} 指定经纬度作为中心点 byType: []string 指定搜索范围,两种方式取其一
BYRADIUS: []string, 根据给定的<radius>在圆形区域内搜索, 传值格式:[]string{"BYRADIUS", radius, unit} BYBOX: []string, 在轴对齐的矩形内搜索, 传值格式:[]string{"BYBOX", width, height, unit}
sort: string, 排序方式,取值:ASC | DESC
ASC:相对于中心点,从最近到最远进行排序。 DESC:相对于中心点,从最远到最近进行排序。
count: [2]int, 默认返回所有匹配项。 使用COUNT参数将结果限制为前 N 个匹配项
不使用ANY选项时:传值格式[2]int{count,0} 使用ANY选项时:传值格式[2]int{count,1}
特别说明:使用 ANY 选项时,一旦找到足够的匹配项,命令就会返回。 这意味着返回的结果可能不是最接近指定点的结果,但服务器为生成它们所投入的努力要少得多。 return:
reply: []string
func (*Rgeo) GeoSearchFromLonlatStore ¶
func (c *Rgeo) GeoSearchFromLonlatStore(destination, source string, poi [2]string, byType []string, sort string, count [2]int, storeDist bool) (int, error)
GEOSEARCHSTORE, 此方法通过FROMLONLAT方式搜索,即使用给定的经纬度, 将结果存储到指定key中 since: 7.0.0 destination: string 目标键名 source: string 源键名 poi: [2]string{longitude, latitude} 指定经纬度作为中心点 byType: []string 指定搜索范围,两种方式取其一
BYRADIUS: []string, 根据给定的<radius>在圆形区域内搜索, 传值格式:[]string{"BYRADIUS", radius, unit} BYBOX: []string, 在轴对齐的矩形内搜索, 传值格式:[]string{"BYBOX", width, height, unit}
sort: string, 排序方式,取值:ASC | DESC
ASC:相对于中心点,从最近到最远进行排序。 DESC:相对于中心点,从最远到最近进行排序。
count: [2]int, 默认返回所有匹配项。 使用COUNT参数将结果限制为前 N 个匹配项
不使用ANY选项时:传值格式[2]int{count,0} 使用ANY选项时:传值格式[2]int{count,1}
特别说明:使用 ANY 选项时,一旦找到足够的匹配项,命令就会返回。 这意味着返回的结果可能不是最接近指定点的结果,但服务器为生成它们所投入的努力要少得多。 storeDist: bool 是否同时存储与指定中心点的距离,默认false不存储 return:
reply: int 存储到结果集中的成员数量
func (*Rgeo) GeoSearchFromMemberHasWith ¶
func (c *Rgeo) GeoSearchFromMemberHasWith(key, member string, byType []string, sort string, count [2]int) ([]map[string]string, error)
GEOSEARCH, 此方法通过FROMMEMBER方式搜索,同时指定所有WITH选项,即使用给定的集合内的某个成员 since: 7.0.0 key: string 键名 member: string 指定集合内的成员作为中心点 byType: []string 指定搜索范围,两种方式取其一
BYRADIUS: []string, 根据给定的<radius>在圆形区域内搜索, 传值格式:[]string{"BYRADIUS", radius, unit} BYBOX: []string, 在轴对齐的矩形内搜索, 传值格式:[]string{"BYBOX", width, height, unit}
sort: string, 排序方式,取值:ASC | DESC
ASC:相对于中心点,从最近到最远进行排序。 DESC:相对于中心点,从最远到最近进行排序。
count: [2]int, 默认返回所有匹配项。 使用COUNT参数将结果限制为前 N 个匹配项
不使用ANY选项时:传值格式[2]int{count,0} 使用ANY选项时:传值格式[2]int{count,1}
特别说明:使用 ANY 选项时,一旦找到足够的匹配项,命令就会返回。 这意味着返回的结果可能不是最接近指定点的结果,但服务器为生成它们所投入的努力要少得多。 WITH选项说明: WITHCOORD: 同时返回匹配项的经度和纬度。 WITHDIST: 同样返回成员距指定中心点的距离。 返回的距离与为半径或高度和宽度参数指定的单位相同 WITHHASH: 以 52 位无符号整数的形式返回成员的原始 geohash 编码排序集score return:
reply: []map[string]string, map格式{"member":"", "dist":"","hash":"","longitude":"","latitude":""}
func (*Rgeo) GeoSearchFromMemberNoWith ¶
func (c *Rgeo) GeoSearchFromMemberNoWith(key, member string, byType []string, sort string, count [2]int) ([]string, error)
GEOSEARCH, 此方法通过FROMMEMBER方式搜索,同时不指定任何WITH选项,即使用给定的集合内的某个成员 since: 7.0.0 key: string 键名 member: string 指定集合内的成员作为中心点 byType: []string 指定搜索范围,两种方式取其一
BYRADIUS: []string, 根据给定的<radius>在圆形区域内搜索, 传值格式:[]string{"BYRADIUS", radius, unit} BYBOX: []string, 在轴对齐的矩形内搜索, 传值格式:[]string{"BYBOX", width, height, unit}
sort: string, 排序方式,取值:ASC | DESC
ASC:相对于中心点,从最近到最远进行排序。 DESC:相对于中心点,从最远到最近进行排序。
count: [2]int, 默认返回所有匹配项。 使用COUNT参数将结果限制为前 N 个匹配项
不使用ANY选项时:传值格式[2]int{count,0} 使用ANY选项时:传值格式[2]int{count,1}
特别说明:使用 ANY 选项时,一旦找到足够的匹配项,命令就会返回。 这意味着返回的结果可能不是最接近指定点的结果,但服务器为生成它们所投入的努力要少得多。 return:
reply: []string
func (*Rgeo) GeoSearchFromMemberStore ¶
func (c *Rgeo) GeoSearchFromMemberStore(destination, source, member string, byType []string, sort string, count [2]int, storeDist bool) (int, error)
GEOSEARCHSTORE, 此方法通过FROMMEMBER方式搜索,即使用给定的集合内的某个成员, 将结果存储到指定key中 since: 7.0.0 destination: string 目标键名 source: string 源键名 member: string 指定集合内的成员作为中心点 byType: []string 指定搜索范围,两种方式取其一
BYRADIUS: []string, 根据给定的<radius>在圆形区域内搜索, 传值格式:[]string{"BYRADIUS", radius, unit} BYBOX: []string, 在轴对齐的矩形内搜索, 传值格式:[]string{"BYBOX", width, height, unit}
sort: string, 排序方式,取值:ASC | DESC
ASC:相对于中心点,从最近到最远进行排序。 DESC:相对于中心点,从最远到最近进行排序。
count: [2]int, 默认返回所有匹配项。 使用COUNT参数将结果限制为前 N 个匹配项
不使用ANY选项时:传值格式[2]int{count,0} 使用ANY选项时:传值格式[2]int{count,1}
特别说明:使用 ANY 选项时,一旦找到足够的匹配项,命令就会返回。 这意味着返回的结果可能不是最接近指定点的结果,但服务器为生成它们所投入的努力要少得多。 storeDist: bool 是否同时存储与指定中心点的距离,默认false不存储 return:
reply: int 存储到结果集中的成员数量
type Rhash ¶
type Rhash struct {
// contains filtered or unexported fields
}
func (*Rhash) Hdel ¶
HDEL, 从key中移除指定fields key: string 键名 fields: []string 字段集 return: reply int 返回成功移除的field数量 link: https://redis.io/commands/hdel/
func (*Rhash) Hexists ¶
HEXISTS, 判断key中是否包含指定fields key: string 键名 field: string 字段名 return:
reply: int 0: 不包含,或key不存在 1: 包含
func (*Rhash) Hget ¶
HGET, 获取key中指定field的值 key: string 键名 field: string 字段名 return: reply string link: https://redis.io/commands/hget/
func (*Rhash) HgetAll ¶
HGETALL, 返回存储在key中的所有字段和值 key: string 键名 return: reply map[string]string link: https://redis.io/commands/hgetall/
func (*Rhash) HincrBy ¶
HINCRBY , 将存储在 key 中的指定field值递增指定增量, 如果key不存在,则创建,若field不存在,则先创建并将值设为初始0 key: string 键名 field: string 字段名 increment: int 增量值,可以为负值 return: reply int 返回操作之后的新值 link:https://redis.io/commands/incrby/
func (*Rhash) HincrByFloat ¶
HINCRBYFLOAT , 将存储在 key 中的数字递增指定增量, 如果key不存在,则在执行操作之前将其设置为 0 key: string 键名 field: string 字段名 increment: float64 增量值,可以设置负数 return: reply float64 返回操作之后的新值 link:https://redis.io/commands/hincrbyfloat/
func (*Rhash) Hkeys ¶
HKEYS, 返回指定key中存储的所有field, key若不存在返回空数组 key: string 键名 return: reply []string link: https://redis.io/commands/hkeys/
func (*Rhash) Hlen ¶
HLEN, 返回指定key中存储的所有field的数量 key: string 键名 return: reply int link: https://redis.io/commands/hlen/
func (*Rhash) Hmget ¶
HMGET, 返回key中指定field的值 key: string 键名 fields: []string 字段集 return: reply []string link: https://redis.io/commands/hmget/
func (*Rhash) Hset ¶
HSET,可同时设置多个field=>value key: string 键名 fieldValues: [][2]string{{field, value}, ...} return: reply int 成功添加的字段数 link: https://redis.io/commands/hset/
func (*Rhash) HsetNx ¶
HSETNX, 一次只能设置一个field key: string 键名 field: string 字段名 value: string 字段值 return:
reply: int 0: 设置失败 1: 设置成功,当且仅当field不存在时
func (*Rhash) HstrLen ¶
HSTRLEN,返回指定field存储的value值字符串长度 key: string 键名 field: string 字段名 return: reply: int 若field不存在返回0 link: https://redis.io/commands/hstrlen/
func (*Rhash) Hvals ¶
HVALS, 返回指定key中存储的所有字段的value, key若不存在返回空数组 key: string 键名 return: reply []string link: https://redis.io/commands/hvals/
func (*Rhash) ScanAll ¶
根据条件迭代指定key中所有满足条件的键值对 key: string 键名 pattern: string 正则表达式 count: int 单次迭代键值对的数量 return: arr [][2]string link:https://redis.io/commands/hscan/
func (*Rhash) ScanDel ¶
根据条件迭代指定key中所有满足条件的键值对并删除 key: string 键名 pattern: string 正则表达式 count: int 单次迭代键值对的数量 return: nums int 本次迭代删除的键值对数量 link:https://redis.io/commands/hscan/
func (*Rhash) ScanOnce ¶
func (c *Rhash) ScanOnce(key string, cursor int, pattern string, count int) (int, [][2]string, error)
根据条件迭代一次指定key中满足条件的键值对 key: string 键名 cursor: string 游标 pattern: string 正则表达式 count: int 单次迭代键值对的数量, 存储的数据体量小时,一般返回都是全部结果,该选项并不起作用,这是正常的 link:https://redis.io/commands/hscan/
type Rhyper ¶
type Rhyper struct {
// contains filtered or unexported fields
}
func (*Rhyper) Pfadd ¶
PFADD 将任意数量的元素添加到指定的 HyperLogLog 里面 如果命令执行时给定的键不存在, 那么程序将先创建一个空的 HyperLogLog 结构, 然后再执行命令。 key: string 给定的key elements: []string 元素集 return:
reply: int 0: 未发生任何修改 1: 如果 HyperLogLog 的内部储存被修改了
func (*Rhyper) Pfcount ¶
PFCOUNT 返回给定key的基数,注意: 基数并不是精确值, 而是一个带有 0.81% 标准错误(standard error)的近似值 1. 命令作用于单个键时, 返回储存在给定键的 HyperLogLog 的近似基数, 如果键不存在, 那么返回 0 2. 命令作用于多个键时, 返回所有给定 HyperLogLog 的并集的近似基数, 这个近似基数是通过将所有给定 HyperLogLog 合并至一个临时 HyperLogLog 来计算得出的。 keys: []string return: int link: https://redis.io/commands/pfcount/
func (*Rhyper) Pfmerge ¶
PFMERGE 将多个 HyperLogLog 合并为一个 HyperLogLog , 合并后的 HyperLogLog 的基数接近于所有输入 HyperLogLog 的可见集合的并集。 如果destkey不存在,则会先创建一个空的 HyperLogLog destkey: string 目标键名 sourcekeys: []string 源键 return: string 此命令只返回“OK” link: https://redis.io/commands/pfmerge/
type Rlist ¶
type Rlist struct {
// contains filtered or unexported fields
}
func (*Rlist) Lindex ¶
LINDEX, 返回指定索引位的元素 key: string 键名 index: int 索引,可以负数,当为负数时表示从列表尾部开始 return: reply string link: https://redis.io/commands/lindex/
func (*Rlist) Linsert ¶
LINSERT, 在列表指定位置插入元素 key: string 键名 condition: string 指定插入的方式 BEFORE | AFTER pivot: string 参考值 element: string 待插入的元素 return:
reply: int 成功插入元素之后列表的长度 0: key不存在 -1: 参考值pivot未找到
func (*Rlist) Llen ¶
LLEN, 返回指定列表的长度 key: string 键名 return: reply int link: https://redis.io/commands/llen/
func (*Rlist) Lmove ¶
LMOVE, 以原子方式返回并删除存储在源中的列表的第一个/最后一个元素(头/尾取决于 wherefrom 参数), 并将元素存入目标列表的第一个/最后一个元素(头/尾取决于 whereto 参数) 如果源不存在,则返回值nil,不执行任何操作。 如果 source 和 destination 相同, 则该操作相当于从列表中删除第一个/最后一个元素并将其作为列表的第一个/最后一个元素推送, 因此可以将其视为列表轮换命令(或空操作 如果wherefrom与whereto相同)。 since: 6.2.0 source: string 源列表 destination: string 目标列表 wherefrom: string 源列表取出元素的位置 取值:LEFT | RIGHT whereto: string 目标列表存入元素的位置 取值:LEFT | RIGHT return: reply string 返回本次操作的元素 link: https://redis.io/commands/lmove/
func (*Rlist) Lmpop ¶
func (c *Rlist) Lmpop(keys []string, condition string, count int) (keyName string, arr []string, err error)
LMPOP, 从提供的键名列表中的第一个非空列表键中移出一个或多个元素。 since: 7.0.0 keys: []string 键名数组 condition: string 取值:LEFT | RIGHT count: int 返回元素的数量,取非空列表的长度和count两者的较小者 return: link: https://redis.io/commands/lmpop/
func (*Rlist) Lpop ¶
LPOP, 从列表的开头开始删除并返回一个或多个元素 key: string 键名 count: int 需移出的数量 return: reply []string link: https://redis.io/commands/lpop/
func (*Rlist) Lpos ¶
LPOS,根据条件返回元素的在列表中的索引位置 since: 6.0.6 key: string 键名 element: string 待匹配的元素 rank: int 正数代表从头开始搜索,选项指定要返回的第一个元素的“等级”,以防存在多个匹配项。 等级 1 表示返回第一个匹配项,等级 2 表示返回第二个匹配项,依此类推。 若值为负数,代表从尾部开始搜索,但是索引值不会受搜索方向影响。 count: int 指定返回前N个匹配的元素位置,0代表所有匹配的 maxlen: int MAXLEN 选项告诉命令只将提供的元素与给定的maxlen次数进行比较 当使用 MAXLEN 时,可以将 0 指定为最大比较次数,以此告诉命令我们需要无限次比较。 这比给出一个非常大的 MAXLEN 选项要好,因为它更通用。 return: reply []int link: https://redis.io/commands/lpos/
func (*Rlist) Lpush ¶
LPUSH, 往列表头部插入多个元素, 若列表key不存在,则先创建 key: string 键名 elements: []string 待插入的元素数组 return: reply int 返回操作执行之后列表的长度 link: https://redis.io/commands/lpush/
func (*Rlist) Lpushx ¶
LPUSHX, 往列表头部插入多个元素, 若列表key不存在,则不执行任何操作 key: string 键名 elements: []string 待插入的元素数组 return: reply int 返回操作执行之后列表的长度 link: https://redis.io/commands/lpushx/
func (*Rlist) Lrange ¶
LRANGE, 返回列表指定偏移量区间的所有元素 超出范围的索引不会产生错误。如果开始大于列表的末尾,则返回一个空列表。 如果 stop 大于列表的实际末尾,Redis 会将其视为列表的最后一个元素。 key: string 键名 start: int 起始偏移量,可以为负数 stop: int 截止偏移量,可以为负数 return: reply []string link: https://redis.io/commands/lrange/
func (*Rlist) Lrem ¶
LREM, 从列表中删除指定次数的元素 key: string 键名 count: int 指定删除的元素次数 count > 0:删除等于从头到尾移动的元素的元素。 count < 0:删除等于从尾部移动到头部的元素的元素。 count = 0:移除所有等于element的元素。 element: string 元素 return: reply int 返回被删除元素的数量,若key不存在,始终返回0 link: https://redis.io/commands/lrange/
func (*Rlist) Lset ¶
LSET, 将列表中索引位的元素设置为指定元素 key: string 键名 index: int 索引值 可为负数 element: string 元素值 return: reply string 成功返回"OK" link: https://redis.io/commands/lset/
func (*Rlist) Ltrim ¶
LTRIM, 修剪现有列表,使其仅包含指定索引范围的元素。 超出范围的索引不会产生错误:如果 start 大于列表的末尾,或者 start > end,结果将是一个空列表(这会导致 key 被删除)。 如果 end 大于列表的末尾,Redis 会将其视为列表的最后一个元素。 key: string 键名 start: int 起始索引,可以为负数 stop: int 截止索引,可以为负数 return: reply string 成功返回"OK" link: https://redis.io/commands/ltrim/
func (*Rlist) Rpop ¶
RPOP, 从列表的尾部开始删除并返回一个或多个元素 key: string 键名 count: int 需移出的数量 return: reply []string link: https://redis.io/commands/rpop/
func (*Rlist) Rpush ¶
RPUSH, 往列表尾部插入多个元素, 若列表key不存在,则先创建 key: string 键名 elements: []string 待插入的元素数组 return: reply int 返回操作执行之后列表的长度 link: https://redis.io/commands/rpush/
type Rscan ¶
type Rscan struct {
// contains filtered or unexported fields
}
func (*Rscan) ScanAll ¶
根据条件迭代当前数据库中所有满足条件的键集 pattern: string 正则表达式 count: int 单次迭代键的数量 typ: string 类型 6.0.0版本以后支持该参数 return: arr []string link:https://redis.io/commands/scan/
func (*Rscan) ScanDel ¶
根据条件迭代当前数据库中所有满足条件的键集并删除 pattern: string 正则表达式 count: int 单次迭代键的数量 typ: string 类型 6.0.0版本以后支持该参数 return: nums int 本次迭代删除的键数量 link:https://redis.io/commands/scan/
type Rset ¶
type Rset struct {
// contains filtered or unexported fields
}
func (*Rset) Sadd ¶
SADD, 往指定集合添加成员,已经存在的跳过, key存在将创建 key: string 键名 members: []string 成员 return: reply int 成功添加的成员数 link: https://redis.io/commands/sadd/
func (*Rset) ScanAll ¶
根据条件迭代指定key中所有满足条件的成员 key: string 键名 pattern: string 正则表达式 count: int 单次迭代成员的数量 return: arr []string link:https://redis.io/commands/sscan/
func (*Rset) ScanDel ¶
根据条件迭代指定key中所有满足条件的成员并删除 key: string 键名 pattern: string 正则表达式 count: int 单次迭代成员的数量 return: nums int 本次迭代删除的成员数量 link:https://redis.io/commands/sscan/
func (*Rset) ScanOnce ¶
根据条件迭代一次指定key中满足条件的成员 key: string 键名 cursor: string 游标 pattern: string 正则表达式 count: int 单次迭代成员的数量, 存储的数据体量小时,一般返回都是全部结果,该选项并不起作用,这是正常的 link:https://redis.io/commands/sscan/
func (*Rset) Scard ¶
SCARD, 返回指定key中存储的成员数 key: string 键名 return: reply int link: https://redis.io/commands/scard/
func (*Rset) Sdiff ¶
SDIFF, 返回由第一个集合和所有后续集合之间的差异产生的集合成员 key: string 第一个集合键名 diffKeys: []string 其他对比的键名数组 return: reply int link: https://redis.io/commands/sdiff/
func (*Rset) SdiffStore ¶
SDIFF, 比对第一个集合和所有后续集合之间的差异产生的集合成员, 并将结果存储到目标destination中,如果destination存在则值会被完全覆盖。 key: string 第一个集合键名 diffKeys: []string 其他对比的键名数组 destination: string 目标键名 return: reply int destination的成员数量 link: https://redis.io/commands/sdiffstore/
func (*Rset) Sinter ¶
SINTER, 返回所有给定集合的交集成员,其中只要有一个空集合,结果必然为空,不存在的key也视为空集合 key: []string 键名数组 return: reply []string link: https://redis.io/commands/sinter/
func (*Rset) SinterCard ¶
SINTERCARD, 返回所有给定集合的交集成员数,其中只要有一个空集合, 结果必然为0,不存在的key也视为空集合 since: 7.0.0 keys: []string 键名数组 limit: int 限制返回的数量 return: reply int link: https://redis.io/commands/sintercard/
func (*Rset) SinterStore ¶
SINTERSTORE, 比对所有给定集合的交集成员数,并将结果存储到目标destination中,如果destination存在则值会被覆盖。 key: []string 其键名数组 destination: string 目标键名 return: reply int destination的成员数量 link: https://redis.io/commands/sinterstore/
func (*Rset) Sismember ¶
SISMEMBER, 判断指定member是否在集合中 key: string 键名 member: string 成员 return:
reply: int 0: 不包含,或key不存在 1: 包含
func (*Rset) Smembers ¶
SMEMBERS, 返回集合中所有成员,大数据量集合慎用,尤其是生产环境 key: string 键名 return: reply []string link: https://redis.io/commands/smembers/
func (*Rset) Smismember ¶
SMISMEMBER, 判断每个给定的member是否在集合中, since: 6.2.0 key: string 键名 members: []string 成员数组 return:
reply: []int 返回顺序与members顺序一致 0: 不包含,或key不存在 1: 包含
func (*Rset) Smove ¶
SMOVE, 判断每个给定的member是否在集合中,如果destination中当前已经存在该member 则会从source中移除该member,destination不做任何改变 source: string 源集合键名 destination: string 目标集合键名 members: 指定成员 return:
reply: int 0: 转移失败 1: 成功转移
func (*Rset) Spop ¶
SPOP,从集合中移除并返回一个或多个随机成员 key: string 键名 count: int 指定返回成员个数 return: reply []string link: https://redis.io/commands/spop/
func (*Rset) Srandmember ¶
SRANDMEMBER,从集合中返回一个或多个随机成员 key: string 键名 count: int 指定返回成员个数
正数:返回值不存在重复,若超过集合最大成员数,则取最小者 负数:返回值可能有重复值,返回值数量始终等于count
return: reply []string link: https://redis.io/commands/srandmember/
func (*Rset) Srem ¶
SREM, 移除指定成员,不存在的成员会被忽略,不存在的集合始终返回0 key: string 键名 members: []string 成员数组 return: reply int 返回成功移除的成员数 link: https://redis.io/commands/srem/
func (*Rset) Sunion ¶
SUNION,返回由所有给定集合的并集生成的集合的成员 keys: []string 键名数组 return: reply []string link: https://redis.io/commands/sunion/
func (*Rset) SunionStore ¶
SUNIONSTORE,返回由所有给定集合的并集生成的集合的成员, 并存储到目标键destination中,若destination存在,则值会被覆盖 keys: []string 键名数组 destination: string 目标键名 return: reply []string link: https://redis.io/commands/sunionstore/
type Rstring ¶
type Rstring struct {
// contains filtered or unexported fields
}
func (*Rstring) Append ¶
APPEND, 在指定key尾部追加字符串 key: string 键名 value: string 追加字符串 return: reply int 追加之后的字符串长度 link:https://redis.io/commands/append/
func (*Rstring) Decr ¶
DECR , 将存储在 key 中的数字递减 1, 如果key不存在,则在执行操作之前将其设置为 0 key: string 键名 return: reply int 返回操作之后的新值 link:https://redis.io/commands/decr/
func (*Rstring) DecrBy ¶
DECRBY , 将存储在 key 中的数字递减指定量, 如果key不存在,则在执行操作之前将其设置为 0 key: string 键名 decrement: int 递减值,可以为负值 return: reply int 返回操作之后的新值 link:https://redis.io/commands/decrby/
func (*Rstring) Get ¶
GET key: string 键名 return: reply string link: https://redis.io/commands/get/
func (*Rstring) GetDel ¶
GETDEL, 获取指定键值并在成功时删除该键 key: string 键名 return: reply string link: https://redis.io/commands/getdel/
func (*Rstring) GetEx ¶
GETDEL, 获取指定键值并设置它的生命周期 key: string 键名 return: reply string expireType: string 设置生命周期格式, 取值范围:EX | PX | EXAT | PXAT | PERSIST link:https://redis.io/commands/getex/
func (*Rstring) GetRange ¶
GETRANGE,截取指定偏移量区间的字符串并返回 key: string 键名 start: int 支持负数 end: int 支持负数 return: reply string link:https://redis.io/commands/getrange/
func (*Rstring) GetSet ¶
GETSET, 将键 key 的值设为 value , 并返回键 key 在被设置之前的旧值。6.2.0版本以后已弃用该方法 key: string 键名 value: string 值 return: reply string link:https://redis.io/commands/getset/
func (*Rstring) Incr ¶
INCR , 将存储在 key 中的数字递增 1, 如果key不存在,则在执行操作之前将其设置为 0 key: string 键名 return: reply int 返回操作之后的新值 link:https://redis.io/commands/incr/
func (*Rstring) IncrBy ¶
INCRBY , 将存储在 key 中的数字递增指定增量, 如果key不存在,则在执行操作之前将其设置为 0 key: string 键名 increment: int 增量值,可以为负值 return: reply int 返回操作之后的新值 link:https://redis.io/commands/incrby/
func (*Rstring) IncrByFloat ¶
INCRBYFLOAT , 将存储在 key 中的数字递增指定增量, 如果key不存在,则在执行操作之前将其设置为 0 key: string 键名 increment: float64 增量值,可以设置负数 return: reply float64 返回操作之后的新值 link:https://redis.io/commands/incrbyfloat/
func (*Rstring) Mget ¶
MGET,同时为多个键设置值,此操作从不失败,如果某个给定键不存在,那么对应的值返回"" keys: ...string 键名 link: https://redis.io/commands/mget/
func (*Rstring) Mset ¶
MSET,同时为多个键设置值,此操作从不失败,如果某个给定键已经存在,那么 MSET 将使用新值去覆盖旧值 keyValues: [][2]string link: https://redis.io/commands/mset/
func (*Rstring) MsetNx ¶
MSETNX,同时为多个键设置值,只要有一个key存在,此命令都不会进行任何操作 keyValues: [][2]string return:
reply: int 0: 设置失败 1: 设置成功
func (*Rstring) PsetEx ¶
PSETEX,设置key并同时设置毫秒级生命周期 key: string 键名 milliseconds: int 毫秒级时间 value: string 值 link: https://redis.io/commands/psetex/
func (*Rstring) Set ¶
func (c *Rstring) Set(key, value, condition, expireType string, timeout int64) (reply string, err error)
SET--全参数功能方法 key: string 键名 value: string 值 condition: string 指定条件,取值范围: NX | XX expireType: string 设置生命周期格式, 取值范围:EX | PX | EXAT | PXAT | KEEPTTL 参数对照说明可查阅:https://redis.io/commands/set/
func (*Rstring) SetEx ¶
SETEX,设置key并同时设置秒级生命周期 key: string 键名 seconds: int 秒级时间 value: string 值 link: https://redis.io/commands/setex/
func (*Rstring) SetGet ¶
func (c *Rstring) SetGet(key, value, condition, expireType string, timeout int64) (reply string, err error)
SET 同时返回旧的值--全参数功能方法 key: string 键名 value: string 值 condition: string 指定条件,取值范围: NX | XX expireType: string 设置生命周期格式, 取值范围:EX | PX | EXAT | PXAT | KEEPTTL 参数对照说明可查阅:https://redis.io/commands/set/
func (*Rstring) SetNx ¶
SETNX, 仅当key无值时执行操作 key: string 键名 seconds: int 秒级时间 value: string 值 return:
reply: int 0: 设置失败 1: 设置成功
func (*Rstring) SetRange ¶
SETRANGE,从指定偏移量位置开始,覆盖value的整个长度 key: string 键名 offset: int 偏移量 可以设置的最大偏移量为 2^29 -1 (536870911) value: string 值 return: reply int 修改之后的字符串长度 link: https://redis.io/commands/setrange/
type Rtransaction ¶
type Rtransaction struct {
// contains filtered or unexported fields
}
func (*Rtransaction) Discard ¶
func (t *Rtransaction) Discard() (string, error)
DISCARD 刷新事务中所有先前排队的命令并将连接状态恢复为正常。 return: 始终返回"OK" link: https://redis.io/commands/discard/
func (*Rtransaction) Exec ¶
func (t *Rtransaction) Exec() (interface{}, error)
EXEC 执行事务中所有先前排队的命令并将连接状态恢复为正常。 使用 WATCH 时,EXEC 将仅在监视的键未被修改时才执行命令,从而允许检查和设置机制。 return:
1.返回数组:事务块内所有命令的返回值,按命令执行的先后顺序排列。 2. 当操作被打断时,返回空值 nil
特别说明:因此命令返回值多种多样,故不在此做类型转换,根据业务场景自行转换处理 link: https://redis.io/commands/exec/
func (*Rtransaction) Multi ¶
func (t *Rtransaction) Multi() (string, error)
MULTI 标记事务块的开始。后续命令将使用 EXEC 排队等待原子执行 return: 始终返回"OK" link: https://redis.io/commands/multi/
func (*Rtransaction) Unwatch ¶
func (t *Rtransaction) Unwatch() (string, error)
UNWATCH 解除所有key的监视 return: 始终返回"OK" link: https://redis.io/commands/unwatch/
func (*Rtransaction) Watch ¶
func (t *Rtransaction) Watch(keys []string) (string, error)
WATCH 监视所有给定的key keys: []string 需要监视的key return: 始终返回"OK" link: https://redis.io/commands/watch/
type Rzset ¶
type Rzset struct {
// contains filtered or unexported fields
}
func (*Rzset) ScanAll ¶
根据条件迭代指定key中所有满足条件的成员 key: string 键名 pattern: string 正则表达式 count: int 单次迭代成员的数量 return: arr []string link:https://redis.io/commands/zscan/
func (*Rzset) ScanDel ¶
根据条件迭代指定key中所有满足条件的成员并删除 key: string 键名 pattern: string 正则表达式 count: int 单次迭代成员的数量 return: nums int 本次迭代删除的成员数量 link:https://redis.io/commands/zscan/
func (*Rzset) ScanOnce ¶
func (c *Rzset) ScanOnce(key string, cursor int, pattern string, count int) (int, [][2]string, error)
根据条件迭代一次指定key中满足条件的成员 key: string 键名 cursor: string 游标 pattern: string 正则表达式 count: int 单次迭代成员的数量, 存储的数据体量小时,一般返回都是全部结果,该选项并不起作用,这是正常的 link:https://redis.io/commands/zscan/
func (*Rzset) Zadd ¶
func (c *Rzset) Zadd(key string, scoreElements [][2]string, elementCondition, scoreCondition string, isCh bool) (int, error)
ZADD, 将具有指定score的所有指定成员添加到key中,如果key不存在,则创建。此方法不添加"INCR"参数 如果指定的成员已经是排序集的成员,则更新score并将元素重新插入正确的位置以确保正确的排序。 注意:GT、LT 和 NX 选项相互排斥。 since: 6.2.0 key: string 键名 elementCondition: string , 取值 XX | NX, 不指定传空
XX:只更新已经存在的元素。 不要添加新元素。 NX:只添加新元素。 不要更新已经存在的元素。
scoreCondition: string, 取值 LT | GT, 不指定传空
LT:如果新分数小于当前分数,则只更新现有元素。 此标志不会阻止添加新元素。 GT:如果新分数大于当前分数,则仅更新现有元素。 此标志不会阻止添加新元素。
isCh: bool, 指定该参数时,会将返回值修改,由原先的返回新添加的元素个数,变为返回变更的元素+新添加的元素总数 isIncr: bool, 指定此选项时,ZADD 的行为类似于 ZINCRBY。 在此模式下只能指定一个score-element对。 scoreElements: [][2]string{score,element} score-element对数组 return:
reply: int 返回成功影响的成员总数
func (*Rzset) ZaddIncr ¶
func (c *Rzset) ZaddIncr(key, score, element string, elementCondition, scoreCondition string, isCh bool) (string, error)
ZADD, 将指定score-element对添加到key中,如果key不存在,则创建。 此方法默认添加 "INCR"参数 如果指定的成员已经是排序集的成员,则更新score并将元素重新插入正确的位置以确保正确的排序。 注意:GT、LT 和 NX 选项相互排斥。 since: 6.2.0 key: string 键名 score: string score下标值 element: string 成员值 elementCondition: string , 取值 XX | NX, 不指定传空
XX:只更新已经存在的元素。 不要添加新元素。 NX:只添加新元素。 不要更新已经存在的元素。
scoreCondition: string, 取值 LT | GT, 不指定传空
LT:如果新分数小于当前分数,则只更新现有元素。 此标志不会阻止添加新元素。 GT:如果新分数大于当前分数,则仅更新现有元素。 此标志不会阻止添加新元素。
isCh: bool, 指定该参数时,会将返回值修改,由原先的返回新添加的元素个数,变为返回变更的元素+新添加的元素总数 return:
reply: string 返回新的score值
func (*Rzset) Zcount ¶
ZCOUNT, 返回有序集合中指定score区间范围内的元素数量, 不存在的key返回0 key: string 键名 min: string score起始值,默认是包含边界值的,可指定为不包括,传值方法例如“(2”,即在score前面加一个“(”符号
也可以直接传值“-inf”,会自动取集合中最小的score
max: string score截止值,默认是包含边界值的,可指定为不包括,传值方法例如“(2”,即在score前面加一个“(”符号
也可以直接传值“+inf”,会自动取集合中最大的score
return: reply int link: https://redis.io/commands/zcount/
func (*Rzset) Zdiff ¶
ZDIFF, 返回给定的N个有序集合之间的差异,此方法不指定 WITHSCORES 参数 since: 6.2.0 key: string 第一个集合键名 diffKeys: []string 需要比对的键名数组 return:
reply []string
func (*Rzset) ZdiffStore ¶
ZDIFFSTORE, 比对给定的N个有序集合之间的差异,并将结果存储到指定destination中 若destination已经存在,则会完全覆盖 since: 6.2.0 key: string 第一个集合键名 diffKeys: []string 需要比对的键名数组 destination: string 比对结果目标存储键名 return:
reply int 返回存储到destination中的元素总数
func (*Rzset) ZdiffWithScore ¶
ZDIFF, 返回给定的N个有序集合之间的差异,此方法默认指定 WITHSCORES 参数 since: 6.2.0 key: string 第一个集合键名 diffKeys: []string 需要比对的键名数组 return:
reply [][2]string{{"score", "element"}, ...}
func (*Rzset) Zincrby ¶
ZINCRBY,按增量值递增指定成员的score值, 若成员不存在,则把增量值视为score值添加该成员, 若key不存在则创建 key: string 键名 increment: string 数值型增量字符串, 可以为负数值,代表递减 member: string 成员 return:
reply: string 返回设置之后该成员的新score值
func (*Rzset) Zinter ¶
ZINTER, 返回多个给定集合的交集,此方法不指定 WITHSCORES 参数 since: 6.2.0 keys: []string 集合键名数组 weights: []string 乘法因子,值必须为数值型字符串 使用 WEIGHTS 选项,可以为每个输入排序集指定一个乘法因子。 这意味着在传递给聚合函数之前, 每个输入排序集中每个元素的分数都乘以该因子。 当未给出 WEIGHTS 时,倍增因子默认为 1。 aggregate: string , 取值: SUM | MIN | MAX 使用 AGGREGATE 选项, 可以指定结果集元素的score的聚合方式,默认为SUM return:
reply []string
func (*Rzset) ZinterCard ¶
ZINTERCARD, 返回多个给定集合的交集成员数,若其中一个集合为空,则结果必然为0 since: 7.0.0 keys: []string 集合键名数组 limit: int 当提供可选的 LIMIT 参数(默认为 0,表示无限制)时,如果交集基数在计算中途达到极限, 算法将退出并产生极限作为基数。 这样的实现确保了limit低于实际交集基数的查询的显著加速。 return:
reply: int
func (*Rzset) ZinterStore ¶
func (c *Rzset) ZinterStore(destination string, keys, weights []string, aggregate string) (int, error)
ZINTERSTORE, 查询多个给定集合的交集,并将结果存储到指定集合中,若destination已经存在,则其值会被完全覆盖 destination: string 结果存储集合键名 keys: []string 集合键名数组 weights: []string 乘法因子,值必须为数值型字符串 使用 WEIGHTS 选项,可以为每个输入排序集指定一个乘法因子。 这意味着在传递给聚合函数之前, 每个输入排序集中每个元素的分数都乘以该因子。 当未给出 WEIGHTS 时,倍增因子默认为 1。 aggregate: string , 取值: SUM | MIN | MAX 使用 AGGREGATE 选项, 可以指定结果集元素的score的聚合方式,默认为SUM return:
reply int 返回结果集中的成员数
func (*Rzset) ZinterWithScore ¶
func (c *Rzset) ZinterWithScore(keys, weights []string, aggregate string) (arr [][2]string, err error)
ZINTER, 返回多个给定集合的交集,此方法指定 WITHSCORES 参数 since: 6.2.0 keys: []string 集合键名数组 weights: []string 乘法因子,值必须为数值型字符串 使用 WEIGHTS 选项,可以为每个输入排序集指定一个乘法因子。 这意味着在传递给聚合函数之前, 每个输入排序集中每个元素的分数都乘以该因子。 当未给出 WEIGHTS 时,倍增因子默认为 1。 aggregate: string , 取值: SUM | MIN | MAX 使用 AGGREGATE 选项, 可以指定结果集元素的score的聚合方式,默认为SUM return:
reply [][2]string{{"score", "element"}, ...}
func (*Rzset) Zlexcount ¶
ZLEXCOUNT, 当有序集合中的所有元素都以相同的分数插入时, 为了强制按字典顺序排序,返回min和max区间范围内的成员数量 key: string 键名 min: string 起始值 max: string 截止值 return:
reply: int
func (*Rzset) Zmpop ¶
func (c *Rzset) Zmpop(keys []string, condition string, count int) (keyName string, arr [][2]string, err error)
ZMPOP, 从提供的键名列表中的第一个非空集合键中移出一个或多个score-member对。 since: 7.0.0 keys: []string 键名数组 condition: string 取值:MIN | MAX count: int 返回元素的数量,取非空集合的长度和count两者的较小者 return:
keyName: string 移出成员的集合名 arr: [][2]string{{score,element}, ...}
func (*Rzset) Zmscore ¶
ZMSCORE, 返回集合中指定成员的score值,不存在的成员score返回空 since: 6.2.0 key: string 键名 members: []string 成员数组 return:
reply: map[string]string, 格式为map[element]score
func (*Rzset) ZpopMax ¶
ZPOPMAX, 移除并返回集合中指定count个数的score最大成员 key: string 键名 count: int 移除数量 return:
reply: [][2]string{{score,element}, ...}
func (*Rzset) ZpopMin ¶
ZPOPMIN, 移除并返回集合中指定count个数的score最小成员 key: string 键名 count: int 移除数量 return:
reply: [][2]string{{score,element}, ...}
func (*Rzset) ZrandMember ¶
ZRANDMEMBER, 从集合中随机返回N个成员,此方法默认不指定 WITHSCORES 参数 since: 6.2.0 key: string 键名 count: int 指定返回的成员数
正数:返回结果数量是count与集合成员总数两者的较小者 负数:返回的结果数量是count的绝对值,此时的结果可能会存在相同成员
return:
reply: []string
func (*Rzset) ZrandMemberWithScore ¶
ZRANDMEMBER, 从集合中随机返回N个成员,此方法默认指定 WITHSCORES 参数 since: 6.2.0 key: string 键名 count: int 指定返回的成员数
正数:返回结果数量是count与集合成员总数两者的较小者 负数:返回的结果数量是count的绝对值,此时的结果可能会存在相同成员
return:
reply: [][2]string{{score,element}, ...}
func (*Rzset) Zrange ¶
ZRANGE, 返回集合中指定范围区间的成员,此方法默认不指定 WITHSCORES参数 since: 6.2.0 key: string 键名 start: string 起始区间 stop: string 截止区间 byType: string 范围查询方式, 取值:BYSCORE | BYLEX isRev: bool, 成员的顺序默认score从低到高,若需要反向顺序,需指定此参数为true limit: []int{offset,count}, LIMIT 参数可用于从匹配元素中获取子范围, 类似 sql的 [offset,count] 负数 <count> 返回 <offset> 中的所有元素。 请记住,如果 <offset> 很大,则需要遍历排序集以获取 <offset> 元素,然后才能返回元素 return:
reply: []string
func (*Rzset) ZrangeStore ¶
func (c *Rzset) ZrangeStore(dst, src, min, max, byType string, isRev bool, limit []int) (int, error)
ZRANGESTORE, 返回集合中指定范围区间的成员,此方法默认不指定 WITHSCORES参数 since: 6.2.0 dst: string 目标键名 src: string 源键名 min: string 起始区间 max: string 截止区间 byType: string 范围查询方式, 取值:BYSCORE | BYLEX isRev: bool, 成员的顺序默认score从低到高,若需要反向顺序,需指定此参数为true limit: []int{offset,count}, LIMIT 参数可用于从匹配元素中获取子范围, 类似 sql的 [offset,count] 负数 <count> 返回 <offset> 中的所有元素。 请记住,如果 <offset> 很大,则需要遍历排序集以获取 <offset> 元素,然后才能返回元素 return:
reply: int 存储到目标集合的成员数
func (*Rzset) ZrangeWithScore ¶
func (c *Rzset) ZrangeWithScore(key, start, stop, byType string, isRev bool, limit []int) (arr [][2]string, err error)
ZRANGE, 返回集合中指定范围区间的成员,此方法默认指定 WITHSCORES参数 since: 6.2.0 key: string 键名 start: string 起始区间 stop: string 截止区间 byType: string 范围查询方式, 取值:BYSCORE | BYLEX isRev: bool, 成员的顺序默认score从低到高,若需要反向顺序,需指定此参数为true limit: []int{offset,count}, LIMIT 参数可用于从匹配元素中获取子范围, 类似 sql的 [offset,count] 负数 <count> 返回 <offset> 中的所有元素。 请记住,如果 <offset> 很大,则需要遍历排序集以获取 <offset> 元素,然后才能返回元素 return:
reply: [][2]string{{score,element}, ...}
func (*Rzset) Zrank ¶
ZRANK, 返回member在集合中的排名,score从低到高排列, 排名从0开始,意味着score最小的成员排名为0, 此方法不传递 WITHSCORE 参数 key: string 键名 member: string 指定成员 return:
reply: int ,特别说明:member不存在或者key不存在时,也会返回0 , 但是此时error信息不是nil,所以可以通过判断error值来区分是否返回的是正常排名值。
func (*Rzset) ZrankWithScore ¶
ZRANK, 返回member在集合中的排名,score从低到高排列, 排名从0开始,意味着score最小的成员排名为0, 此方法传递 WITHSCORE 参数 since: 7.2.0 key: string 键名 member: string 指定成员 return:
reply: []string
func (*Rzset) Zrem ¶
ZREM, 移除集合中指定的N个成员,不存在的成员忽略 key: string 键名 members: []string 成员数组 return:
reply: int 返回成功移除的成员数,不存在的member不计算在内
func (*Rzset) ZremRangeByLex ¶
ZREMRANGEBYLEX, 当有序集合中的所有元素都以相同的score插入时,为了强制按字典顺序排序, 此命令删除由 min 和 max 指定的字典序范围之间的所有元素。 key: string 键名 min: string 起始值 max: string 结束值 return:
reply: int 返回被删除的元素数量
func (*Rzset) ZremRangeByRank ¶
ZREMRANGEBYRANK, 删除存储在 key 处且排名在 start 和 stop 之间的排序集中的所有元素。 start 和 stop 都是基于 0 的索引,其中 0 是score最低的元素。 这些索引可以是负数, 表示从score最高的元素开始的偏移量。 例如:-1 是score最高的元素,-2 是score第二高的元素,依此类推。 key: string 键名 start: int 起始值 stop: int 结束值 return:
reply: int 返回被删除的元素数量
func (*Rzset) ZremRangeByScore ¶
ZREMRANGEBYSCORE, 删除由 min 和 max 指定的score范围之间的所有元素。 key: string 键名 min: string 起始值 max: string 结束值 return:
reply: int 返回被删除的元素数量
func (*Rzset) Zrevrank ¶
ZREVRANK, 返回member在集合中的排名,score从高到低排列, 排名从0开始,意味着score最小的成员排名为0, 此方法不传递 WITHSCORE 参数 key: string 键名 member: string 指定成员 return:
reply: int ,特别说明:member不存在或者key不存在时,也会返回0 , 但是此时error信息不是nil,所以可以通过判断error值来区分是否返回的是正常排名值。
func (*Rzset) ZrevrankWithScore ¶
ZREVRANK, 返回member在集合中的排名,score从高到低排列, 排名从0开始,意味着score最小的成员排名为0, 此方法传递 WITHSCORE 参数 since: 7.2.0 key: string 键名 member: string 指定成员 return:
reply: []string
func (*Rzset) Zscore ¶
ZSCORE, 返回集合中指定member的score值,member或key不存在,返回空 key: string 键名 member: string 指定成员 return:
reply: string
func (*Rzset) Zunion ¶
ZUNION, 返回多个给定集合的并集,此方法不指定 WITHSCORES 参数 since: 6.2.0 keys: []string 集合键名数组 weights: []string 乘法因子,值必须为数值型字符串 使用 WEIGHTS 选项,可以为每个输入排序集指定一个乘法因子。 这意味着在传递给聚合函数之前, 每个输入排序集中每个元素的分数都乘以该因子。 当未给出 WEIGHTS 时,倍增因子默认为 1。 aggregate: string , 取值: SUM | MIN | MAX 使用 AGGREGATE 选项, 可以指定结果集元素的score的聚合方式,默认为SUM return:
reply []string
func (*Rzset) ZunionStore ¶
func (c *Rzset) ZunionStore(destination string, keys, weights []string, aggregate string) (int, error)
ZUNIONSTORE, 查询多个给定集合的并集,并将结果存储到指定集合中,若destination已经存在,则其值会被完全覆盖 destination: string 结果存储集合键名 keys: []string 集合键名数组 weights: []string 乘法因子,值必须为数值型字符串 使用 WEIGHTS 选项,可以为每个输入排序集指定一个乘法因子。 这意味着在传递给聚合函数之前, 每个输入排序集中每个元素的分数都乘以该因子。 当未给出 WEIGHTS 时,倍增因子默认为 1。 aggregate: string , 取值: SUM | MIN | MAX 使用 AGGREGATE 选项, 可以指定结果集元素的score的聚合方式,默认为SUM return:
reply int 返回结果集中的成员数
func (*Rzset) ZunionWithScore ¶
func (c *Rzset) ZunionWithScore(keys, weights []string, aggregate string) (arr [][2]string, err error)
ZUNION, 返回多个给定集合的并集,此方法指定 WITHSCORES 参数 since: 6.2.0 keys: []string 集合键名数组 weights: []string 乘法因子,值必须为数值型字符串 使用 WEIGHTS 选项,可以为每个输入排序集指定一个乘法因子。 这意味着在传递给聚合函数之前, 每个输入排序集中每个元素的分数都乘以该因子。 当未给出 WEIGHTS 时,倍增因子默认为 1。 aggregate: string , 取值: SUM | MIN | MAX 使用 AGGREGATE 选项, 可以指定结果集元素的score的聚合方式,默认为SUM return:
reply [][2]string{{"score", "element"}, ...}