redis

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

redis组件 特别说明:该组件要求redis版本使用7.0.0以上,引入了redis7.0的一些新特性,否则有些方法会不支持

Redis 位图

Redis Database相关操作

生命周期相关

地理位置(本质是有序集合)

哈希表

Redis HyperLogLog

列表

scan迭代,针对全数据库的键,返回的每个元素都是一个数据库键

集合

字符串

Redis transaction 事务管理

有序集合

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Db          *Rdb
	Scan        *Rscan
	String      *Rstring
	Expire      *Rexpire
	Hash        *Rhash
	Set         *Rset
	Zset        *Rzset
	List        *Rlist
	Geo         *Rgeo
	Transaction *Rtransaction
	Hyper       *Rhyper
	Bit         *Rbit
	// contains filtered or unexported fields
}

func Instance

func Instance(config Config) *Client

返回指定name的客户端单例对象

func (*Client) Do

func (c *Client) Do(commandName string, args ...interface{}) (reply interface{}, err error)

通用Do方法保留

type Config

type Config struct {
	Address     string // 地址 ip:port
	Username    string // redis6.0版本以上开始提供Redis ACL,用户名+密码一起使用
	Password    string // 密码
	Database    int    // 数据库
	UseTLS      bool   // 是否启用tls
	MaxIdle     int    // 允许闲置的最大连接数(0表示不限制)
	MaxActive   int    // 最大连接数量限制(0表示不限制)
	IdleTimeout int    // 连接最大空闲时间
}

func SetConfig

func SetConfig(conf Config) Config

type Rbit

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

func (*Rbit) Bitcount

func (b *Rbit) Bitcount(key string, start, end int) (int, error)

BITCOUNT 计算给定key存储字符串中,被设置为 1 的比特位的数量,不存在的key会被当做空字符串处理,返回0 key: string start: int 起始位置,可以为负数 end: int 结束位置,可以为负数 return: int link: https://redis.io/commands/bitcount/

func (*Rbit) BitcountIndex

func (b *Rbit) BitcountIndex(key string, start, end int, indexType string) (int, error)

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

func (b *Rbit) Bitop(operation, destkey string, keys []string) (int, error)

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

func (b *Rbit) Bitpos(key string, bit, start, end int) (int, error)

BITPOS 返回位图中第一个值为 指定bit 的二进制位的位置。 key: string bit: int 指定bit位 (0 | 1) start: int 起始位置 可以为负数 end: int 结束位置 可以为负数 return: int link: https://redis.io/commands/bitpos/

func (*Rbit) BitposIndex

func (b *Rbit) BitposIndex(key string, bit, start, end int, indexType string) (int, error)

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

func (b *Rbit) Getbit(key string, offset int) (int, error)

GETBIT 对 key 所储存的字符串值,获取指定偏移量上的位(bit)。当 offset 比字符串值的长度大,或者 key 不存在时,返回 0 key: string 指定键名 offset: int 偏移量 return: int link: https://redis.io/commands/getbit/

func (*Rbit) Setbit

func (b *Rbit) Setbit(key string, offset, value int) (int, error)

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

func (c *Rdb) Copy(source, destination string) (reply int, err error)

将存储在源键中的值复制到目标键, redis版本不低于6.2.0可用 source: string 源键 destination: string 目标键 return:

  reply: int
			0: 拷贝失败
			1: 拷贝成功

func (*Rdb) Dbsize

func (c *Rdb) Dbsize() (int, error)

DBSIZE 获取当前选中数据库中的所有键的数量 return: reply int

func (*Rdb) Del

func (c *Rdb) Del(keys []string) (reply int, err error)

移除指定的key,同步删除,阻塞式,删除小体量简单数据时推荐优先使用该方式 keys: []string 键名数组 return: reply int 成功移除的键的数量

func (*Rdb) Exists

func (c *Rdb) Exists(keys []string) (reply int, err error)

返回指定的键存在的数量 keys: []string 键名数组 return: reply int

func (*Rdb) FlushAll

func (c *Rdb) FlushAll(mode string)

删除所有数据库中的所有键,此命令永不失败,慎用! mode: string 刷新模式 SYNC(同步)|ASYNC(异步)

func (*Rdb) FlushDb

func (c *Rdb) FlushDb(mode string)

删除当前数据库中的所有键,次命令永不失败,慎用! mode: string 刷新模式 SYNC(同步)|ASYNC(异步)

func (*Rdb) Move

func (c *Rdb) Move(key string, destinationDb int) (reply int, err error)

将指定key从当前数据库中移动到目标数据库中 key: string 键名 destinationDb: int 目标数据库 return:

  reply: int
			0: 移动失败
			1: 移动成功

func (*Rdb) Rename

func (c *Rdb) Rename(key, newKey string) (reply string, err error)

将指定key重命名,如果newKey是已经存在的key,则实际上会先执行隐式Del操作, 所以如果这个newKey包含比较大的值,则可能引起高延迟。 key: string 指定键名 newKey: string 新的键名 return:

reply: string

func (*Rdb) RenameNx

func (c *Rdb) RenameNx(key, newKey string) (reply string, err error)

将指定key重命名,仅当newKey不存在时才执行,如果指定key不存在,则会返回错误 所以如果这个newKey包含比较大的值,则可能引起高延迟。 key: string 指定键名 newKey: string 新的键名 return:

  reply: int
			0: newKey当前已经存在
			1: 重命名成功

func (*Rdb) Select

func (c *Rdb) Select(index int) (string, error)

SELECT 切换数据库 return: reply string

func (*Rdb) Touch

func (c *Rdb) Touch(keys []string) (reply int, err error)

更改指定键的最后访问时间。如果键不存在,则忽略 keys: []string 键名数组 return: reply int 成功修改的键的数量

func (*Rdb) Type

func (c *Rdb) Type(key string) (reply string, err error)

返回指定key的类型 key: 指定键名 return: reply string 可能的类型:string、list、set、zset、hash、stream

func (c *Rdb) Unlink(keys []string) (reply int, err error)

移除指定的key,异步删除,非阻塞式,删除大数据时推荐优先使用该方式,以免阻塞其他短io作业 keys: []string 键名数组 return: reply int 成功移除的键的数量

type Rexpire

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

func (*Rexpire) Expire

func (c *Rexpire) Expire(key string, seconds int, options string) (reply int, err error)

设置指定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

func (c *Rexpire) ExpireAt(key string, timestamp int, options string) (reply int, err error)

设置指定key的过期时间点 key: string 键名 timestamp: int 秒级时间戳 options: string NX|XX|GT|LT, 对应值的含义查阅https://redis.io/commands/expireat/ return:

  reply: int
			0: 设置失败
			1: 设置成功

func (*Rexpire) ExpireTime

func (c *Rexpire) ExpireTime(key string) (reply int, err error)

返回指定key的失效时间秒级时间戳,7.0.0版本以上可用 key: string 键名 return:

   reply: int
			 Unix timestamp in seconds
		     -1: key存在但未设置过过期时间
		     -2: key不存在

func (*Rexpire) Persist

func (c *Rexpire) Persist(key string) (reply int, err error)

移除指定key的过期时间,使其变为永不过期 key: string 键名 return:

reply: int
		0: 移除失败
		1: 移除成功

func (*Rexpire) Pexpire

func (c *Rexpire) Pexpire(key string, milliseconds int, options string) (reply int, err error)

设置指定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

func (c *Rexpire) PexpireAt(key string, miltimestamp int64, options string) (reply int, err error)

设置指定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

func (c *Rexpire) PexpireTime(key string) (reply int64, err error)

返回指定key的失效时间秒级时间戳,7.0.0版本以上支持 key: string 键名 return:

   reply: int64
			 Unix timestamp in seconds
		     -1: key存在但未设置过过期时间
		     -2: key不存在

func (*Rexpire) Ttl

func (c *Rexpire) Ttl(key string) (reply int, err error)

返回指定key的秒级剩余生存时间 key: string 键名 return:

   reply: int
			 TTL 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

func (c *Rgeo) GeoDist(key string, members [2]string, unit string) (string, error)

GEODIST, 返回的地理空间索引中两个成员之间的距离。 key: string 键名 members: [2]string{member1,member2} unit: string 单位,默认为M

M for 米.
KM for 公里.
MI for 英里.
FT for 英尺.

return:

reply: string

link: https://redis.io/commands/geodist/

func (*Rgeo) GeoHash

func (c *Rgeo) GeoHash(key string, members []string) (map[string]string, error)

GEOHASH, 返回给定的N个元素在集合中的有效的 Geohash 字符串 key: string 键名 members: []string 指定元素数组 return:

reply: map[string]string, 格式 map[member]hash

link: https://redis.io/commands/geohash/

func (*Rgeo) GeoPos

func (c *Rgeo) GeoPos(key string, members []string) (arr []map[string]string, err error)

GEOPOS, 返回给定的N个成员的经纬度位置信息 key: string 键名 members: []string 指定成员数组 return:

reply: []map[string]string, 格式 []map[string]string{"member":"", "longitude":"","latitude"}, ...}

link: https://redis.io/commands/geopos/

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":""}

link: https://redis.io/commands/geosearch/

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

link: https://redis.io/commands/geosearch/

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 存储到结果集中的成员数量

link: https://redis.io/commands/geosearchstore/

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":""}

link: https://redis.io/commands/geosearch/

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

link: https://redis.io/commands/geosearch/

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 存储到结果集中的成员数量

link: https://redis.io/commands/geosearchstore/

type Rhash

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

func (*Rhash) Hdel

func (c *Rhash) Hdel(key string, fields []string) (reply int, err error)

HDEL, 从key中移除指定fields key: string 键名 fields: []string 字段集 return: reply int 返回成功移除的field数量 link: https://redis.io/commands/hdel/

func (*Rhash) Hexists

func (c *Rhash) Hexists(key, field string) (reply int, err error)

HEXISTS, 判断key中是否包含指定fields key: string 键名 field: string 字段名 return:

  reply: int
			0: 不包含,或key不存在
			1: 包含

link: https://redis.io/commands/hexists/

func (*Rhash) Hget

func (c *Rhash) Hget(key, field string) (reply string, err error)

HGET, 获取key中指定field的值 key: string 键名 field: string 字段名 return: reply string link: https://redis.io/commands/hget/

func (*Rhash) HgetAll

func (c *Rhash) HgetAll(key string) (reply map[string]string, err error)

HGETALL, 返回存储在key中的所有字段和值 key: string 键名 return: reply map[string]string link: https://redis.io/commands/hgetall/

func (*Rhash) HincrBy

func (c *Rhash) HincrBy(key, field string, increment int) (reply int, err error)

HINCRBY , 将存储在 key 中的指定field值递增指定增量, 如果key不存在,则创建,若field不存在,则先创建并将值设为初始0 key: string 键名 field: string 字段名 increment: int 增量值,可以为负值 return: reply int 返回操作之后的新值 link:https://redis.io/commands/incrby/

func (*Rhash) HincrByFloat

func (c *Rhash) HincrByFloat(key, field string, increment float64) (reply float64, err error)

HINCRBYFLOAT , 将存储在 key 中的数字递增指定增量, 如果key不存在,则在执行操作之前将其设置为 0 key: string 键名 field: string 字段名 increment: float64 增量值,可以设置负数 return: reply float64 返回操作之后的新值 link:https://redis.io/commands/hincrbyfloat/

func (*Rhash) Hkeys

func (c *Rhash) Hkeys(key string) (reply []string, err error)

HKEYS, 返回指定key中存储的所有field, key若不存在返回空数组 key: string 键名 return: reply []string link: https://redis.io/commands/hkeys/

func (*Rhash) Hlen

func (c *Rhash) Hlen(key string) (reply int, err error)

HLEN, 返回指定key中存储的所有field的数量 key: string 键名 return: reply int link: https://redis.io/commands/hlen/

func (*Rhash) Hmget

func (c *Rhash) Hmget(key string, fields []string) (reply []string, err error)

HMGET, 返回key中指定field的值 key: string 键名 fields: []string 字段集 return: reply []string link: https://redis.io/commands/hmget/

func (*Rhash) Hset

func (c *Rhash) Hset(key string, fieldValues [][2]string) (reply int, err error)

HSET,可同时设置多个field=>value key: string 键名 fieldValues: [][2]string{{field, value}, ...} return: reply int 成功添加的字段数 link: https://redis.io/commands/hset/

func (*Rhash) HsetNx

func (c *Rhash) HsetNx(key, field, value string) (reply int, err error)

HSETNX, 一次只能设置一个field key: string 键名 field: string 字段名 value: string 字段值 return:

  reply: int
			0: 设置失败
			1: 设置成功,当且仅当field不存在时

link: https://redis.io/commands/hsetnx/

func (*Rhash) HstrLen

func (c *Rhash) HstrLen(key, field string) (reply int, err error)

HSTRLEN,返回指定field存储的value值字符串长度 key: string 键名 field: string 字段名 return: reply: int 若field不存在返回0 link: https://redis.io/commands/hstrlen/

func (*Rhash) Hvals

func (c *Rhash) Hvals(key string) (reply []string, err error)

HVALS, 返回指定key中存储的所有字段的value, key若不存在返回空数组 key: string 键名 return: reply []string link: https://redis.io/commands/hvals/

func (*Rhash) ScanAll

func (c *Rhash) ScanAll(key string, pattern string, count int) [][2]string

根据条件迭代指定key中所有满足条件的键值对 key: string 键名 pattern: string 正则表达式 count: int 单次迭代键值对的数量 return: arr [][2]string link:https://redis.io/commands/hscan/

func (*Rhash) ScanDel

func (c *Rhash) ScanDel(key string, pattern string, count int) (nums int)

根据条件迭代指定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

func (h *Rhyper) Pfadd(key string, elements []string) (int, error)

PFADD 将任意数量的元素添加到指定的 HyperLogLog 里面 如果命令执行时给定的键不存在, 那么程序将先创建一个空的 HyperLogLog 结构, 然后再执行命令。 key: string 给定的key elements: []string 元素集 return:

  reply: int
			0: 未发生任何修改
			1: 如果 HyperLogLog 的内部储存被修改了

link: https://redis.io/commands/pfadd/

func (*Rhyper) Pfcount

func (h *Rhyper) Pfcount(keys []string) (int, error)

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

func (h *Rhyper) Pfmerge(destkey string, sourcekeys []string) (string, error)

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

func (c *Rlist) Lindex(key string, index int) (string, error)

LINDEX, 返回指定索引位的元素 key: string 键名 index: int 索引,可以负数,当为负数时表示从列表尾部开始 return: reply string link: https://redis.io/commands/lindex/

func (*Rlist) Linsert

func (c *Rlist) Linsert(key, condition, pivot, element string) (int, error)

LINSERT, 在列表指定位置插入元素 key: string 键名 condition: string 指定插入的方式 BEFORE | AFTER pivot: string 参考值 element: string 待插入的元素 return:

  reply: int 成功插入元素之后列表的长度
			0: key不存在
			-1: 参考值pivot未找到

link: https://redis.io/commands/linsert/

func (*Rlist) Llen

func (c *Rlist) Llen(key string) (int, error)

LLEN, 返回指定列表的长度 key: string 键名 return: reply int link: https://redis.io/commands/llen/

func (*Rlist) Lmove

func (c *Rlist) Lmove(source, destination, wherefrom, whereto string) (string, error)

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

func (c *Rlist) Lpop(key string, count int) ([]string, error)

LPOP, 从列表的开头开始删除并返回一个或多个元素 key: string 键名 count: int 需移出的数量 return: reply []string link: https://redis.io/commands/lpop/

func (*Rlist) Lpos

func (c *Rlist) Lpos(key, element string, rank, count, maxlen int) ([]int, error)

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

func (c *Rlist) Lpush(key string, elements []string) (int, error)

LPUSH, 往列表头部插入多个元素, 若列表key不存在,则先创建 key: string 键名 elements: []string 待插入的元素数组 return: reply int 返回操作执行之后列表的长度 link: https://redis.io/commands/lpush/

func (*Rlist) Lpushx

func (c *Rlist) Lpushx(key string, elements []string) (int, error)

LPUSHX, 往列表头部插入多个元素, 若列表key不存在,则不执行任何操作 key: string 键名 elements: []string 待插入的元素数组 return: reply int 返回操作执行之后列表的长度 link: https://redis.io/commands/lpushx/

func (*Rlist) Lrange

func (c *Rlist) Lrange(key string, start, stop int) ([]string, error)

LRANGE, 返回列表指定偏移量区间的所有元素 超出范围的索引不会产生错误。如果开始大于列表的末尾,则返回一个空列表。 如果 stop 大于列表的实际末尾,Redis 会将其视为列表的最后一个元素。 key: string 键名 start: int 起始偏移量,可以为负数 stop: int 截止偏移量,可以为负数 return: reply []string link: https://redis.io/commands/lrange/

func (*Rlist) Lrem

func (c *Rlist) Lrem(key string, count int, element string) (int, error)

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

func (c *Rlist) Lset(key string, index int, element string) (string, error)

LSET, 将列表中索引位的元素设置为指定元素 key: string 键名 index: int 索引值 可为负数 element: string 元素值 return: reply string 成功返回"OK" link: https://redis.io/commands/lset/

func (*Rlist) Ltrim

func (c *Rlist) Ltrim(key string, start, stop int) (string, error)

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

func (c *Rlist) Rpop(key string, count int) ([]string, error)

RPOP, 从列表的尾部开始删除并返回一个或多个元素 key: string 键名 count: int 需移出的数量 return: reply []string link: https://redis.io/commands/rpop/

func (*Rlist) Rpush

func (c *Rlist) Rpush(key string, elements []string) (int, error)

RPUSH, 往列表尾部插入多个元素, 若列表key不存在,则先创建 key: string 键名 elements: []string 待插入的元素数组 return: reply int 返回操作执行之后列表的长度 link: https://redis.io/commands/rpush/

func (*Rlist) Rpushx

func (c *Rlist) Rpushx(key string, elements []string) (int, error)

RPUSHX, 往列表尾部插入多个元素, 若列表key不存在,则不执行任何操作 key: string 键名 elements: []string 待插入的元素数组 return: reply int 返回操作执行之后列表的长度 link: https://redis.io/commands/rpushx/

type Rscan

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

func (*Rscan) ScanAll

func (s *Rscan) ScanAll(pattern string, count int, typ string) (arr []string)

根据条件迭代当前数据库中所有满足条件的键集 pattern: string 正则表达式 count: int 单次迭代键的数量 typ: string 类型 6.0.0版本以后支持该参数 return: arr []string link:https://redis.io/commands/scan/

func (*Rscan) ScanDel

func (s *Rscan) ScanDel(pattern string, count int, typ string) (nums int)

根据条件迭代当前数据库中所有满足条件的键集并删除 pattern: string 正则表达式 count: int 单次迭代键的数量 typ: string 类型 6.0.0版本以后支持该参数 return: nums int 本次迭代删除的键数量 link:https://redis.io/commands/scan/

func (*Rscan) ScanOnce

func (s *Rscan) ScanOnce(cursor int, pattern string, count int, typ string) (int, []string, error)

根据条件迭代一次当前数据库中满足条件的键集 cursor: string 游标 pattern: string 正则表达式 count: int 单次迭代键的数量 typ: string 类型 6.0.0版本以后支持该参数 link:https://redis.io/commands/scan/

type Rset

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

func (*Rset) Sadd

func (c *Rset) Sadd(key string, members []string) (int, error)

SADD, 往指定集合添加成员,已经存在的跳过, key存在将创建 key: string 键名 members: []string 成员 return: reply int 成功添加的成员数 link: https://redis.io/commands/sadd/

func (*Rset) ScanAll

func (c *Rset) ScanAll(key string, pattern string, count int) (arr []string)

根据条件迭代指定key中所有满足条件的成员 key: string 键名 pattern: string 正则表达式 count: int 单次迭代成员的数量 return: arr []string link:https://redis.io/commands/sscan/

func (*Rset) ScanDel

func (c *Rset) ScanDel(key string, pattern string, count int) (nums int)

根据条件迭代指定key中所有满足条件的成员并删除 key: string 键名 pattern: string 正则表达式 count: int 单次迭代成员的数量 return: nums int 本次迭代删除的成员数量 link:https://redis.io/commands/sscan/

func (*Rset) ScanOnce

func (c *Rset) ScanOnce(key string, cursor int, pattern string, count int) (int, []string, error)

根据条件迭代一次指定key中满足条件的成员 key: string 键名 cursor: string 游标 pattern: string 正则表达式 count: int 单次迭代成员的数量, 存储的数据体量小时,一般返回都是全部结果,该选项并不起作用,这是正常的 link:https://redis.io/commands/sscan/

func (*Rset) Scard

func (c *Rset) Scard(key string) (int, error)

SCARD, 返回指定key中存储的成员数 key: string 键名 return: reply int link: https://redis.io/commands/scard/

func (*Rset) Sdiff

func (c *Rset) Sdiff(key string, diffKeys []string) ([]string, error)

SDIFF, 返回由第一个集合和所有后续集合之间的差异产生的集合成员 key: string 第一个集合键名 diffKeys: []string 其他对比的键名数组 return: reply int link: https://redis.io/commands/sdiff/

func (*Rset) SdiffStore

func (c *Rset) SdiffStore(key string, diffKeys []string, destination string) (int, error)

SDIFF, 比对第一个集合和所有后续集合之间的差异产生的集合成员, 并将结果存储到目标destination中,如果destination存在则值会被完全覆盖。 key: string 第一个集合键名 diffKeys: []string 其他对比的键名数组 destination: string 目标键名 return: reply int destination的成员数量 link: https://redis.io/commands/sdiffstore/

func (*Rset) Sinter

func (c *Rset) Sinter(keys []string) ([]string, error)

SINTER, 返回所有给定集合的交集成员,其中只要有一个空集合,结果必然为空,不存在的key也视为空集合 key: []string 键名数组 return: reply []string link: https://redis.io/commands/sinter/

func (*Rset) SinterCard

func (c *Rset) SinterCard(keys []string, limit int) (int, error)

SINTERCARD, 返回所有给定集合的交集成员数,其中只要有一个空集合, 结果必然为0,不存在的key也视为空集合 since: 7.0.0 keys: []string 键名数组 limit: int 限制返回的数量 return: reply int link: https://redis.io/commands/sintercard/

func (*Rset) SinterStore

func (c *Rset) SinterStore(keys []string, destination string) (int, error)

SINTERSTORE, 比对所有给定集合的交集成员数,并将结果存储到目标destination中,如果destination存在则值会被覆盖。 key: []string 其键名数组 destination: string 目标键名 return: reply int destination的成员数量 link: https://redis.io/commands/sinterstore/

func (*Rset) Sismember

func (c *Rset) Sismember(key, member string) (int, error)

SISMEMBER, 判断指定member是否在集合中 key: string 键名 member: string 成员 return:

  reply: int
			0: 不包含,或key不存在
			1: 包含

link: https://redis.io/commands/sismember/

func (*Rset) Smembers

func (c *Rset) Smembers(key string) ([]string, error)

SMEMBERS, 返回集合中所有成员,大数据量集合慎用,尤其是生产环境 key: string 键名 return: reply []string link: https://redis.io/commands/smembers/

func (*Rset) Smismember

func (c *Rset) Smismember(key string, members []string) ([]int, error)

SMISMEMBER, 判断每个给定的member是否在集合中, since: 6.2.0 key: string 键名 members: []string 成员数组 return:

  reply: []int 返回顺序与members顺序一致
			0: 不包含,或key不存在
			1: 包含

link: https://redis.io/commands/smismember/

func (*Rset) Smove

func (c *Rset) Smove(source, destination, member string) (int, error)

SMOVE, 判断每个给定的member是否在集合中,如果destination中当前已经存在该member 则会从source中移除该member,destination不做任何改变 source: string 源集合键名 destination: string 目标集合键名 members: 指定成员 return:

  reply: int
			0: 转移失败
			1: 成功转移

link: https://redis.io/commands/smove/

func (*Rset) Spop

func (c *Rset) Spop(key string, count int) ([]string, error)

SPOP,从集合中移除并返回一个或多个随机成员 key: string 键名 count: int 指定返回成员个数 return: reply []string link: https://redis.io/commands/spop/

func (*Rset) Srandmember

func (c *Rset) Srandmember(key string, count int) ([]string, error)

SRANDMEMBER,从集合中返回一个或多个随机成员 key: string 键名 count: int 指定返回成员个数

正数:返回值不存在重复,若超过集合最大成员数,则取最小者
负数:返回值可能有重复值,返回值数量始终等于count

return: reply []string link: https://redis.io/commands/srandmember/

func (*Rset) Srem

func (c *Rset) Srem(key string, members []string) (int, error)

SREM, 移除指定成员,不存在的成员会被忽略,不存在的集合始终返回0 key: string 键名 members: []string 成员数组 return: reply int 返回成功移除的成员数 link: https://redis.io/commands/srem/

func (*Rset) Sunion

func (c *Rset) Sunion(keys []string) ([]string, error)

SUNION,返回由所有给定集合的并集生成的集合的成员 keys: []string 键名数组 return: reply []string link: https://redis.io/commands/sunion/

func (*Rset) SunionStore

func (c *Rset) SunionStore(keys []string, destination string) ([]string, error)

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

func (c *Rstring) Append(key, value string) (reply int, err error)

APPEND, 在指定key尾部追加字符串 key: string 键名 value: string 追加字符串 return: reply int 追加之后的字符串长度 link:https://redis.io/commands/append/

func (*Rstring) Decr

func (c *Rstring) Decr(key string) (reply int, err error)

DECR , 将存储在 key 中的数字递减 1, 如果key不存在,则在执行操作之前将其设置为 0 key: string 键名 return: reply int 返回操作之后的新值 link:https://redis.io/commands/decr/

func (*Rstring) DecrBy

func (c *Rstring) DecrBy(key string, decrement int) (reply int, err error)

DECRBY , 将存储在 key 中的数字递减指定量, 如果key不存在,则在执行操作之前将其设置为 0 key: string 键名 decrement: int 递减值,可以为负值 return: reply int 返回操作之后的新值 link:https://redis.io/commands/decrby/

func (*Rstring) Get

func (c *Rstring) Get(key string) (reply string, err error)

GET key: string 键名 return: reply string link: https://redis.io/commands/get/

func (*Rstring) GetDel

func (c *Rstring) GetDel(key string) (reply string, err error)

GETDEL, 获取指定键值并在成功时删除该键 key: string 键名 return: reply string link: https://redis.io/commands/getdel/

func (*Rstring) GetEx

func (c *Rstring) GetEx(key, expireType string, timeout int64) (reply string, err error)

GETDEL, 获取指定键值并设置它的生命周期 key: string 键名 return: reply string expireType: string 设置生命周期格式, 取值范围:EX | PX | EXAT | PXAT | PERSIST link:https://redis.io/commands/getex/

func (*Rstring) GetRange

func (c *Rstring) GetRange(key string, start, end int) (reply string, err error)

GETRANGE,截取指定偏移量区间的字符串并返回 key: string 键名 start: int 支持负数 end: int 支持负数 return: reply string link:https://redis.io/commands/getrange/

func (*Rstring) GetSet

func (c *Rstring) GetSet(key, value string) (reply string, err error)

GETSET, 将键 key 的值设为 value , 并返回键 key 在被设置之前的旧值。6.2.0版本以后已弃用该方法 key: string 键名 value: string 值 return: reply string link:https://redis.io/commands/getset/

func (*Rstring) Incr

func (c *Rstring) Incr(key string) (reply int, err error)

INCR , 将存储在 key 中的数字递增 1, 如果key不存在,则在执行操作之前将其设置为 0 key: string 键名 return: reply int 返回操作之后的新值 link:https://redis.io/commands/incr/

func (*Rstring) IncrBy

func (c *Rstring) IncrBy(key string, increment int) (reply int, err error)

INCRBY , 将存储在 key 中的数字递增指定增量, 如果key不存在,则在执行操作之前将其设置为 0 key: string 键名 increment: int 增量值,可以为负值 return: reply int 返回操作之后的新值 link:https://redis.io/commands/incrby/

func (*Rstring) IncrByFloat

func (c *Rstring) IncrByFloat(key string, increment float64) (reply float64, err error)

INCRBYFLOAT , 将存储在 key 中的数字递增指定增量, 如果key不存在,则在执行操作之前将其设置为 0 key: string 键名 increment: float64 增量值,可以设置负数 return: reply float64 返回操作之后的新值 link:https://redis.io/commands/incrbyfloat/

func (*Rstring) Mget

func (c *Rstring) Mget(keys []string) (reply []string, err error)

MGET,同时为多个键设置值,此操作从不失败,如果某个给定键不存在,那么对应的值返回"" keys: ...string 键名 link: https://redis.io/commands/mget/

func (*Rstring) Mset

func (c *Rstring) Mset(keyValues [][2]string) (reply string, err error)

MSET,同时为多个键设置值,此操作从不失败,如果某个给定键已经存在,那么 MSET 将使用新值去覆盖旧值 keyValues: [][2]string link: https://redis.io/commands/mset/

func (*Rstring) MsetNx

func (c *Rstring) MsetNx(keyValues [][2]string) (reply int, err error)

MSETNX,同时为多个键设置值,只要有一个key存在,此命令都不会进行任何操作 keyValues: [][2]string return:

reply: int
		0: 设置失败
		1: 设置成功

link: https://redis.io/commands/msetnx/

func (*Rstring) PsetEx

func (c *Rstring) PsetEx(key, value string, milliseconds int) (reply string, err error)

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

func (c *Rstring) SetEx(key, value string, seconds int) (reply string, err error)

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

func (c *Rstring) SetNx(key, value string) (reply int, err error)

SETNX, 仅当key无值时执行操作 key: string 键名 seconds: int 秒级时间 value: string 值 return:

reply: int
		0: 设置失败
		1: 设置成功

link: https://redis.io/commands/setnx/

func (*Rstring) SetRange

func (c *Rstring) SetRange(key, value string, offset int) (reply int, err error)

SETRANGE,从指定偏移量位置开始,覆盖value的整个长度 key: string 键名 offset: int 偏移量 可以设置的最大偏移量为 2^29 -1 (536870911) value: string 值 return: reply int 修改之后的字符串长度 link: https://redis.io/commands/setrange/

func (*Rstring) Strlen

func (c *Rstring) Strlen(key string) (reply int, err error)

STRLEN,获取指定key存储的字符串值的长度 key: string 键名 return: reply int 长度 link: https://redis.io/commands/strlen/

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

func (c *Rzset) ScanAll(key string, pattern string, count int) (arr [][2]string)

根据条件迭代指定key中所有满足条件的成员 key: string 键名 pattern: string 正则表达式 count: int 单次迭代成员的数量 return: arr []string link:https://redis.io/commands/zscan/

func (*Rzset) ScanDel

func (c *Rzset) ScanDel(key string, pattern string, count int) (nums int)

根据条件迭代指定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 返回成功影响的成员总数

link: https://redis.io/commands/zadd/

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值

link: https://redis.io/commands/zadd/

func (*Rzset) Zcard

func (c *Rzset) Zcard(key string) (int, error)

ZCARD, 返回有序集合的元素总数, 不存在的key返回0 key: string 键名 return:

reply: int

link: https://redis.io/commands/zcard/

func (*Rzset) Zcount

func (c *Rzset) Zcount(key, min, max string) (int, error)

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

func (c *Rzset) Zdiff(key string, diffKeys []string) ([]string, error)

ZDIFF, 返回给定的N个有序集合之间的差异,此方法不指定 WITHSCORES 参数 since: 6.2.0 key: string 第一个集合键名 diffKeys: []string 需要比对的键名数组 return:

reply []string

link: https://redis.io/commands/zdiff/

func (*Rzset) ZdiffStore

func (c *Rzset) ZdiffStore(key string, diffKeys []string, destination string) (int, error)

ZDIFFSTORE, 比对给定的N个有序集合之间的差异,并将结果存储到指定destination中 若destination已经存在,则会完全覆盖 since: 6.2.0 key: string 第一个集合键名 diffKeys: []string 需要比对的键名数组 destination: string 比对结果目标存储键名 return:

reply int 返回存储到destination中的元素总数

link: https://redis.io/commands/zdiffstore/

func (*Rzset) ZdiffWithScore

func (c *Rzset) ZdiffWithScore(key string, diffKeys []string) (arr [][2]string, err error)

ZDIFF, 返回给定的N个有序集合之间的差异,此方法默认指定 WITHSCORES 参数 since: 6.2.0 key: string 第一个集合键名 diffKeys: []string 需要比对的键名数组 return:

reply [][2]string{{"score", "element"}, ...}

link: https://redis.io/commands/zdiff/

func (*Rzset) Zincrby

func (c *Rzset) Zincrby(key, increment, member string) (string, error)

ZINCRBY,按增量值递增指定成员的score值, 若成员不存在,则把增量值视为score值添加该成员, 若key不存在则创建 key: string 键名 increment: string 数值型增量字符串, 可以为负数值,代表递减 member: string 成员 return:

reply: string 返回设置之后该成员的新score值

link: https://redis.io/commands/zincrby/

func (*Rzset) Zinter

func (c *Rzset) Zinter(keys, weights []string, aggregate string) ([]string, error)

ZINTER, 返回多个给定集合的交集,此方法不指定 WITHSCORES 参数 since: 6.2.0 keys: []string 集合键名数组 weights: []string 乘法因子,值必须为数值型字符串 使用 WEIGHTS 选项,可以为每个输入排序集指定一个乘法因子。 这意味着在传递给聚合函数之前, 每个输入排序集中每个元素的分数都乘以该因子。 当未给出 WEIGHTS 时,倍增因子默认为 1。 aggregate: string , 取值: SUM | MIN | MAX 使用 AGGREGATE 选项, 可以指定结果集元素的score的聚合方式,默认为SUM return:

reply []string

link: https://redis.io/commands/zinter/

func (*Rzset) ZinterCard

func (c *Rzset) ZinterCard(keys []string, limit int) (int, error)

ZINTERCARD, 返回多个给定集合的交集成员数,若其中一个集合为空,则结果必然为0 since: 7.0.0 keys: []string 集合键名数组 limit: int 当提供可选的 LIMIT 参数(默认为 0,表示无限制)时,如果交集基数在计算中途达到极限, 算法将退出并产生极限作为基数。 这样的实现确保了limit低于实际交集基数的查询的显著加速。 return:

reply: int

link: https://redis.io/commands/zintercard/

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 返回结果集中的成员数

link: https://redis.io/commands/zinterstore/

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"}, ...}

link: https://redis.io/commands/zinter/

func (*Rzset) Zlexcount

func (c *Rzset) Zlexcount(key, min, max string) (string, error)

ZLEXCOUNT, 当有序集合中的所有元素都以相同的分数插入时, 为了强制按字典顺序排序,返回min和max区间范围内的成员数量 key: string 键名 min: string 起始值 max: string 截止值 return:

reply: int

link: https://redis.io/commands/zlexcount/

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}, ...}

link: https://redis.io/commands/zmpop/

func (*Rzset) Zmscore

func (c *Rzset) Zmscore(key string, members []string) (map[string]string, error)

ZMSCORE, 返回集合中指定成员的score值,不存在的成员score返回空 since: 6.2.0 key: string 键名 members: []string 成员数组 return:

reply: map[string]string, 格式为map[element]score

link: https://redis.io/commands/zmscore/

func (*Rzset) ZpopMax

func (c *Rzset) ZpopMax(key string, count int) (arr [][2]string, err error)

ZPOPMAX, 移除并返回集合中指定count个数的score最大成员 key: string 键名 count: int 移除数量 return:

reply: [][2]string{{score,element}, ...}

link: https://redis.io/commands/zpopmax/

func (*Rzset) ZpopMin

func (c *Rzset) ZpopMin(key string, count int) (arr [][2]string, err error)

ZPOPMIN, 移除并返回集合中指定count个数的score最小成员 key: string 键名 count: int 移除数量 return:

reply: [][2]string{{score,element}, ...}

link: https://redis.io/commands/zpopmin/

func (*Rzset) ZrandMember

func (c *Rzset) ZrandMember(key string, count int) ([]string, error)

ZRANDMEMBER, 从集合中随机返回N个成员,此方法默认不指定 WITHSCORES 参数 since: 6.2.0 key: string 键名 count: int 指定返回的成员数

正数:返回结果数量是count与集合成员总数两者的较小者
负数:返回的结果数量是count的绝对值,此时的结果可能会存在相同成员

return:

reply: []string

link: https://redis.io/commands/zrandmember/

func (*Rzset) ZrandMemberWithScore

func (c *Rzset) ZrandMemberWithScore(key string, count int) (arr [][2]string, err error)

ZRANDMEMBER, 从集合中随机返回N个成员,此方法默认指定 WITHSCORES 参数 since: 6.2.0 key: string 键名 count: int 指定返回的成员数

正数:返回结果数量是count与集合成员总数两者的较小者
负数:返回的结果数量是count的绝对值,此时的结果可能会存在相同成员

return:

reply: [][2]string{{score,element}, ...}

link: https://redis.io/commands/zrandmember/

func (*Rzset) Zrange

func (c *Rzset) Zrange(key, start, stop, byType string, isRev bool, limit []int) ([]string, 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: []string

link:https://redis.io/commands/zrange/

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  存储到目标集合的成员数

link:https://redis.io/commands/zrangestore/

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}, ...}

link:https://redis.io/commands/zrange/

func (*Rzset) Zrank

func (c *Rzset) Zrank(key, member string) (int, error)

ZRANK, 返回member在集合中的排名,score从低到高排列, 排名从0开始,意味着score最小的成员排名为0, 此方法不传递 WITHSCORE 参数 key: string 键名 member: string 指定成员 return:

reply: int ,特别说明:member不存在或者key不存在时,也会返回0 ,
但是此时error信息不是nil,所以可以通过判断error值来区分是否返回的是正常排名值。

link: https://redis.io/commands/zrank/

func (*Rzset) ZrankWithScore

func (c *Rzset) ZrankWithScore(key, member string) ([]string, error)

ZRANK, 返回member在集合中的排名,score从低到高排列, 排名从0开始,意味着score最小的成员排名为0, 此方法传递 WITHSCORE 参数 since: 7.2.0 key: string 键名 member: string 指定成员 return:

reply: []string

link: https://redis.io/commands/zrank/

func (*Rzset) Zrem

func (c *Rzset) Zrem(key string, members []string) (int, error)

ZREM, 移除集合中指定的N个成员,不存在的成员忽略 key: string 键名 members: []string 成员数组 return:

reply: int  返回成功移除的成员数,不存在的member不计算在内

link: https://redis.io/commands/zrem/

func (*Rzset) ZremRangeByLex

func (c *Rzset) ZremRangeByLex(key, min, max string) (int, error)

ZREMRANGEBYLEX, 当有序集合中的所有元素都以相同的score插入时,为了强制按字典顺序排序, 此命令删除由 min 和 max 指定的字典序范围之间的所有元素。 key: string 键名 min: string 起始值 max: string 结束值 return:

reply: int 返回被删除的元素数量

link:https://redis.io/commands/zremrangebylex/

func (*Rzset) ZremRangeByRank

func (c *Rzset) ZremRangeByRank(key string, min, max int) (int, error)

ZREMRANGEBYRANK, 删除存储在 key 处且排名在 start 和 stop 之间的排序集中的所有元素。 start 和 stop 都是基于 0 的索引,其中 0 是score最低的元素。 这些索引可以是负数, 表示从score最高的元素开始的偏移量。 例如:-1 是score最高的元素,-2 是score第二高的元素,依此类推。 key: string 键名 start: int 起始值 stop: int 结束值 return:

reply: int 返回被删除的元素数量

link:https://redis.io/commands/zremrangebyrank/

func (*Rzset) ZremRangeByScore

func (c *Rzset) ZremRangeByScore(key, min, max string) (int, error)

ZREMRANGEBYSCORE, 删除由 min 和 max 指定的score范围之间的所有元素。 key: string 键名 min: string 起始值 max: string 结束值 return:

reply: int 返回被删除的元素数量

link:https://redis.io/commands/zremrangebyscore/

func (*Rzset) Zrevrank

func (c *Rzset) Zrevrank(key, member string) (int, error)

ZREVRANK, 返回member在集合中的排名,score从高到低排列, 排名从0开始,意味着score最小的成员排名为0, 此方法不传递 WITHSCORE 参数 key: string 键名 member: string 指定成员 return:

reply: int ,特别说明:member不存在或者key不存在时,也会返回0 ,
但是此时error信息不是nil,所以可以通过判断error值来区分是否返回的是正常排名值。

link: https://redis.io/commands/zrevrank/

func (*Rzset) ZrevrankWithScore

func (c *Rzset) ZrevrankWithScore(key, member string) ([]string, error)

ZREVRANK, 返回member在集合中的排名,score从高到低排列, 排名从0开始,意味着score最小的成员排名为0, 此方法传递 WITHSCORE 参数 since: 7.2.0 key: string 键名 member: string 指定成员 return:

reply: []string

link: https://redis.io/commands/zrevrank/

func (*Rzset) Zscore

func (c *Rzset) Zscore(key, member string) (string, error)

ZSCORE, 返回集合中指定member的score值,member或key不存在,返回空 key: string 键名 member: string 指定成员 return:

reply: string

link: https://redis.io/commands/zscore/

func (*Rzset) Zunion

func (c *Rzset) Zunion(keys, weights []string, aggregate string) ([]string, error)

ZUNION, 返回多个给定集合的并集,此方法不指定 WITHSCORES 参数 since: 6.2.0 keys: []string 集合键名数组 weights: []string 乘法因子,值必须为数值型字符串 使用 WEIGHTS 选项,可以为每个输入排序集指定一个乘法因子。 这意味着在传递给聚合函数之前, 每个输入排序集中每个元素的分数都乘以该因子。 当未给出 WEIGHTS 时,倍增因子默认为 1。 aggregate: string , 取值: SUM | MIN | MAX 使用 AGGREGATE 选项, 可以指定结果集元素的score的聚合方式,默认为SUM return:

reply []string

link: https://redis.io/commands/zunion/

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 返回结果集中的成员数

link: https://redis.io/commands/zunionstore/

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"}, ...}

link: https://redis.io/commands/zunion/

Jump to

Keyboard shortcuts

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