Documentation ¶
Index ¶
- Constants
- Variables
- func ConnGet(conn redis.Conn, key string) (string, error)
- func ConnHDel(conn redis.Conn, args ...interface{}) (int64, error)
- func ConnHGet(conn redis.Conn, hashID string, field string) (string, error)
- func ConnSetEx(conn redis.Conn, key string, val string, timeOutSeconds int64) error
- func ConnZRangeByScorelimit(conn redis.Conn, field string, min int64, max int64, limit int) ([]string, error)
- type Client
- func (rc *Client) ActiveConnCount() int
- func (rc *Client) Close()
- func (rc *Client) Conn() redis.Conn
- func (rc *Client) DBSize() (int64, error)
- func (rc *Client) Del(key string) (int64, error)
- func (rc *Client) Expire(key string, timeOutSeconds int64) (int64, error)
- func (rc *Client) Get(key string) (string, error)
- func (rc *Client) HDel(args ...interface{}) (int64, error)
- func (rc *Client) HExist(hashID string, field string) (int, error)
- func (rc *Client) HGet(hashID string, field string) (string, error)
- func (rc *Client) HGetAll(hashID string) (map[string]string, error)
- func (rc *Client) HIncrBy(hashID string, field string, increment int) (int, error)
- func (rc *Client) HKeys(hashID string) ([]string, error)
- func (rc *Client) HLen(field string) (int, error)
- func (rc *Client) HSet(hashID string, field string, val string) error
- func (rc *Client) Init(cfg interface{}) error
- func (rc *Client) Keys(pattern string) ([]string, error)
- func (rc *Client) LLen(key string) (int, error)
- func (rc *Client) LPush(key string, value string) (int, error)
- func (rc *Client) LPushX(key string, value string) (int, error)
- func (rc *Client) LRange(key string, start int, stop int) ([]string, error)
- func (rc *Client) LRem(key string, count int, value string) (int, error)
- func (rc *Client) Ping() (string, error)
- func (rc *Client) RPop(key string) (string, error)
- func (rc *Client) RPush(key string, value string) (int, error)
- func (rc *Client) Run()
- func (rc *Client) SAdd(key string, member ...interface{}) (int, error)
- func (rc *Client) SCard(key string) (int, error)
- func (rc *Client) SMembers(key string) ([]string, error)
- func (rc *Client) SRandMember(key string, count int) ([]string, error)
- func (rc *Client) SRem(key string, member ...interface{}) (int, error)
- func (rc *Client) Set(key string, val string) error
- func (rc *Client) SetEx(key string, timeOutSeconds int64, val string) error
- func (rc *Client) SetWithExpire(key string, val interface{}, timeOutSeconds int64) (interface{}, error)
- func (rc *Client) SiSMembers(key string, member string) (int, error)
- func (rc *Client) ZAdd(field string, score int64, member string) (int64, error)
- func (rc *Client) ZCount(field string, min int64, max int64) (int64, error)
- func (rc *Client) ZIncrby(field string, incScore int, member string) (int64, error)
- func (rc *Client) ZRange(field string, start int64, stop int64) ([]string, error)
- func (rc *Client) ZRangeByScore(field string, min int64, max int64) ([]string, error)
- func (rc *Client) ZRangeByScorelimit(field string, min int64, max int64, limit int) ([]string, error)
- func (rc *Client) ZRem(field string, member string) (int64, error)
- func (rc *Client) ZRemRangeByScore(field string, min int64, max int64) (int64, error)
- func (rc *Client) ZRevRange(field string, start int64, stop int64) ([]string, error)
- func (rc *Client) ZRevRangeByScoreLimitWithscores(field string, max int64, min int64, offset int, count int) ([]string, error)
- func (rc *Client) ZRevRangeByScorelimit(field string, max int64, min int64, offset int, count int) ([]string, error)
- func (rc *Client) ZRevRangeWithscores(field string, start int64, stop int64) ([]string, error)
- func (rc *Client) ZRevRank(field string, member string) (int64, error)
- func (rc *Client) ZScore(field string, member string) (int64, error)
- type Config
- type Mutex
Constants ¶
const ( // Expiry 默认2秒的超时时间,当到达超时时强行释放锁。 Expiry = 3 * time.Second // Tries 如果获取锁失败,可重试的次数 Tries = 4 // Delay 重新获得锁的间隔(毫秒 Delay = 700 )
Variables ¶
var ( // ErrRedisMtxAcquire 申请分布式锁失败 ErrRedisMtxAcquire = errors.New("failed to acquire lock") // ErrRedisMtxInvaildToken 错误的传入token ErrRedisMtxInvaildToken = errors.New("acquire token is empty") )
var ( // ErrConfigConvert 配置转换失败 ErrConfigConvert = errors.New("Convert linker config") )
var GetDelScript = redis.NewScript(1, `
if redis.call("get", KEYS[1]) == ARGV[1] then
return redis.call("del", KEYS[1])
else
return 0
end`)
GetDelScript 将get 和del整合成原子操作
var IncrExpireScript = redis.NewScript(1, `
local current
current = redis.call("incr", KEYS[1])
if tonumber(current) == 1 then
redis.call("expire", KEYS[1], 1)
end`)
IncrExpireScript 将incr和expire指令整合成原子操作
Functions ¶
Types ¶
type Client ¶
type Client struct { Address string // contains filtered or unexported fields }
Client redis client
func (*Client) ActiveConnCount ¶ added in v1.1.10
ActiveConnCount 获取 redis 当前连接数量
func (*Client) SCard ¶
SCard returns cardinality of the set(count of elements). returns 0 when set does not exist
func (*Client) SRandMember ¶
SRandMember 如果命令执行时,只提供了 key 参数,那么返回集合中的一个随机元素。
func (*Client) SetWithExpire ¶
func (rc *Client) SetWithExpire(key string, val interface{}, timeOutSeconds int64) (interface{}, error)
SetWithExpire Set带ex
func (*Client) SiSMembers ¶
SiSMembers 判断 member 元素是否集合 key 的成员。
func (*Client) ZRangeByScore ¶
ZRangeByScore 返回有序集 key 中,所有 score 值介于 min 和 max 之间(包括等于 min 或 max )的成员。有序集成员按 score 值递增(从小到大)次序排列。
func (*Client) ZRangeByScorelimit ¶
func (rc *Client) ZRangeByScorelimit(field string, min int64, max int64, limit int) ([]string, error)
ZRangeByScorelimit 返回有序集
func (*Client) ZRemRangeByScore ¶
ZRemRangeByScore 移除有序集 key 中,所有 score 值介于 min 和 max 之间(包括等于 min 或 max )的成员
func (*Client) ZRevRangeByScoreLimitWithscores ¶
func (rc *Client) ZRevRangeByScoreLimitWithscores(field string, max int64, min int64, offset int, count int) ([]string, error)
ZRevRangeByScoreLimitWithscores 返回有序集 key 中, score 值介于 max 和 min 之间(默认包括等于 max 或 min )的所有的成员
func (*Client) ZRevRangeByScorelimit ¶
func (rc *Client) ZRevRangeByScorelimit(field string, max int64, min int64, offset int, count int) ([]string, error)
ZRevRangeByScorelimit 返回有序集 key 中, score 值介于 max 和 min 之间(默认包括等于 max 或 min )的所有的成员
func (*Client) ZRevRangeWithscores ¶
ZRevRangeWithscores 返回有序集 key 中,指定区间内的成员。
type Config ¶ added in v1.1.10
type Config struct { Address string //connection string, like "redis:// :password@10.0.1.11:6379/0" ReadTimeOut time.Duration // 连接的读取超时时间 WriteTimeOut time.Duration // 连接的写入超时时间 ConnectTimeOut time.Duration // 连接超时时间 MaxIdle int // 最大空闲连接数 MaxActive int // 最大连接数,当为0时没有连接数限制 IdleTimeout time.Duration // 闲置连接的超时时间, 设置小于服务器的超时时间 redis.conf : timeout }
Config 配置项