Documentation ¶
Index ¶
- Constants
- Variables
- type BatchReply
- type BatchReq
- type RedisCluster
- type RedisClusterClient
- func (r *RedisClusterClient) Close()
- func (r *RedisClusterClient) Del(key string) (int64, error)
- func (r *RedisClusterClient) Eval(script string, keys []string, args []interface{}) (interface{}, error)
- func (r *RedisClusterClient) EvalSha(scriptSha string, keys []string, args []interface{}) (interface{}, error)
- func (r *RedisClusterClient) Exist(key string) (bool, error)
- func (r *RedisClusterClient) Expire(key string, expiration time.Duration) (bool, error)
- func (r *RedisClusterClient) Get(key string) (string, error)
- func (r *RedisClusterClient) HGet(key string, field string) (string, error)
- func (r *RedisClusterClient) HGetAll(key string) (map[string]string, error)
- func (r *RedisClusterClient) HIncrBy(key string, field string, value int64) (int64, error)
- func (r *RedisClusterClient) HLen(key string) (int64, error)
- func (r *RedisClusterClient) HMDel(key string, fields []string) (int64, error)
- func (r *RedisClusterClient) HMGet(key string, fields []string) ([]interface{}, error)
- func (r *RedisClusterClient) HMSet(key string, fields map[string]string) (bool, error)
- func (r *RedisClusterClient) HScan(key string, count int64) (map[string]string, error)
- func (r *RedisClusterClient) HSet(key string, field string, value string) (bool, error)
- func (r *RedisClusterClient) HSetNx(key string, field string, value string) (bool, error)
- func (r *RedisClusterClient) IncrBy(key string, value int64) (int64, error)
- func (r *RedisClusterClient) LIndex(key string, index int64) (string, error)
- func (r *RedisClusterClient) LPop(key string) (string, error)
- func (r *RedisClusterClient) LPush(key string, value string) (int64, error)
- func (r *RedisClusterClient) MDel(keys []string) (map[string]bool, error)
- func (r *RedisClusterClient) MDel2(keys []string) (map[string]bool, error)
- func (r *RedisClusterClient) MGet(keys []string) ([]interface{}, error)
- func (r *RedisClusterClient) MGet2(keys []string) ([]interface{}, error)
- func (r *RedisClusterClient) MSet(kvs map[string]string, expire time.Duration) (map[string]bool, error)
- func (r *RedisClusterClient) MSet2(kvs map[string]string, expire time.Duration) (map[string]bool, error)
- func (r *RedisClusterClient) PExpire(key string, expiration time.Duration) (bool, error)
- func (r *RedisClusterClient) PTtl(key string) (time.Duration, error)
- func (r *RedisClusterClient) RPush(key string, value string) (int64, error)
- func (r *RedisClusterClient) SAdd(key string, members []interface{}) (int64, error)
- func (r *RedisClusterClient) SPop(key string) (string, error)
- func (r *RedisClusterClient) Set(key string, value string, expire time.Duration) (string, error)
- func (r *RedisClusterClient) SetBit(key string, offset int64, value int) (int64, error)
- func (r *RedisClusterClient) SetNX(key string, value string, expire time.Duration) (bool, error)
- func (r *RedisClusterClient) Start() error
- func (r *RedisClusterClient) ZAdd(key string, members []redis.Z) (int64, error)
- func (r *RedisClusterClient) ZRange(key string, start, stop int64) ([]string, error)
- func (r *RedisClusterClient) ZRangeByScoreWithScores(key string, min, max string, offset, limit int64) ([]*ZSetResult, error)
- func (r *RedisClusterClient) ZRem(key string, members ...interface{}) (int64, error)
- func (r *RedisClusterClient) ZRemRangeByRank(key string, start, stop int64) (int64, error)
- func (r *RedisClusterClient) ZRemRangeByScore(key string, min, max string) (int64, error)
- func (r *RedisClusterClient) ZRevRange(key string, start, stop int64) ([]string, error)
- func (r *RedisClusterClient) ZRevRangeByScoreWithScores(key string, min, max string, offset, limit int64) ([]*ZSetResult, error)
- type RedisClusterConf
- type RedisClusterCustomError
- type RedisConfig
- type RedisPool
- type RedisPoolClient
- func (p *RedisPoolClient) ActiveCount() int
- func (p *RedisPoolClient) BatchDo(commandName string, req []*BatchReq) (reply []*BatchReply)
- func (p *RedisPoolClient) Close()
- func (p *RedisPoolClient) Del(key string) (err error)
- func (p *RedisPoolClient) Do(commandName string, args ...interface{}) (reply interface{}, err error)
- func (p *RedisPoolClient) Exists(key string) (bool, error)
- func (p *RedisPoolClient) Expire(key string, time int) (int, error)
- func (p *RedisPoolClient) Get(key string) (ret string, errRet error)
- func (p *RedisPoolClient) HDel(key, field string) (err error)
- func (p *RedisPoolClient) HGet(key string, field string) (string, error)
- func (p *RedisPoolClient) HGetAll(key string) (ret map[string]string, err error)
- func (p *RedisPoolClient) HIncrBy(key, field string, val int64) (int64, error)
- func (p *RedisPoolClient) HLen(key string) (int64, error)
- func (p *RedisPoolClient) HMDel(key string, values []string) (int64, error)
- func (p *RedisPoolClient) HMGet(key string, values []string) ([]string, error)
- func (p *RedisPoolClient) HScan(key string, count int64) (ret map[string]string, err error)
- func (p *RedisPoolClient) HSet(key string, field string, value string) (err error)
- func (p *RedisPoolClient) Incr(key string) (int, error)
- func (p *RedisPoolClient) IncrBy(key string, val int64) (int64, error)
- func (p *RedisPoolClient) LIndex(key string, index int64) (string, error)
- func (p *RedisPoolClient) LPop(key string) (string, error)
- func (p *RedisPoolClient) LPush(key string, val string) (int64, error)
- func (p *RedisPoolClient) MGet(keys []string) (ret []interface{}, errRet error)
- func (p *RedisPoolClient) RPush(key, val string) (int64, error)
- func (p *RedisPoolClient) SAdd(key string, vals []string) error
- func (p *RedisPoolClient) SPop(key string) (string, error)
- func (p *RedisPoolClient) Set(key, value string) (err error)
- func (p *RedisPoolClient) SetEx(key string, expire int64, value string) (err error)
- func (p *RedisPoolClient) SetNX(key, value string, expire int) (interface{}, error)
- func (p *RedisPoolClient) Start() error
- func (p *RedisPoolClient) ZAdd(key string, score int64, val string) error
- func (p *RedisPoolClient) ZRange(key string, start int64, end int64) ([]string, error)
- func (p *RedisPoolClient) ZRemByScore(key string, start string, end string) error
- type ZSetResult
Constants ¶
const ( MaxGoroutinePoolSize = 5 MGetCostMax = 60 MSetCostMax = 60 MDelCostMax = 60 RedisClusterCommonCostMax = 20 RedisClusterCmdNormal = "redis_cluster_cmd_normal" RedisClusterCmd = "redis_cluster_cmd_%v" RedisClusterCmdSlowCount = "redis_cluster_%v_slow_count" RedisClusterNormalSlowCount = "redis_cluster_common_slow_count" )
const ( DefaultMaxActive = 500 DefaultMaxIdle = 8 DefaultIdleTimeout = 300 DefaultRetryTimes = 3 DefaultConnTimeout = 400 DefaultReadTimeout = 700 DefaultWriteTimeout = 500 RedisPoolCommonCostMax = 20 RedisPoolCmdNormal = "redis_pool_cmd_normal" RedisPoolCmd = "redis_pool_cmd_%v" RedisPoolCmdSlowCount = "redis_pool_%v_slow_count" RedisPoolNormalSlowCount = "redis_pool_common_slow_count" )
Variables ¶
var ErrNil = errors.New("redis: nil returned")
Functions ¶
This section is empty.
Types ¶
type BatchReply ¶
type RedisCluster ¶
type RedisCluster struct {
// contains filtered or unexported fields
}
type RedisClusterClient ¶ added in v1.6.7
type RedisClusterClient struct { RedisConfig *RedisClusterConf `inject:"redisClusterConfig" canNil:"true"` RedisConf *ini.File `inject:"redisClusterConf" canNil:"true"` RedisConfPath string `inject:"redisClusterConfPath" canNil:"true"` ClusterName string `inject:"clusterName" canNil:"true"` // contains filtered or unexported fields }
func (*RedisClusterClient) Close ¶ added in v1.6.7
func (r *RedisClusterClient) Close()
func (*RedisClusterClient) Del ¶ added in v1.6.7
func (r *RedisClusterClient) Del(key string) (int64, error)
* 1. 若正常, 返回 (num,nil), num为删除的key个数 2. 若异常, 返回 (0,error)
func (*RedisClusterClient) Eval ¶ added in v1.6.7
func (r *RedisClusterClient) Eval(script string, keys []string, args []interface{}) (interface{}, error)
func (*RedisClusterClient) EvalSha ¶ added in v1.6.7
func (r *RedisClusterClient) EvalSha(scriptSha string, keys []string, args []interface{}) (interface{}, error)
func (*RedisClusterClient) Exist ¶ added in v1.6.7
func (r *RedisClusterClient) Exist(key string) (bool, error)
func (*RedisClusterClient) Expire ¶ added in v1.6.7
*
- 若正常, 返回 (true,nil)
- 若异常, 返回 (false,error) key不存在返回(false,nil)
func (*RedisClusterClient) Get ¶ added in v1.6.7
func (r *RedisClusterClient) Get(key string) (string, error)
* 1. 若key存在且成功, 返回(string,nil) 2. 若key不存在且成功, 返回("",redisCluster.ErrNil) 3. 若异常, 返回("",error)
func (*RedisClusterClient) HGet ¶ added in v1.6.7
func (r *RedisClusterClient) HGet(key string, field string) (string, error)
* 1. 异常, 返回 ("",error) 2. 正常, 但key不存在或者field不存在, 返回 ("",redisCluster.ErrNil) 3. 正常, 且key存在, filed存在, 返回 (string, nil)
func (*RedisClusterClient) HGetAll ¶ added in v1.6.7
func (r *RedisClusterClient) HGetAll(key string) (map[string]string, error)
* 1. 若异常, 返回 (nil, error) 2. 若正常, 返回 (map[string]string, nil)
func (*RedisClusterClient) HLen ¶ added in v1.6.7
func (r *RedisClusterClient) HLen(key string) (int64, error)
func (*RedisClusterClient) HMDel ¶ added in v1.6.7
func (r *RedisClusterClient) HMDel(key string, fields []string) (int64, error)
func (*RedisClusterClient) HMGet ¶ added in v1.6.7
func (r *RedisClusterClient) HMGet(key string, fields []string) ([]interface{}, error)
*
- 异常, 返回 (nil, error)
- 正常, 返回 ([]interface{}, nil), 其中slice里的值顺序与fields一一对应, 对于不存在的field, 对应值为nil 例如: HMGet("key", []string{"field1","field2","field3"}) 返回值: []interface{}{ "value1", //field1的值 nil, //field2不存在 "value3" //field3的值 },nil 备注: 若key不存在, slice里的所有值都为nil
func (*RedisClusterClient) HMSet ¶ added in v1.6.7
* 1. 若异常, 返回 (false, error) 2. 若正常, 返回 (true, nil)
func (*RedisClusterClient) HScan ¶ added in v1.6.7
* 1. 若异常, 返回 (nil, error) 2. 若正常, 返回 (map[string]string, nil)
Notice: 这个函数并不能严格的限制返回count个,简单测试看起来主要和redis用的存储结构有关。
Hmap redis在存储的时候如果数据比较少(看文章是512)会使用ziplist,测试了下,在ziplist存储的状态下,会都返回,count不生效 如果数据超过512之后会使用hmap来存储,这时基本就是准确的了。所以这个函数只能保证返回 >= count
func (*RedisClusterClient) HSet ¶ added in v1.6.7
* 1. 若异常, 返回 (false, error) 2. 若正常, 返回 (bool, nil), 其中true: field在hash中不存在且新增成功; false: field已在hash中存在且更新成功.
func (*RedisClusterClient) HSetNx ¶ added in v1.6.7
* 1. 若异常, 返回 (false, error) 2. 若正常, 返回 (bool, nil), 其中true: field在hash中不存在且新增成功; false: field已在hash中存在, 不做更新.
func (*RedisClusterClient) IncrBy ¶ added in v1.6.7
func (r *RedisClusterClient) IncrBy(key string, value int64) (int64, error)
func (*RedisClusterClient) LIndex ¶ added in v1.6.7
func (r *RedisClusterClient) LIndex(key string, index int64) (string, error)
func (*RedisClusterClient) LPop ¶ added in v1.6.7
func (r *RedisClusterClient) LPop(key string) (string, error)
func (*RedisClusterClient) LPush ¶ added in v1.6.7
func (r *RedisClusterClient) LPush(key string, value string) (int64, error)
func (*RedisClusterClient) MDel ¶ added in v1.6.7
func (r *RedisClusterClient) MDel(keys []string) (map[string]bool, error)
func (*RedisClusterClient) MDel2 ¶ added in v1.6.7
func (r *RedisClusterClient) MDel2(keys []string) (map[string]bool, error)
* 1. err!=nil, 在err!=nil的情况下,若ret为空,则表示都失败了 2. ret标识每个key对应的成功与否,true成功,false失败 有如下情况: ret==nil, err!=nil: 全部失败 ret!=nil, err!=nil: 部分失败, ret会包含所有key的操作结果 ret!=nil, err==nil: 全部成功, ret会包含所有key的操作结果
func (*RedisClusterClient) MGet ¶ added in v1.6.7
func (r *RedisClusterClient) MGet(keys []string) ([]interface{}, error)
*
- 若有异常, 返回 (nil,error)
- 若正常, 返回 ([]interface{}{...},nil), 其中结果里的value顺序与keys的顺序一一对应, 若某个key不存在, 所对应value为nil 例如 MGet([]string{"key1","key2","key3"}), 假设key2不存在, 返回数据如下: []interface{}{ "value1", //key1的值 nil, //不存在 "value3", //key3的值 }, nil
func (*RedisClusterClient) MGet2 ¶ added in v1.6.7
func (r *RedisClusterClient) MGet2(keys []string) ([]interface{}, error)
*
- 若有异常, 返回 (nil,error)
- 若正常, 返回 ([]interface{}{...},nil), 其中结果里的value顺序与keys的顺序一一对应, 若某个key不存在, 所对应value为nil 例如 MGet([]string{"key1","key2","key3"}), 假设key2不存在, 返回数据如下: []interface{}{ "value1", //key1的值 nil, //不存在 "value3", //key3的值 }, nil
func (*RedisClusterClient) MSet2 ¶ added in v1.6.7
func (r *RedisClusterClient) MSet2(kvs map[string]string, expire time.Duration) (map[string]bool, error)
* 1. err!=nil, 在err!=nil的情况下,若ret为空,则表示都失败了 2. ret标识每个key对应的成功与否,true成功,false失败 有如下情况: ret==nil, err!=nil: 全部失败 ret!=nil, err!=nil: 部分失败, ret里会包含所有key的操作结果 ret!=nil, err==nil: 全部成功, ret里会包含所有key的操作结果
备注: expire为0表示key不过期
func (*RedisClusterClient) PExpire ¶ added in v1.6.7
*
- 若正常, 返回 (true,nil)
- 若异常, 返回 (false,error) key不存在返回(false,nil)
func (*RedisClusterClient) PTtl ¶ added in v1.6.7
func (r *RedisClusterClient) PTtl(key string) (time.Duration, error)
*
- 若正常, 返回 (true,nil)
- 若异常, 返回 (false,error) key不存在返回(false,nil)
func (*RedisClusterClient) RPush ¶ added in v1.6.7
func (r *RedisClusterClient) RPush(key string, value string) (int64, error)
func (*RedisClusterClient) SAdd ¶ added in v1.6.7
func (r *RedisClusterClient) SAdd(key string, members []interface{}) (int64, error)
func (*RedisClusterClient) SPop ¶ added in v1.6.7
func (r *RedisClusterClient) SPop(key string) (string, error)
func (*RedisClusterClient) Set ¶ added in v1.6.7
* 1. 若expire为0, 表示不设置过期 2. 若设置成功, 返回("ok",nil) 3. 若异常, 返回("",error)
func (*RedisClusterClient) SetNX ¶ added in v1.6.7
* 1. 若expire为0, 表示不设置过期 2. 如果 err 不为空, 则发生异常; 3. 在 err 为空的情况下, bool=false 表示key已存在set无效, bool=true表示key不存在set成功 https://redis.io/commands/setnx
func (*RedisClusterClient) Start ¶ added in v1.6.7
func (r *RedisClusterClient) Start() error
func (*RedisClusterClient) ZRange ¶ added in v1.6.7
func (r *RedisClusterClient) ZRange(key string, start, stop int64) ([]string, error)
func (*RedisClusterClient) ZRangeByScoreWithScores ¶ added in v1.6.7
func (r *RedisClusterClient) ZRangeByScoreWithScores(key string, min, max string, offset, limit int64) ([]*ZSetResult, error)
func (*RedisClusterClient) ZRem ¶ added in v1.6.7
func (r *RedisClusterClient) ZRem(key string, members ...interface{}) (int64, error)
func (*RedisClusterClient) ZRemRangeByRank ¶ added in v1.6.7
func (r *RedisClusterClient) ZRemRangeByRank(key string, start, stop int64) (int64, error)
func (*RedisClusterClient) ZRemRangeByScore ¶ added in v1.6.7
func (r *RedisClusterClient) ZRemRangeByScore(key string, min, max string) (int64, error)
func (*RedisClusterClient) ZRevRange ¶ added in v1.6.7
func (r *RedisClusterClient) ZRevRange(key string, start, stop int64) ([]string, error)
func (*RedisClusterClient) ZRevRangeByScoreWithScores ¶ added in v1.6.7
func (r *RedisClusterClient) ZRevRangeByScoreWithScores(key string, min, max string, offset, limit int64) ([]*ZSetResult, error)
type RedisClusterConf ¶
type RedisClusterConf struct { //cluster name ClusterName string //server address Addrs []string //conn/read/write timeout, 单位: 毫秒, 0表示默认值(1秒), -1表示不超时 DialTimeout int64 ReadTimeout int64 WriteTimeout int64 //pool config //每个redis节点会起一个连接池, 该poolSize表示每个redis节点的最大连接数 PoolSize int //从连接池获取可用连接的超时, 单位: 毫秒, 0表示默认值(1秒), -1表示不超时 PoolTimeout int64 //最小空闲连接数 MinIdleConns int //空闲连接可被回收的判断阈值, 单位: 秒 IdleTimeout int64 //空闲连接检查频率, 单位: 秒, 0表示默认值(30分钟), -1表示不做检查 IdleCheckFrequency int64 //当访问的key不在某节点或者某节点有异常, 会做move(redirect)操作, 该参数表示最大move操作次数, 0表示默认值(2次) MaxRedirects int Password string }
type RedisClusterCustomError ¶
type RedisClusterCustomError string
func (RedisClusterCustomError) Error ¶
func (e RedisClusterCustomError) Error() string
type RedisConfig ¶
type RedisPoolClient ¶ added in v1.6.7
type RedisPoolClient struct { RedisConfig *RedisConfig `inject:"redisConfig" canNil:"true"` RedisConf *ini.File `inject:"redisConf" canNil:"true"` RedisConfPath string `inject:"redisConfPath" canNil:"true"` PoolName string `inject:"poolName" canNil:"true"` // contains filtered or unexported fields }
func (*RedisPoolClient) ActiveCount ¶ added in v1.6.7
func (p *RedisPoolClient) ActiveCount() int
func (*RedisPoolClient) BatchDo ¶ added in v1.6.7
func (p *RedisPoolClient) BatchDo(commandName string, req []*BatchReq) (reply []*BatchReply)
func (*RedisPoolClient) Close ¶ added in v1.6.7
func (p *RedisPoolClient) Close()
func (*RedisPoolClient) Del ¶ added in v1.6.7
func (p *RedisPoolClient) Del(key string) (err error)
func (*RedisPoolClient) Do ¶ added in v1.6.7
func (p *RedisPoolClient) Do(commandName string, args ...interface{}) (reply interface{}, err error)
func (*RedisPoolClient) Exists ¶ added in v1.6.7
func (p *RedisPoolClient) Exists(key string) (bool, error)
func (*RedisPoolClient) Expire ¶ added in v1.6.7
func (p *RedisPoolClient) Expire(key string, time int) (int, error)
func (*RedisPoolClient) Get ¶ added in v1.6.7
func (p *RedisPoolClient) Get(key string) (ret string, errRet error)
* Redis get return string if exist
err = redis.ErrNil if not exist
func (*RedisPoolClient) HDel ¶ added in v1.6.7
func (p *RedisPoolClient) HDel(key, field string) (err error)
func (*RedisPoolClient) HGet ¶ added in v1.6.7
func (p *RedisPoolClient) HGet(key string, field string) (string, error)
func (*RedisPoolClient) HGetAll ¶ added in v1.6.7
func (p *RedisPoolClient) HGetAll(key string) (ret map[string]string, err error)
func (*RedisPoolClient) HIncrBy ¶ added in v1.6.7
func (p *RedisPoolClient) HIncrBy(key, field string, val int64) (int64, error)
func (*RedisPoolClient) HLen ¶ added in v1.6.7
func (p *RedisPoolClient) HLen(key string) (int64, error)
func (*RedisPoolClient) HMDel ¶ added in v1.6.7
func (p *RedisPoolClient) HMDel(key string, values []string) (int64, error)
func (*RedisPoolClient) HMGet ¶ added in v1.6.7
func (p *RedisPoolClient) HMGet(key string, values []string) ([]string, error)
func (*RedisPoolClient) HSet ¶ added in v1.6.7
func (p *RedisPoolClient) HSet(key string, field string, value string) (err error)
func (*RedisPoolClient) Incr ¶ added in v1.6.7
func (p *RedisPoolClient) Incr(key string) (int, error)
func (*RedisPoolClient) IncrBy ¶ added in v1.6.7
func (p *RedisPoolClient) IncrBy(key string, val int64) (int64, error)
func (*RedisPoolClient) LIndex ¶ added in v1.6.7
func (p *RedisPoolClient) LIndex(key string, index int64) (string, error)
func (*RedisPoolClient) LPop ¶ added in v1.6.7
func (p *RedisPoolClient) LPop(key string) (string, error)
func (*RedisPoolClient) LPush ¶ added in v1.6.7
func (p *RedisPoolClient) LPush(key string, val string) (int64, error)
func (*RedisPoolClient) MGet ¶ added in v1.6.7
func (p *RedisPoolClient) MGet(keys []string) (ret []interface{}, errRet error)
func (*RedisPoolClient) RPush ¶ added in v1.6.7
func (p *RedisPoolClient) RPush(key, val string) (int64, error)
func (*RedisPoolClient) SAdd ¶ added in v1.6.7
func (p *RedisPoolClient) SAdd(key string, vals []string) error
func (*RedisPoolClient) SPop ¶ added in v1.6.7
func (p *RedisPoolClient) SPop(key string) (string, error)
func (*RedisPoolClient) Set ¶ added in v1.6.7
func (p *RedisPoolClient) Set(key, value string) (err error)
func (*RedisPoolClient) SetEx ¶ added in v1.6.7
func (p *RedisPoolClient) SetEx(key string, expire int64, value string) (err error)
func (*RedisPoolClient) SetNX ¶ added in v1.6.7
func (p *RedisPoolClient) SetNX(key, value string, expire int) (interface{}, error)
func (*RedisPoolClient) Start ¶ added in v1.6.7
func (p *RedisPoolClient) Start() error
func (*RedisPoolClient) ZAdd ¶ added in v1.6.7
func (p *RedisPoolClient) ZAdd(key string, score int64, val string) error
func (*RedisPoolClient) ZRemByScore ¶ added in v1.6.7
func (p *RedisPoolClient) ZRemByScore(key string, start string, end string) error