redisClient

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2023 License: MIT Imports: 10 Imported by: 0

README

redis

RedisConnMap 全局 redis连接map

var RedisConnMap map[string]*RedisClient


Client 全局 redis连接

var Client *RedisClient


RedisClient redis客户端对象
type RedisClient struct {
	Conn redis.Conn
}

获取连接,取的是 RedisConnMap里的redis客户端对象

func GetClient(name string) (*RedisClient, error)


配置文件读redis配置,并将连接保存到 RedisConnMap

func InitConfRedisConn() error

配置

# redis 配置
redis:
  -
    name: "redis1"
    host: "127.0.0.1"
    port: "3306"
    db: 1
    password: ""
    maxIdle: 10  # 最大 Idle 连接
    maxActive: 50 # 最大 活跃 连接
  -
    name: "redis2"
    host: "127.0.0.1"
    port: "3306"
    db: 2
    password: ""
    maxIdle: 10  # 最大 Idle 连接
    maxActive: 50 # 最大 活跃 连接

连接redis

func Conn(host, password, db string) (redis.Conn, error)


连接redis, 连接存储到全局redis连接 Client

func RedisConn(host, password, db string) error


指定db的连接

func (c *RedisClient) SelectDB(db string) error


通过ssh隧道连接redis

func RedisSshConn(user, pass, addr, host, password, db string) error


GetKeyType 获取key的类型

func (c *RedisClient) GetKeyType(key string) string


GetKeyTTL 获取key的过期时间

func (c *RedisClient) GetKeyTTL(key string) int64


EXISTSKey 检查给定 key 是否存在

func (c *RedisClient) EXISTSKey(key string) bool


RenameKey 修改key名称

func (c *RedisClient) RenameKey(name, newName string) bool


UpdateKeyTTL 更新key ttl

func (c *RedisClient) UpdateKeyTTL(key string, ttl int64) bool


EXPIREATKey 指定key多久过期 接收的是unix时间戳

func (c *RedisClient) EXPIREATKey(key string, date int64) bool


DELKey 删除key

func (c *RedisClient) DELKey(key string) bool


HashHGETALL HGETALL 获取Hash value

func (c *RedisClient) HashHGETALL(key string) (map[string]string, error)


HashHGETALLInt HGETALL 获取Hash value

func (c *RedisClient) HashHGETALLInt(key string) (map[string]int, error)


HashHGETALLInt64 HGETALL 获取Hash value

func (c *RedisClient) HashHGETALLInt64(key string) (map[string]int64, error)


HashHSET HSET 新建Hash 单个field

func (c *RedisClient) HashHSET(key, field string, value interface{}) (int64, error)


HashHMSET HMSET 新建Hash 多个field

func (c *RedisClient) HashHMSET(key string, values map[interface{}]interface{}) error


HashHSETNX HSETNX key field value

func (c *RedisClient) HashHSETNX(key, field string, value interface{}) error


HashHDEL HDEL key field [field ...] 删除哈希表

func (c *RedisClient) HashHDEL(key string, fields []string) error


HashHEXISTS HEXISTS key field 查看哈希表

func (c *RedisClient) HashHEXISTS(key, fields string) bool


HashHGET HGET key field 返回哈希表

func (c *RedisClient) HashHGET(key, fields string) (string, error)


HashHINCRBY HINCRBY key field increment

func (c *RedisClient) HashHINCRBY(key, field string, increment int64) (int64, error)


HashHINCRBYFLOAT HINCRBYFLOAT key field increment

func (c *RedisClient) HashHINCRBYFLOAT(key, field string, increment float64) (res float64, err error)


HashHKEYS HKEYS key 返回哈希表

func (c *RedisClient) HashHKEYS(key string) (res []string, err error)


HashHLEN HLEN key 返回哈希表

func (c *RedisClient) HashHLEN(key string) (res int64, err error)


HashHMGET HMGET key field [field ...]

func (c *RedisClient) HashHMGET(key string, fields []string) (res []string, err error)


HashHVALS HVALS key

func (c *RedisClient) HashHVALS(key string) ([]string, error)


ListLRANGEALL LRANGE 获取List value

func (c *RedisClient) ListLRANGEALL(key string) ([]interface{}, error)


ListLRANGE LRANGE key start stop

func (c *RedisClient) ListLRANGE(key string, start, stop int64) ([]interface{}, error)


ListLPUSH LPUSH 新创建list 将一个或多个值 value 插入到列表 key 的表头

func (c *RedisClient) ListLPUSH(key string, values []interface{}) error


ListRPUSH RPUSH key value [value ...]

func (c *RedisClient) ListRPUSH(key string, values []interface{}) error


ListLINDEX LINDEX key index

func (c *RedisClient) ListLINDEX(key string, index int64) (string, error)


ListLINSERT LINSERT key BEFORE|AFTER pivot value

func (c *RedisClient) ListLINSERT(direction bool, key, pivot, value string) error


ListLLEN LLEN key

func (c *RedisClient) ListLLEN(key string) (int64, error)


ListLPOP LPOP key

func (c *RedisClient) ListLPOP(key string) (string, error)


ListLPUSHX LPUSHX key value

func (c *RedisClient) ListLPUSHX(key string, value interface{}) error


ListLREM LREM key count value

func (c *RedisClient) ListLREM(key string, count int64, value interface{}) error


ListLSET LSET key index value

func (c *RedisClient) ListLSET(key string, index int64, value interface{}) error


ListLTRIM LTRIM key start stop

func (c *RedisClient) ListLTRIM(key string, start, stop int64) error


ListRPOP RPOP key

func (c *RedisClient) ListRPOP(key string) (string, error)


ListRPOPLPUSH RPOPLPUSH source destination

func (c *RedisClient) ListRPOPLPUSH(key, destination string) (string, error)


ListRPUSHX RPUSHX key value

func (c *RedisClient) ListRPUSHX(key string, value interface{}) error


SetSMEMBERS SMEMBERS key 返回集合 key 中的所有成员。

func (c *RedisClient) SetSMEMBERS(key string) ([]interface{}, error)


SetSADD SADD 新创建Set 将一个或多个 member 元素加入到集合 key 当中,已经存在于集合的 member 元素将被忽略。

func (c *RedisClient) SetSADD(key string, values []interface{}) error


SetSCARD SCARD key

func (c *RedisClient) SetSCARD(key string) error


SetSDIFF SDIFF key [key ...]

func (c *RedisClient) SetSDIFF(keys []string) ([]interface{}, error)


SetSDIFFSTORE SDIFFSTORE destination key [key ...]

func (c *RedisClient) SetSDIFFSTORE(key string, keys []string) ([]interface{}, error)


SetSINTER SINTER key [key ...]

func (c *RedisClient) SetSINTER(keys []string) ([]interface{}, error)


SetSINTERSTORE SINTERSTORE destination key [key ...]

func (c *RedisClient) SetSINTERSTORE(key string, keys []string) ([]interface{}, error)


SetSISMEMBER SISMEMBER key member

func (c *RedisClient) SetSISMEMBER(key string, value interface{}) (resBool bool, err error)


SetSMOVE SMOVE source destination member

func (c *RedisClient) SetSMOVE(key, destination string, member interface{}) (resBool bool, err error)


SetSPOP SPOP key

func (c *RedisClient) SetSPOP(key string) (string, error)


SetSRANDMEMBER SRANDMEMBER key [count]

func (c *RedisClient) SetSRANDMEMBER(key string, count int64) ([]interface{}, error)


SetSREM SREM key member [member ...]

func (c *RedisClient) SetSREM(key string, member []interface{}) error


SetSUNION SUNION key [key ...]

func (c *RedisClient) SetSUNION(keys []string) ([]interface{}, error)


SetSUNIONSTORE SUNIONSTORE destination key [key ...]

func (c *RedisClient) SetSUNIONSTORE(key string, keys []string) ([]interface{}, error)


StringGet GET 获取String value

func (c *RedisClient) StringGet(key string) (string, error)


StringSET SET 新建String

func (c *RedisClient) StringSET(key string, value interface{}) error


StringSETEX SETEX 新建String 含有时间

func (c *RedisClient) StringSETEX(key string, ttl int64, value interface{}) error


StringPSETEX PSETEX key milliseconds value

func (c *RedisClient) StringPSETEX(key string, ttl int64, value interface{}) error


StringSETNX key value

func (c *RedisClient) StringSETNX(key string, value interface{}) error


StringSETRANGE SETRANGE key offset value

func (c *RedisClient) StringSETRANGE(key string, offset int64, value interface{}) error


StringAPPEND APPEND key value

func (c *RedisClient) StringAPPEND(key string, value interface{}) error


StringDECR key

func (c *RedisClient) StringDECR(key string) (int64, error)


StringDECRBY DECRBY key decrement

func (c *RedisClient) StringDECRBY(key, decrement string) (int64, error)


StringGETRANGE GETRANGE key start end

func (c *RedisClient) StringGETRANGE(key string, start, end int64) (string, error)


StringGETSET GETSET key value

func (c *RedisClient) StringGETSET(key string, value interface{}) (string, error)


StringINCR INCR key

func (c *RedisClient) StringINCR(key string) (int64, error)


StringINCRBY INCRBY key increment

func (c *RedisClient) StringINCRBY(key, increment string) (int64, error)


StringINCRBYFLOAT INCRBYFLOAT key increment

func (c *RedisClient) StringINCRBYFLOAT(key, increment float64) (float64, error)


StringMGET MGET key [key ...]

func (c *RedisClient) StringMGET(key []interface{}) ([]string, error)


StringMSET MSET key value [key value ...]

func (c *RedisClient) StringMSET(values []interface{}) error


StringMSETNX MSETNX key value [key value ...]

func (c *RedisClient) StringMSETNX(values []interface{}) error


ZSetZRANGEALL ZRANGE 获取ZSet value 返回集合 有序集成员的列表。

func (c *RedisClient) ZSetZRANGEALL(key string) ([]interface{}, error)


ZSetZRANGE ZRANGE key start stop [WITHSCORES]

func (c *RedisClient) ZSetZRANGE(key string, start, stop int64) ([]interface{}, error)


ZSetZREVRANGE ZREVRANGE key start stop [WITHSCORES]

func (c *RedisClient) ZSetZREVRANGE(key string, start, stop int64) ([]interface{}, error)


ZSetZADD ZADD 新创建ZSet 将一个或多个 member 元素及其 score 值加入到有序集 key 当中

func (c *RedisClient) ZSetZADD(key string, values []interface{}) error


ZSetZCARD ZCARD key

func (c *RedisClient) ZSetZCARD(key string) (int64, error)


ZSetZCOUNT ZCOUNT key min max

func (c *RedisClient) ZSetZCOUNT(key string, min, max int64) (int64, error)


ZSetZINCRBY ZINCRBY key increment member

func (c *RedisClient) ZSetZINCRBY(key, member string, increment int64) (string, error)


ZSetZRANGEBYSCORE ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count]

func (c *RedisClient) ZSetZRANGEBYSCORE(key string, min, max, offset, count int64) ([]interface{}, error)


ZSetZRANGEBYSCOREALL ZRANGEBYSCORE

func (c *RedisClient) ZSetZRANGEBYSCOREALL(key string) ([]interface{}, error)


ZSetZREVRANGEBYSCORE ZREVRANGEBYSCORE

func (c *RedisClient) ZSetZREVRANGEBYSCORE(key string, min, max, offset, count int64) ([]interface{}, error)


ZSetZREVRANGEBYSCOREALL ZREVRANGEBYSCOREALL

func (c *RedisClient) ZSetZREVRANGEBYSCOREALL(key string) ([]interface{}, error)


ZSetZRANK ZRANK key member

func (c *RedisClient) ZSetZRANK(key string, member interface{}) (int64, error)


ZSetZREM ZREM key member [member ...]

func (c *RedisClient) ZSetZREM(key string, member []interface{}) error


ZSetZREMRANGEBYRANK ZREMRANGEBYRANK key start stop

func (c *RedisClient) ZSetZREMRANGEBYRANK(key string, start, stop int64) error


ZSetZREMRANGEBYSCORE ZREMRANGEBYSCORE key min max

func (c *RedisClient) ZSetZREMRANGEBYSCORE(key string, min, max int64) error


ZSetZREVRANK ZREVRANK key member

func (c *RedisClient) ZSetZREVRANK(key string, member interface{}) (int64, error)


ZSetZSCORE ZSCORE key member

func (c *RedisClient) ZSetZSCORE(key string, member interface{}) (string, error)


Documentation

Index

Constants

This section is empty.

Variables

View Source
var NotConnError = fmt.Errorf("未连接redis")
View Source
var RedisPoolMap map[string]*RedisPool = make(map[string]*RedisPool, 0)

RedisPoolMap 全局redis 连接对象 map

Functions

func Conn

func Conn(host, password, db string) (redis.Conn, error)

func GetConn

func GetConn(name string) (redis.Conn, error)

func InitConfRedisPool

func InitConfRedisPool()

func RedisPoolConn

func RedisPoolConn(host, password, db string, maxIdle, maxActive int) *redis.Pool

func RedisSshConn

func RedisSshConn(user, pass, addr, host, password, db string) (redis.Conn, error)

Types

type RedisClient

type RedisClient struct {
	Name string
}

func NewRedisClient

func NewRedisClient(name string) *RedisClient

func (*RedisClient) DELKey

func (c *RedisClient) DELKey(key string) bool

DELKey 删除key

func (*RedisClient) EXISTSKey

func (c *RedisClient) EXISTSKey(key string) bool

EXISTSKey 检查给定 key 是否存在。

func (*RedisClient) EXPIREATKey

func (c *RedisClient) EXPIREATKey(key string, date int64) bool

EXPIREATKey 指定key多久过期 接收的是unix时间戳

func (*RedisClient) GetALLKeys

func (c *RedisClient) GetALLKeys(match string) (ksyList map[string]int)

GetALLKeys 获取所有的key

func (*RedisClient) GetKeyTTL

func (c *RedisClient) GetKeyTTL(key string) int64

GetKeyTTL 获取key的过期时间

func (*RedisClient) GetKeyType

func (c *RedisClient) GetKeyType(key string) string

GetKeyType 获取key的类型

func (*RedisClient) HashHDEL

func (c *RedisClient) HashHDEL(key string, fields []string) error

HashHDEL HDEL key field [field ...] 删除哈希表 key 中的一个或多个指定域,不存在的域将被忽略。

func (*RedisClient) HashHEXISTS

func (c *RedisClient) HashHEXISTS(key, fields string) bool

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

func (*RedisClient) HashHGET

func (c *RedisClient) HashHGET(key, fields string) (string, error)

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

func (*RedisClient) HashHGETALL

func (c *RedisClient) HashHGETALL(key string) (map[string]string, error)

HashHGETALL HGETALL 获取Hash value

func (*RedisClient) HashHGETALLInt

func (c *RedisClient) HashHGETALLInt(key string) (map[string]int, error)

HashHGETALLInt HGETALL 获取Hash value

func (*RedisClient) HashHGETALLInt64

func (c *RedisClient) HashHGETALLInt64(key string) (map[string]int64, error)

HashHGETALLInt64 HGETALL 获取Hash value

func (*RedisClient) HashHINCRBY

func (c *RedisClient) HashHINCRBY(key, field string, increment int64) (int64, error)

HashHINCRBY HINCRBY key field increment 为哈希表 key 中的域 field 的值加上增量 increment 。 增量也可以为负数,相当于对给定域进行减法操作。 如果 key 不存在,一个新的哈希表被创建并执行 HINCRBY 命令。 如果域 field 不存在,那么在执行命令前,域的值被初始化为 0

func (*RedisClient) HashHINCRBYFLOAT

func (c *RedisClient) HashHINCRBYFLOAT(key, field string, increment float64) (float64, error)

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

func (*RedisClient) HashHKEYS

func (c *RedisClient) HashHKEYS(key string) ([]string, error)

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

func (*RedisClient) HashHLEN

func (c *RedisClient) HashHLEN(key string) (int64, error)

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

func (*RedisClient) HashHMGET

func (c *RedisClient) HashHMGET(key string, fields []string) ([]string, error)

HashHMGET HMGET key field [field ...] 返回哈希表 key 中,一个或多个给定域的值。 如果给定的域不存在于哈希表,那么返回一个 nil 值。

func (*RedisClient) HashHMSET

func (c *RedisClient) HashHMSET(key string, values map[interface{}]interface{}) error

HashHMSET HMSET 新建Hash 多个field HMSET key field value [field value ...] 同时将多个 field-value (域-值)对设置到哈希表 key 中。 此命令会覆盖哈希表中已存在的域。

func (*RedisClient) HashHSET

func (c *RedisClient) HashHSET(key, field string, value interface{}) (int64, error)

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

func (*RedisClient) HashHSETNX

func (c *RedisClient) HashHSETNX(key, field string, value interface{}) error

HashHSETNX HSETNX key field value 给hash追加field value 将哈希表 key 中的域 field 的值设置为 value ,当且仅当域 field 不存在。

func (*RedisClient) HashHVALS

func (c *RedisClient) HashHVALS(key string) ([]string, error)

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

func (*RedisClient) ListBLPOP

func (c *RedisClient) ListBLPOP()

ListBLPOP BLPOP key [key ...] timeout BLPOP 是列表的阻塞式(blocking)弹出原语。 它是 LPOP 命令的阻塞版本,当给定列表内没有任何元素可供弹出的时候,连接将被 BLPOP 命令阻塞,直到等待超时或发现可弹出元素为止。

func (*RedisClient) ListBRPOP

func (c *RedisClient) ListBRPOP()

ListBRPOP BRPOP key [key ...] timeout BRPOP 是列表的阻塞式(blocking)弹出原语。 它是 RPOP 命令的阻塞版本,当给定列表内没有任何元素可供弹出的时候,连接将被 BRPOP 命令阻塞,直到等待超时或发现可弹出元素为止。

func (*RedisClient) ListBRPOPLPUSH

func (c *RedisClient) ListBRPOPLPUSH()

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

func (*RedisClient) ListLINDEX

func (c *RedisClient) ListLINDEX(key string, index int64) (string, error)

ListLINDEX LINDEX key index 返回列表 key 中,下标为 index 的元素。

func (*RedisClient) ListLINSERT

func (c *RedisClient) ListLINSERT(direction bool, key, pivot, value string) error

ListLINSERT LINSERT key BEFORE|AFTER pivot value 将值 value 插入到列表 key 当中,位于值 pivot 之前或之后。 当 pivot 不存在于列表 key 时,不执行任何操作。 当 key 不存在时, key 被视为空列表,不执行任何操作。 如果 key 不是列表类型,返回一个错误。 direction : 方向 bool true:BEFORE(前) false: AFTER(后)

func (*RedisClient) ListLLEN

func (c *RedisClient) ListLLEN(key string) (int64, error)

ListLLEN LLEN key 返回列表 key 的长度。 如果 key 不存在,则 key 被解释为一个空列表,返回 0 .

func (*RedisClient) ListLPOP

func (c *RedisClient) ListLPOP(key string) (string, error)

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

func (*RedisClient) ListLPUSH

func (c *RedisClient) ListLPUSH(key string, values []interface{}) error

ListLPUSH LPUSH 新创建list 将一个或多个值 value 插入到列表 key 的表头

func (*RedisClient) ListLPUSHX

func (c *RedisClient) ListLPUSHX(key string, value interface{}) error

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

func (*RedisClient) ListLRANGE

func (c *RedisClient) ListLRANGE(key string, start, stop int64) ([]interface{}, error)

ListLRANGE LRANGE key start stop 返回列表 key 中指定区间内的元素,区间以偏移量 start 和 stop 指定。

func (*RedisClient) ListLRANGEALL

func (c *RedisClient) ListLRANGEALL(key string) ([]interface{}, error)

ListLRANGEALL LRANGE 获取List value

func (*RedisClient) ListLREM

func (c *RedisClient) ListLREM(key string, count int64, value interface{}) error

ListLREM LREM key count value 根据参数 count 的值,移除列表中与参数 value 相等的元素。 count 的值可以是以下几种: count > 0 : 从表头开始向表尾搜索,移除与 value 相等的元素,数量为 count 。 count < 0 : 从表尾开始向表头搜索,移除与 value 相等的元素,数量为 count 的绝对值。 count = 0 : 移除表中所有与 value 相等的值。

func (*RedisClient) ListLSET

func (c *RedisClient) ListLSET(key string, index int64, value interface{}) error

ListLSET LSET key index value 将列表 key 下标为 index 的元素的值设置为 value 。 当 index 参数超出范围,或对一个空列表( key 不存在)进行 LSET 时,返回一个错误。

func (*RedisClient) ListLTRIM

func (c *RedisClient) ListLTRIM(key string, start, stop int64) error

ListLTRIM LTRIM key start stop 对一个列表进行修剪(trim),就是说,让列表只保留指定区间内的元素,不在指定区间之内的元素都将被删除。 举个例子,执行命令 LTRIM list 0 2 ,表示只保留列表 list 的前三个元素,其余元素全部删除。

func (*RedisClient) ListRPOP

func (c *RedisClient) ListRPOP(key string) (string, error)

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

func (*RedisClient) ListRPOPLPUSH

func (c *RedisClient) ListRPOPLPUSH(key, destination string) (string, error)

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

func (*RedisClient) ListRPUSH

func (c *RedisClient) ListRPUSH(key string, values []interface{}) error

ListRPUSH RPUSH key value [value ...] 将一个或多个值 value 插入到列表 key 的表尾(最右边)。 如果有多个 value 值,那么各个 value 值按从左到右的顺序依次插入到表尾:比如对一个空列表 mylist 执行 RPUSH mylist a b c ,得出的结果列表为 a b c ,等同于执行命令 RPUSH mylist a 、 RPUSH mylist b 、 RPUSH mylist c 。 新创建List 将一个或多个值 value 插入到列表 key 的表尾(最右边)。

func (*RedisClient) ListRPUSHX

func (c *RedisClient) ListRPUSHX(key string, value interface{}) error

ListRPUSHX RPUSHX key value 将值 value 插入到列表 key 的表尾,当且仅当 key 存在并且是一个列表。

func (*RedisClient) RenameKey

func (c *RedisClient) RenameKey(name, newName string) bool

RenameKey 修改key名称

func (*RedisClient) SearchKeys

func (c *RedisClient) SearchKeys(match string) (ksyList map[string]int)

func (*RedisClient) SelectDB

func (c *RedisClient) SelectDB(db string) error

SelectDB 指定db的连接

func (*RedisClient) SetSADD

func (c *RedisClient) SetSADD(key string, values []interface{}) error

SetSADD SADD 新创建Set 将一个或多个 member 元素加入到集合 key 当中,已经存在于集合的 member 元素将被忽略。

func (*RedisClient) SetSCARD

func (c *RedisClient) SetSCARD(key string) error

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

func (*RedisClient) SetSDIFF

func (c *RedisClient) SetSDIFF(keys []string) ([]interface{}, error)

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

func (*RedisClient) SetSDIFFSTORE

func (c *RedisClient) SetSDIFFSTORE(key string, keys []string) ([]interface{}, error)

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

func (*RedisClient) SetSINTER

func (c *RedisClient) SetSINTER(keys []string) ([]interface{}, error)

SetSINTER SINTER key [key ...] 返回一个集合的全部成员,该集合是所有给定集合的交集。 不存在的 key 被视为空集。

func (*RedisClient) SetSINTERSTORE

func (c *RedisClient) SetSINTERSTORE(key string, keys []string) ([]interface{}, error)

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

func (*RedisClient) SetSISMEMBER

func (c *RedisClient) SetSISMEMBER(key string, value interface{}) (bool, error)

SetSISMEMBER SISMEMBER key member 判断 member 元素是否集合 key 的成员。 返回值: 如果 member 元素是集合的成员,返回 1 。 如果 member 元素不是集合的成员,或 key 不存在,返回 0 。

func (*RedisClient) SetSMEMBERS

func (c *RedisClient) SetSMEMBERS(key string) ([]interface{}, error)

SetSMEMBERS SMEMBERS key 返回集合 key 中的所有成员。 获取Set value 返回集合 key 中的所有成员。

func (*RedisClient) SetSMOVE

func (c *RedisClient) SetSMOVE(key, destination string, member interface{}) (bool, error)

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

func (*RedisClient) SetSPOP

func (c *RedisClient) SetSPOP(key string) (string, error)

SetSPOP SPOP key 移除并返回集合中的一个随机元素。

func (*RedisClient) SetSRANDMEMBER

func (c *RedisClient) SetSRANDMEMBER(key string, count int64) ([]interface{}, error)

SetSRANDMEMBER SRANDMEMBER key [count] 如果命令执行时,只提供了 key 参数,那么返回集合中的一个随机元素。 如果 count 为正数,且小于集合基数,那么命令返回一个包含 count 个元素的数组,数组中的元素各不相同。 如果 count 大于等于集合基数,那么返回整个集合。 如果 count 为负数,那么命令返回一个数组,数组中的元素可能会重复出现多次,而数组的长度为 count 的绝对值。

func (*RedisClient) SetSREM

func (c *RedisClient) SetSREM(key string, member []interface{}) error

SetSREM SREM key member [member ...] 移除集合 key 中的一个或多个 member 元素,不存在的 member 元素会被忽略。

func (*RedisClient) SetSUNION

func (c *RedisClient) SetSUNION(keys []string) ([]interface{}, error)

SetSUNION SUNION key [key ...] 返回一个集合的全部成员,该集合是所有给定集合的并集。

func (*RedisClient) SetSUNIONSTORE

func (c *RedisClient) SetSUNIONSTORE(key string, keys []string) ([]interface{}, error)

SetSUNIONSTORE SUNIONSTORE destination key [key ...] 这个命令类似于 SUNION 命令,但它将结果保存到 destination 集合,而不是简单地返回结果集。

func (*RedisClient) StringAPPEND

func (c *RedisClient) StringAPPEND(key string, value interface{}) error

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

func (*RedisClient) StringBITCOUNT

func (c *RedisClient) StringBITCOUNT(key string) (int64, error)

StringBITCOUNT BITCOUNT key [start] [end] 计算给定字符串中,被设置为 1 的比特位的数量。

func (*RedisClient) StringBITOP

func (c *RedisClient) StringBITOP()

StringBITOP BITOP operation destkey key [key ...] 对一个或多个保存二进制位的字符串 key 进行位元操作,并将结果保存到 destkey 上。 BITOP AND destkey key [key ...] ,对一个或多个 key 求逻辑并,并将结果保存到 destkey 。 BITOP OR destkey key [key ...] ,对一个或多个 key 求逻辑或,并将结果保存到 destkey 。 BITOP XOR destkey key [key ...] ,对一个或多个 key 求逻辑异或,并将结果保存到 destkey 。 BITOP NOT destkey key ,对给定 key 求逻辑非,并将结果保存到 destkey 。

func (*RedisClient) StringDECR

func (c *RedisClient) StringDECR(key string) (int64, error)

StringDECR key 将 key 中储存的数字值减一。 如果 key 不存在,那么 key 的值会先被初始化为 0 ,然后再执行 DECR 操作。 如果值包含错误的类型,或字符串类型的值不能表示为数字,那么返回一个错误。

func (*RedisClient) StringDECRBY

func (c *RedisClient) StringDECRBY(key, decrement string) (int64, error)

StringDECRBY DECRBY key decrement 将 key 所储存的值减去减量 decrement 。

func (*RedisClient) StringGETBIT

func (c *RedisClient) StringGETBIT(key string, offset int64) (int64, error)

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

func (*RedisClient) StringGETRANGE

func (c *RedisClient) StringGETRANGE(key string, start, end int64) (string, error)

StringGETRANGE GETRANGE key start end 返回 key 中字符串值的子字符串,字符串的截取范围由 start 和 end 两个偏移量决定(包括 start 和 end 在内)。

func (*RedisClient) StringGETSET

func (c *RedisClient) StringGETSET(key string, value interface{}) (string, error)

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

func (*RedisClient) StringGet

func (c *RedisClient) StringGet(key string) (string, error)

StringGet GET 获取String value

func (*RedisClient) StringINCR

func (c *RedisClient) StringINCR(key string) (int64, error)

StringINCR INCR key 将 key 中储存的数字值增一。 如果 key 不存在,那么 key 的值会先被初始化为 0 ,然后再执行 INCR 操作。 如果值包含错误的类型,或字符串类型的值不能表示为数字,那么返回一个错误。

func (*RedisClient) StringINCRBY

func (c *RedisClient) StringINCRBY(key, increment string) (int64, error)

StringINCRBY INCRBY key increment 将 key 所储存的值加上增量 increment 。

func (*RedisClient) StringINCRBYFLOAT

func (c *RedisClient) StringINCRBYFLOAT(key, increment float64) (float64, error)

StringINCRBYFLOAT INCRBYFLOAT key increment 为 key 中所储存的值加上浮点数增量 increment 。

func (*RedisClient) StringMGET

func (c *RedisClient) StringMGET(key []interface{}) ([]string, error)

StringMGET MGET key [key ...] 返回所有(一个或多个)给定 key 的值。 如果给定的 key 里面,有某个 key 不存在,那么这个 key 返回特殊值 nil 。因此,该命令永不失败。

func (*RedisClient) StringMSET

func (c *RedisClient) StringMSET(values []interface{}) error

StringMSET MSET key value [key value ...] 同时设置一个或多个 key-value 对。 如果某个给定 key 已经存在,那么 MSET 会用新值覆盖原来的旧值,如果这不是你所希望的效果, 请考虑使用 MSETNX 命令:它只会在所有给定 key 都不存在的情况下进行设置操作。 MSET 是一个原子性(atomic)操作,所有给定 key 都会在同一时间内被设置,某些给定 key 被更新而另一些给定 key 没有改变的情况,不可能发生。

func (*RedisClient) StringMSETNX

func (c *RedisClient) StringMSETNX(values []interface{}) error

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

func (*RedisClient) StringPSETEX

func (c *RedisClient) StringPSETEX(key string, ttl int64, value interface{}) error

StringPSETEX PSETEX key milliseconds value 这个命令和 SETEX 命令相似,但它以毫秒为单位设置 key 的生存时间,而不是像 SETEX 命令那样,以秒为单位。

func (*RedisClient) StringSET

func (c *RedisClient) StringSET(key string, value interface{}) error

StringSET SET 新建String

func (*RedisClient) StringSETBIT

func (c *RedisClient) StringSETBIT(key string, offset, value int64) error

StringSETBIT SETBIT key offset value 对 key 所储存的字符串值,设置或清除指定偏移量上的位(bit)。 value : 位的设置或清除取决于 value 参数,可以是 0 也可以是 1 。 注意 offset 不能太大,越大key越大

func (*RedisClient) StringSETEX

func (c *RedisClient) StringSETEX(key string, ttl int64, value interface{}) error

StringSETEX SETEX 新建String 含有时间

func (*RedisClient) StringSETNX

func (c *RedisClient) StringSETNX(key string, value interface{}) error

StringSETNX key value 将 key 的值设为 value ,当且仅当 key 不存在。 若给定的 key 已经存在,则 SETNX 不做任何动作。

func (*RedisClient) StringSETRANGE

func (c *RedisClient) StringSETRANGE(key string, offset int64, value interface{}) error

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

func (*RedisClient) StringSTRLEN

func (c *RedisClient) StringSTRLEN()

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

func (*RedisClient) UpdateKeyTTL

func (c *RedisClient) UpdateKeyTTL(key string, ttl int64) bool

UpdateKeyTTL 更新key ttl

func (*RedisClient) ZSetZADD

func (c *RedisClient) ZSetZADD(key string, weight interface{}, field interface{}) error

ZSetZADD ZADD 新创建ZSet 将一个或多个 member 元素及其 score 值加入到有序集 key 当中。

func (*RedisClient) ZSetZCARD

func (c *RedisClient) ZSetZCARD(key string) (int64, error)

ZSetZCARD ZCARD key 返回有序集 key 的基数。

func (*RedisClient) ZSetZCOUNT

func (c *RedisClient) ZSetZCOUNT(key string, min, max int64) (int64, error)

ZSetZCOUNT ZCOUNT key min max 返回有序集 key 中, score 值在 min 和 max 之间(默认包括 score 值等于 min 或 max )的成员的数量。

func (*RedisClient) ZSetZINCRBY

func (c *RedisClient) ZSetZINCRBY(key, member string, increment int64) (string, error)

ZSetZINCRBY ZINCRBY key increment member 为有序集 key 的成员 member 的 score 值加上增量 increment 。 可以通过传递一个负数值 increment ,让 score 减去相应的值,比如 ZINCRBY key -5 member ,就是让 member 的 score 值减去 5 。 当 key 不存在,或 member 不是 key 的成员时, ZINCRBY key increment member 等同于 ZADD key increment member 。

func (*RedisClient) ZSetZINTERSTORE

func (c *RedisClient) ZSetZINTERSTORE()

ZSetZINTERSTORE ZINTERSTORE destination numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX] 计算给定的一个或多个有序集的交集,其中给定 key 的数量必须以 numkeys 参数指定,并将该交集(结果集)储存到 destination 。 默认情况下,结果集中某个成员的 score 值是所有给定集下该成员 score 值之和.

func (*RedisClient) ZSetZRANGE

func (c *RedisClient) ZSetZRANGE(key string, start, stop int64) ([]interface{}, error)

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

func (*RedisClient) ZSetZRANGEALL

func (c *RedisClient) ZSetZRANGEALL(key string) ([]interface{}, error)

ZSetZRANGEALL ZRANGE 获取ZSet value 返回集合 有序集成员的列表。

func (*RedisClient) ZSetZRANGEBYSCORE

func (c *RedisClient) ZSetZRANGEBYSCORE(key string, min, max, offset, count int64) ([]interface{}, error)

ZSetZRANGEBYSCORE ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count] 返回有序集 key 中,所有 score 值介于 min 和 max 之间(包括等于 min 或 max )的成员。有序集成员按 score 值递增(从小到大)次序排列。 具有相同 score 值的成员按字典序(lexicographical order)来排列(该属性是有序集提供的,不需要额外的计算)。 可选的 LIMIT 参数指定返回结果的数量及区间(就像SQL中的 SELECT LIMIT offset, count ),注意当 offset 很大时, 定位 offset 的操作可能需要遍历整个有序集,此过程最坏复杂度为 O(N) 时间。 可选的 WITHSCORES 参数决定结果集是单单返回有序集的成员,还是将有序集成员及其 score 值一起返回。 区间及无限 min 和 max 可以是 -inf 和 +inf ,这样一来,你就可以在不知道有序集的最低和最高 score 值的情况下,使用 ZRANGEBYSCORE 这类命令。 默认情况下,区间的取值使用闭区间 (小于等于或大于等于),你也可以通过给参数前增加 ( 符号来使用可选的开区间 (小于或大于)。

func (*RedisClient) ZSetZRANGEBYSCOREALL

func (c *RedisClient) ZSetZRANGEBYSCOREALL(key string) ([]interface{}, error)

func (*RedisClient) ZSetZRANK

func (c *RedisClient) ZSetZRANK(key string, member interface{}) (int64, error)

ZSetZRANK ZRANK key member 返回有序集 key 中成员 member 的排名。其中有序集成员按 score 值递增(从小到大)顺序排列。 排名以 0 为底,也就是说, score 值最小的成员排名为 0 。

func (*RedisClient) ZSetZREM

func (c *RedisClient) ZSetZREM(key string, member []interface{}) error

ZSetZREM ZREM key member [member ...] 移除有序集 key 中的一个或多个成员,不存在的成员将被忽略。

func (*RedisClient) ZSetZREMRANGEBYRANK

func (c *RedisClient) ZSetZREMRANGEBYRANK(key string, start, stop int64) error

ZSetZREMRANGEBYRANK ZREMRANGEBYRANK key start stop 移除有序集 key 中,指定排名(rank)区间内的所有成员。 区间分别以下标参数 start 和 stop 指出,包含 start 和 stop 在内。

func (*RedisClient) ZSetZREMRANGEBYSCORE

func (c *RedisClient) ZSetZREMRANGEBYSCORE(key string, min, max int64) error

ZSetZREMRANGEBYSCORE ZREMRANGEBYSCORE key min max 移除有序集 key 中,所有 score 值介于 min 和 max 之间(包括等于 min 或 max )的成员。

func (*RedisClient) ZSetZREVRANGE

func (c *RedisClient) ZSetZREVRANGE(key string, start, stop int64) ([]interface{}, error)

ZSetZREVRANGE ZREVRANGE key start stop [WITHSCORES] 返回有序集 key 中,指定区间内的成员。 其中成员的位置按 score 值递减(从大到小)来排列。 具有相同 score 值的成员按字典序的逆序(reverse lexicographical order)排列。

func (*RedisClient) ZSetZREVRANGEBYSCORE

func (c *RedisClient) ZSetZREVRANGEBYSCORE(key string, min, max, offset, count int64) ([]interface{}, error)

func (*RedisClient) ZSetZREVRANGEBYSCOREALL

func (c *RedisClient) ZSetZREVRANGEBYSCOREALL(key string) ([]interface{}, error)

func (*RedisClient) ZSetZREVRANK

func (c *RedisClient) ZSetZREVRANK(key string, member interface{}) (int64, error)

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

func (*RedisClient) ZSetZSCORE

func (c *RedisClient) ZSetZSCORE(key string, member interface{}) (string, error)

ZSetZSCORE ZSCORE key member 返回有序集 key 中,成员 member 的 score

func (*RedisClient) ZSetZUNIONSTORE

func (c *RedisClient) ZSetZUNIONSTORE()

ZSetZUNIONSTORE ZUNIONSTORE destination numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX] 计算给定的一个或多个有序集的并集,其中给定 key 的数量必须以 numkeys 参数指定,并将该并集(结果集)储存到 destination 。

type RedisPool

type RedisPool struct {
	Pool *redis.Pool
}
var ClientPool *RedisPool = &RedisPool{}

ClientPool 全局redis 连接池

Jump to

Keyboard shortcuts

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