Documentation
¶
Index ¶
- Constants
- Variables
- func Command(dbName string, coding ECoding, command string, args ...interface{}) *reply
- func Connector(dbName string) redis.Conn
- func Decode(encoding ECoding, b []byte, v interface{}) error
- func Encode(encoding ECoding, v interface{}) (interface{}, error)
- func Exec(sends ...sender) *reply
- func Install(confs []*Config) ctl.IControler
- func Pipe(sends ...sender) error
- func RegistCoder(name ECoding, coder Coder)
- func Reply(rep interface{}, err error, coding ECoding, fullCmd string) *reply
- func Sender(k IKeyer, send func(), rep ...func(rps []*Resp)) sender
- type Bit
- type ClusterPool
- type Coder
- type Config
- type ECoding
- type EMode
- type ESetMode
- type ESort
- type Hash
- func (k *Hash) Del(fields ...interface{}) *reply
- func (k *Hash) Exists(field interface{}) *reply
- func (k *Hash) Fields() *reply
- func (k *Hash) Get(field interface{}) *reply
- func (k *Hash) GetAll() *reply
- func (k *Hash) GetMap(fields ...interface{}) *reply
- func (k *Hash) GetStruct() *reply
- func (k *Hash) Getm(fields ...interface{}) *reply
- func (k *Hash) IncrBy(field interface{}, increment interface{}) *reply
- func (k *Hash) IncrByFloat(field interface{}, increment float64) *reply
- func (k *Hash) Len() *reply
- func (k *Hash) Set(field, value interface{}, noExist ...bool) *reply
- func (k *Hash) SetMap(mp map[interface{}]interface{}) *reply
- func (k *Hash) SetStruct(obj interface{}) *reply
- func (k *Hash) Values() *reply
- type IContrler
- type IKeyer
- type IMutexer
- type IPooler
- type Key
- func (k *Key) Clusted() bool
- func (k *Key) Delete(keys ...string) *reply
- func (k *Key) Dump() *reply
- func (k *Key) Existed() *reply
- func (k *Key) Expire(seconds int64) *reply
- func (k *Key) ExpireAt(timestamp int64) *reply
- func (k *Key) Keys() *reply
- func (k *Key) Move(db int64) *reply
- func (k *Key) PExpire(millisecond int64) *reply
- func (k *Key) PExpireAt(timestamp_ms int64) *reply
- func (k *Key) PTTL() *reply
- func (k *Key) Persist() *reply
- func (k *Key) RandomKey() *reply
- func (k *Key) Refresh(ttl ...time.Duration) *reply
- func (k *Key) Rename(newKey string) *reply
- func (k *Key) RenameNX(newKey string) *reply
- func (k *Key) Restore(ttlMS, serializedValue interface{}) *reply
- func (k *Key) Select(db int64) *reply
- func (k *Key) TTL() *reply
- func (k *Key) Type() *reply
- func (k *Key) Valid() bool
- type List
- func (k *List) BLpop(timeout interface{}) *reply
- func (k *List) BRpop(timeout interface{}) *reply
- func (k *List) BRpoplpush(key, source, destination string, timeout interface{}) *reply
- func (k *List) LIndex(index int) *reply
- func (k *List) LInsert(position, pivot, value string) *reply
- func (k *List) LPop() *reply
- func (k *List) LPush(value interface{}, whenListExist ...bool) *reply
- func (k *List) LRange(start, stop interface{}) *reply
- func (k *List) LRem(count, value interface{}) *reply
- func (k *List) LSet(index, value interface{}) *reply
- func (k *List) LTrim(start, stop interface{}) *reply
- func (k *List) RPop() *reply
- func (k *List) RPoplpush(key, source, destination string) *reply
- func (k *List) RPush(value interface{}, whenListExist ...bool) *reply
- type NormalPool
- type Resp
- type Set
- func (k *Set) Add(members ...interface{}) *reply
- func (k *Set) Count() *reply
- func (k *Set) Diff(keys []string) *reply
- func (k *Set) DiffStore(destinationKey string, keys []string) *reply
- func (k *Set) Inter(keys []string) *reply
- func (k *Set) InterStore(destinationKey string, keys []string) *reply
- func (k *Set) IsMember(member interface{}) *reply
- func (k *Set) Members() *reply
- func (k *Set) Move(sourceKey, destinationKey string, member interface{}) *reply
- func (k *Set) Pop() *reply
- func (k *Set) RandMember(count ...int64) *reply
- func (k *Set) Rem(members ...interface{}) *reply
- func (k *Set) Union(keys []string) *reply
- func (k *Set) UnionStore(destinationKey string, keys []string) *reply
- type String
- func (k *String) Append(value interface{}) *reply
- func (k *String) Decr() *reply
- func (k *String) DecrBy(increment int64) *reply
- func (k *String) Get() *reply
- func (k *String) GetRange(start, end int64) *reply
- func (k *String) GetSet(value interface{}) *reply
- func (k *String) Getm(keys []string) *reply
- func (k *String) Getms(args [][]interface{}) *reply
- func (k *String) Incr() *reply
- func (k *String) IncrBy(increment int64) *reply
- func (k *String) IncrByFloat(increment float64) *reply
- func (k *String) LuaIncrBy(amount int) *reply
- func (k *String) Set(mode ESetMode, value interface{}, expire ...time.Duration) *reply
- func (k *String) SetRange(value interface{}, offset int64) *reply
- func (k *String) Setm(kv map[string]interface{}) *reply
- func (k *String) SetmNx(kv map[string]interface{}) *reply
- func (k *String) Setms(args [][]interface{}, vals []interface{}) *reply
- func (k *String) Upd(mode ESetMode, value interface{}) *reply
- type Zset
- func (k *Zset) Add(mode ESetMode, member, score interface{}) *reply
- func (k *Zset) AddArr(ar ...interface{}) *reply
- func (k *Zset) AddMap(mp map[interface{}]interface{}) *reply
- func (k *Zset) Card() *reply
- func (k *Zset) Count(min, max interface{}) *reply
- func (k *Zset) Del(members ...interface{}) *reply
- func (k *Zset) DelRange(min_start, max_stop interface{}, byScore ...bool) *reply
- func (k *Zset) Incr(member, increment interface{}) *reply
- func (k *Zset) Range(start, stop interface{}, withScore ...bool) *reply
- func (k *Zset) Rangebyscore(min, max interface{}, withScore ...bool) *reply
- func (k *Zset) Rank(e ESort, member interface{}) *reply
- func (k *Zset) Revrange(start, stop interface{}, withScore ...bool) *reply
- func (k *Zset) Revrangebyscore(min, max interface{}, withScore ...bool) *reply
- func (k *Zset) Score(member interface{}) *reply
- func (k *Zset) Topn(e ESort, start, stopN int, withScore ...bool) *reply
- func (k *Zset) TopnByScore(e ESort, min, max interface{}, withScore ...bool) *reply
Constants ¶
const ( C_CONN_IDLE_TIMEOVER = 5 * time.Minute // 空闲多久回收连接 C_INF_MAX = "+inf" // 正无穷 C_INF_MIN = "-inf" // 负无穷 C_DB_CLUSTER = "_cluster_" // 如果使用集群部署,Config只能有一个且name='_cluster_' C_TICK_OUTPUT_STAT_INTERVAL = 1 * time.Minute // 一分钟统计输出一次命令调用情况 )
==================== 常量定义
Variables ¶
var ( ErrNil = redis.ErrNil ErrNameRepeated = errors.New("ErrConfigNameRepeated") ErrInvalidTTL = errors.New("ErrInvalidTTL") ErrZsetAddArrInvalid = errors.New("ErrZsetAddArrInvalid") ErrHashGetMapResultMismatch = errors.New("ErrHashGetMapResultMismatch") ErrInvalidCoding = errors.New("ErrInvalidCoding") )
==================== 错误定义
Functions ¶
Types ¶
type ClusterPool ¶
func (*ClusterPool) Mode ¶
func (*ClusterPool) Mode() EMode
type Coder ¶
type Coder struct {
Encoder func(v interface{}) ([]byte, error)
Decoder func(data []byte, v interface{}) error
}
> 编码器接口
type Config ¶
type Config struct {
Name string `json:"name"` // 常量 C_DB_CLUSTER 是唯一的
Addr string `json:"addr"`
DbIdx int64 `json:"index"` // 0-15
Passwd string `json:"passwd"`
MaxIdle int64 `json:"max_idle"`
MaxActive int64 `json:"max_active"`
Wait bool `json:"wait"` // 如果当前的连接已经达到MaxActive值的话, 如果true=>线程将会等待, 否则直接报错.
}
> Redis配置
type ESetMode ¶
type ESetMode int //
> 值的设置模式
const ( ESet_Update ESetMode // 正常设置 ESet_WhenExist // 当值存在时才进行设置 ESet_WhenNoExist // 当值不存在时才进行设置 ESet_WhenValueLT // 当新的分值比当前分值小才设置,不存在则新增 ESet_WhenValueGT // 当新的分值比当前分值大才设置,不存在则新增 )
type Hash ¶
type Hash struct{ Key }
func (*Hash) GetMap ¶
func (k *Hash) GetMap(fields ...interface{}) *reply
Hash.GetMap 返回多个字段以及值(reply.HashMap)
func (*Hash) GetStruct ¶
func (k *Hash) GetStruct() *reply
Hash.GetStruct 获取对象的字段及值(reply.ScanStruct)
func (*Hash) Getm ¶
func (k *Hash) Getm(fields ...interface{}) *reply
Hash.Getm 返回多个字段的值(reply.Xxxs)
func (*Hash) IncrBy ¶
func (k *Hash) IncrBy(field interface{}, increment interface{}) *reply
Hash.IncrBy 为指定字段值增加
func (*Hash) IncrByFloat ¶
Hash.IncrByFloat 为指定字段值增加浮点数
func (*Hash) SetMap ¶
func (k *Hash) SetMap(mp map[interface{}]interface{}) *reply
Hash.SetMap 设置多个字段及值(map[field]value)
type IContrler ¶
type IContrler interface {
ctl.IControler
// 获取某个连接池对象
Use(name string) IPooler
}
控制器接口
var (
Ctl IContrler // 默认Cache控制器
)
func Controller ¶
type Key ¶
type Key struct {
DB string // 哪个db中(表示哪个db索引)
K string // Key的名称(建议格式:'basexxx:param1=%d,param2=%s,....')
Coding ECoding // 编码模式
Ttl time.Duration // 存活时间ms(仅作存储,需要自行调用k.Overdue())
// contains filtered or unexported fields
}
type List ¶
func (*List) BRpoplpush ¶
List.BRpoplpush 阻塞并弹出尾元素,将弹出元素插入另一列表的开头
func (*List) LInsert ¶
List.LInsert 将元素插入指定位置 position:BEFORE|AFTER,当 pivot 不存在于列表 key 时,不执行任何操作。当 key 不存在时, key 被视为空列表,不执行任何操作。
func (*List) LRange ¶
func (k *List) LRange(start, stop interface{}) *reply
List.LRange 获取指定区间的元素(全部:(0,-1))
func (*List) LRem ¶
func (k *List) LRem(count, value interface{}) *reply
List.LRem 移除元素,count = 0 : 移除表中所有与 value 相等的值,count!=0,移除与 value 相等的元素,数量为 count的绝对值
func (*List) LTrim ¶
func (k *List) LTrim(start, stop interface{}) *reply
List.LTrim 列表裁剪,让列表只保留指定区间内的元素,不在指定区间之内的元素都将被删除。-1 表示尾部
type Set ¶
type Set struct{ Key }
func (*Set) InterStore ¶
Set.InterStore 将keys的集合的并集 写入到 destinationKey中
func (*Set) UnionStore ¶
Set.UnionStore 将 keys 的集合的并集 写入到 destinationKey 中
type String ¶
type String struct{ Key }
func (*String) Getms ¶
func (k *String) Getms(args [][]interface{}) *reply
String.Getms 返回多个key的值(以k.K作为fmt模块)
func (*String) IncrByFloat ¶
String.IncrByFloat 增加一个浮点值(并返回增加之后的值)
type Zset ¶
type Zset struct{ Key }
func (*Zset) AddArr ¶
func (k *Zset) AddArr(ar ...interface{}) *reply
Zset.AddArr 添加|更新多元素 member1 score1, ... memberN,scoreN
func (*Zset) AddMap ¶
func (k *Zset) AddMap(mp map[interface{}]interface{}) *reply
Zset.AddMap 添加|更新多元素 map[member]score
func (*Zset) Count ¶
func (k *Zset) Count(min, max interface{}) *reply
Zset.Count 返回集合两个分数间的元素数(min<=score<=max)
func (*Zset) Rangebyscore ¶
Zset.Rangebyscore 通过分数返回指定区间内的元素([min, max])
func (*Zset) Revrangebyscore ¶
Zset.Revrangebyscore 倒序通过分数返回指定区间内的元素([min, max])
func (*Zset) TopnByScore ¶
Zset.Topn 返回Top排行元素