rds

package
v0.0.0-...-0cb7091 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2021 License: BSD-3-Clause-Clear Imports: 9 Imported by: 2

Documentation

Index

Constants

View Source
const (
	DEF_REDIS_IS_WAIT = true            // Redis 默认负荷>MaxActive时等待
	DEF_IDLE_TIMEOVER = 1 * time.Minute // 空闲多久回收

	DEF_CODING_JSON    = "json"    // json方式的编解码器
	DEF_CODING_MSGPACK = "msgpack" // msgpack方式的编解码器
)

------------------------------------------------------------------------------ ====================================常量定义===================================== ------------------------------------------------------------------------------

Variables

View Source
var (
	ErrInvalidConfig = errors.New("ErrInvalidRdsConfig")
	ErrNameRepeated  = errors.New("ErrConfigNameRepeated")
	ErrInvalidRCoder = errors.New("ErrNoRegistRCoder")
)

Functions

func Decode

func Decode(encoding string, b []byte, v interface{}) error

func Encode

func Encode(encoding string, v interface{}) (interface{}, error)

func GetPool

func GetPool(name string) *redis.Pool

GetPool 获取指定pool

func GetPoolConn

func GetPoolConn(name string) redis.Conn

GetPoolConn 获取指定pool的连接 !!!注意释放!!!

func InstallExt

func InstallExt(ctrlName string, mc IMCGeter, confs ...*Config)

安装扩展Redis控制器

func IsErrNil

func IsErrNil(err error) bool

func NewMutex

func NewMutex(dbName, key string) *redsync.Mutex

func RegCodec

func RegCodec(name string, codecer Codecer)

RegCodec 注册编解码器

Types

type Bit

type Bit struct{ Key }

func (Bit) BitCount

func (k Bit) BitCount(interval ...int64) *Reply

func (Bit) BitTop

func (k Bit) BitTop(opt, destKey string, keys ...string) *Reply

opt 包含 and、or、xor、not

func (Bit) GetBit

func (k Bit) GetBit(offset int64) *Reply

func (Bit) SetBit

func (k Bit) SetBit(offset, value int64) *Reply

type Codecer

type Codecer struct {
	Encoder func(v interface{}) ([]byte, error)
	Decoder func(data []byte, v interface{}) error
}

 => 编码器接口

type Config

type Config struct {
	Name      string `json:"name"`
	Addr      string `json:"addr"`
	DbIdx     int    `json:"dbIdx"`
	Password  string `json:"password"`
	MaxIdle   int    `json:"maxIdle"`
	MaxActive int    `json:"maxActive"`
	Wait      bool   `json:"wait"`

} //

 => Redis配置

type Hash

type Hash struct{ Key }

func (Hash) HDel

func (k Hash) HDel(fileds interface{}) *Reply

Hash.HDel 字段删除

func (Hash) HExists

func (k Hash) HExists(filed interface{}) *Reply

Hash.HExists 判断字段是否存在

func (Hash) HGet

func (k Hash) HGet(filed interface{}) *Reply

Hash.HGet 获取指定字段值

func (Hash) HGetAll

func (k Hash) HGetAll() *Reply

Hash.HGetAll 获取所有字段及值

func (Hash) HIncrBy

func (k Hash) HIncrBy(filed interface{}, increment interface{}) *Reply

Hash.HIncrBy 为指定字段值增加

func (Hash) HIncrByFloat

func (k Hash) HIncrByFloat(filed interface{}, increment float64) *Reply

Hash.HIncrByFloat 为指定字段值增加浮点数

func (Hash) HKeys

func (k Hash) HKeys() *Reply

Hash.HKeys 返回所有字段

func (Hash) HLen

func (k Hash) HLen() *Reply

Hash.HLen 返回字段数量

func (Hash) HMGet

func (k Hash) HMGet(fileds interface{}) *Reply

Hash.HMGet 返回多个字段值

func (Hash) HMSetMap

func (k Hash) HMSetMap(mp map[interface{}]interface{}) *Reply

Hash.HMSetMap 设置多个字段及值 [map]

func (Hash) HMSetStruct

func (k Hash) HMSetStruct(obj interface{}) *Reply

Hash.HMSetStruct 设置多个字段及值 [struct]

func (Hash) HSet

func (k Hash) HSet(filed, value interface{}, exist ...bool) *Reply

Hash.HSet 为字段设置其值(exist为true 表示字段不存则设置其值)

func (Hash) HVals

func (k Hash) HVals() *Reply

Hash.HVals 返回所有字段值

type IMCGeter

type IMCGeter interface {
	cto.ICtrlHandler

	// 获取基类配置
	HandleRedis() *Redis
}

 => ETCD管理器接口

type Key

type Key struct {
	DB     string // 哪个db中
	KEY    string
	Coding string // 序列化方式[只在特定的Key类型中生效](默认为空)
}

func (Key) Del

func (k Key) Del(keys ...string) *Reply

Key.Del 删除key(默认删自己,否则删入参指定的keys)

func (Key) Dump

func (k Key) Dump() *Reply

Key.RenameNX 序列化key

func (Key) Exists

func (k Key) Exists() *Reply

Key.Exists 判断key是否存在

func (Key) Expire

func (k Key) Expire(seconds int64) *Reply

Key.Expire 设置Key过期(秒)

func (Key) ExpireAt

func (k Key) ExpireAt(timestamp int64) *Reply

Key.ExpireAt 设置Key过期(时间戳)

func (Key) Keys

func (k Key) Keys() *Reply

Key.Keys 查找键 [*模糊查找]

func (Key) Move

func (k Key) Move(db int64) *Reply

Key.Move 同实例不同库间的键移动

func (Key) PTTL

func (k Key) PTTL() *Reply

Key.PTTL 剩余过期时间(毫秒)

func (Key) Persist

func (k Key) Persist() *Reply

Key.Persist 移除Key的过期设置

func (Key) PersistAt

func (k Key) PersistAt(milliSeconds int64) *Reply

Key.PersistAt 设置Key过期(毫秒)

func (Key) RandomKey

func (k Key) RandomKey() *Reply

Key.RandomKey 随机返回一个key

func (Key) Rename

func (k Key) Rename(newKey string) *Reply

Key.Del 重命名

func (Key) RenameNX

func (k Key) RenameNX(newKey string) *Reply

Key.RenameNX 仅当newkey不存在时重命名

func (Key) Restore

func (k Key) Restore(ttlMS, serializedValue interface{}) *Reply

Key.Restore 反序列化

func (Key) Select

func (k Key) Select(db int64) *Reply

Key.Select 选择库

func (Key) TTL

func (k Key) TTL() *Reply

Key.TTL 剩余过期时间(秒)

func (Key) Type

func (k Key) Type() *Reply

Key.Type 返回值的数据类型

type List

type List struct{ Key }

****************************************************************************** Copyright:cloud Author:cloudapex@126.com Version:1.0 Date:2020-05-13 Description: List数据结构 ******************************************************************************

func (List) BLpop

func (k List) BLpop(timeout interface{}) *Reply

List.BLpop 阻塞并弹出头元素

func (List) BRpop

func (k List) BRpop(timeout interface{}) *Reply

List.BRpop 阻塞并弹出末尾元素

func (List) BRpoplpush

func (k List) BRpoplpush(key, source, destination string, timeout interface{}) *Reply

List.BRpoplpush 阻塞并弹出尾元素,将弹出元素插入另一列表的开头

func (List) LIndex

func (k List) LIndex(index interface{}) *Reply

List.LIndex 返回指定位置的元素

func (List) LInsert

func (k List) LInsert(position, pivot, value string) *Reply

List.LInsert 将元素插入指定位置position:BEFORE|AFTER,当 pivot 不存在于列表 key 时,不执行任何操作。当 key 不存在时, key 被视为空列表,不执行任何操作。

func (List) LPop

func (k List) LPop() *Reply

List.LPop 返回列表头元素

func (List) LPush

func (k List) LPush(value interface{}) *Reply

List.LPush 向列表头插入元素

func (List) LPushx

func (k List) LPushx(value interface{}) *Reply

List.LPushx 当列表存在则将元素插入表头

func (List) LRange

func (k List) LRange(start, stop interface{}) *Reply

List.LRange 获取指定区间的元素

func (List) LRem

func (k List) LRem(count, value interface{}) *Reply

List.LRem 移除元素,count = 0 : 移除表中所有与 value 相等的值,count!=0,移除与 value 相等的元素,数量为 count的绝对值

func (List) LSet

func (k List) LSet(index, value interface{}) *Reply

List.LSet 设置指定位元素

func (List) LTrim

func (k List) LTrim(start, stop interface{}) *Reply

List.LTrim 列表裁剪,让列表只保留指定区间内的元素,不在指定区间之内的元素都将被删除。-1 表示尾部

func (List) RPop

func (k List) RPop() *Reply

List.RPop 返回列表尾元素

func (List) RPoplpush

func (k List) RPoplpush(key, source, destination string) *Reply

List.RPoplpush 弹出source尾元素并返回,将弹出元素插入destination列表的开头

func (List) RPush

func (k List) RPush(value interface{}) *Reply

List.RPush 将指定元素插入列表末尾

func (List) RPushx

func (k List) RPushx(value interface{}) *Reply

List.RPushx 当列表存在则将元素插入表尾

type Redis

type Redis struct {
	cto.ControlBase
	// contains filtered or unexported fields
}

 =>redis client control

func Install

func Install(ctrlName string, confs ...*Config) *Redis

安装默认Redis控制器

func (*Redis) HandleInit

func (this *Redis) HandleInit()

func (*Redis) HandleTerm

func (this *Redis) HandleTerm()

func (*Redis) Use

func (this *Redis) Use(name string) *redis.Pool

 ======== Functions

type Reply

type Reply struct {
	Coding string
	// contains filtered or unexported fields
}

--------

func Command

func Command(dbName, coding string, command string, args ...interface{}) *Reply

执行命令

func Replies

func Replies(rp interface{}, err error) *Reply

func (*Reply) Bool

func (r *Reply) Bool() (bool, error)

func (*Reply) ByteSlices

func (r *Reply) ByteSlices() ([][]byte, error)

func (*Reply) Bytes

func (r *Reply) Bytes() ([]byte, error)

func (*Reply) Error

func (r *Reply) Error() error

func (*Reply) Float64s

func (r *Reply) Float64s() ([]float64, error)

func (*Reply) Int

func (r *Reply) Int() (int, error)

func (*Reply) Int64

func (r *Reply) Int64() (int64, error)

func (*Reply) Int64Map

func (r *Reply) Int64Map() (map[string]int64, error)

func (*Reply) Int64s

func (r *Reply) Int64s() ([]int64, error)

func (*Reply) IntMap

func (r *Reply) IntMap() (map[string]int, error)

func (*Reply) Ints

func (r *Reply) Ints() ([]int, error)

func (*Reply) Positions

func (r *Reply) Positions() ([]*[2]float64, error)

func (*Reply) Result

func (r *Reply) Result() (interface{}, error)

func (*Reply) ScanStruct

func (r *Reply) ScanStruct(pObj interface{}) error

func (*Reply) String

func (r *Reply) String() (string, error)

func (*Reply) StringMap

func (r *Reply) StringMap() (map[string]string, error)

func (*Reply) Strings

func (r *Reply) Strings() ([]string, error)

func (*Reply) Uint64

func (r *Reply) Uint64() (uint64, error)

func (*Reply) Unmarshal

func (r *Reply) Unmarshal(v interface{}) error

func (*Reply) Values

func (r *Reply) Values() ([]interface{}, error)

type Set

type Set struct{ Key }

func (Set) SAdd

func (k Set) SAdd(fileds []interface{}) *Reply

Set.SAdd 添加元素

func (Set) SCard

func (k Set) SCard() *Reply

Set.SCard 集合元素个数

func (Set) SDiff

func (k Set) SDiff(keys []string) *Reply

Set.SDiff 返回一或多个集合的差集

func (Set) SDiffStore

func (k Set) SDiffStore(destinationKey string, keys []string) *Reply

Set.SDiffStore 将一或多个集合的差集保存至另一集合(destinationKey)

func (Set) SInter

func (k Set) SInter(keys []string) *Reply

Set.SInter 一个或多个集合的交集

func (Set) SInterStore

func (k Set) SInterStore(destinationKey string, keys []string) *Reply

Set.SInterStore 将keys的集合的并集 写入到 destinationKey中

func (Set) SMembers

func (k Set) SMembers() *Reply

Set.SMembers 返回集合中成员

func (Set) SMove

func (k Set) SMove(sourceKey, destinationKey string, member interface{}) *Reply

Set.SMove 将元素从集合移至另一个集合

func (Set) SPop

func (k Set) SPop() *Reply

Set.SPop 随机返回并移除一个元素

func (Set) SRandMember

func (k Set) SRandMember(count ...int64) *Reply

Set.SRandMember 随机返回一个或多个元素

func (Set) SRem

func (k Set) SRem(members []interface{}) *Reply

Set.SRem 移除指定的元素

func (Set) SUnion

func (k Set) SUnion(keys []string) *Reply

Set.SUnion 返回集合的并集

func (Set) SUnionStore

func (k Set) SUnionStore(destinationKey string, keys []string) *Reply

Set.SUnionStore 将 keys 的集合的并集 写入到 destinationKey 中

func (Set) SisMember

func (k Set) SisMember(member interface{}) *Reply

Set.SisMember 判断元素是否是集合成员

type String

type String struct{ Key }

func (String) Decr

func (k String) Decr() *Reply

String.Decr 自减

func (String) DecrBy

func (k String) DecrBy(increment int64) *Reply

String.DecrBy 自减指定值

func (String) Get

func (k String) Get() *Reply

String.Get 获取值

func (String) GetRange

func (k String) GetRange(start, end int64) *Reply

String.GetRange 获取子字符串

func (String) GetSet

func (k String) GetSet(value interface{}) *Reply

String.GetSet 设置并返回旧值

func (String) Incr

func (k String) Incr() *Reply

String.Incr 自增

func (String) IncrBy

func (k String) IncrBy(increment int64) *Reply

String.IncrBy 增加指定值

func (String) IncrByFloat

func (k String) IncrByFloat(increment float64) *Reply

String.IncrByFloat 增加一个浮点值

func (String) LuaIncrBy

func (k String) LuaIncrBy(amount int) *Reply

String.LuaIncrBy 安全增减键值(不会出现负值), Result.Reply==nil表示失败, Result.Int()是最新值

func (String) MGet

func (k String) MGet(keys []string) *Reply

String.MGet 返回多个key的值

func (String) MSet

func (k String) MSet(kv map[string]interface{}) *Reply

String.MSet 设置多个值

func (String) MSetNx

func (k String) MSetNx(kv map[string]interface{}) *Reply

String.MSetNx key不存在时设置多个值

func (String) PSetEX

func (k String) PSetEX(value interface{}, milliseconds int64) *Reply

String.PSetEX 设置key值并指定生存时间(毫秒)

func (String) Set

func (k String) Set(value interface{}, expire ...int64) *Reply

String.Set 设置值

func (String) SetEX

func (k String) SetEX(value interface{}, seconds int64) *Reply

String.SetEX 设置key并指定生存时间

func (String) SetNX

func (k String) SetNX(value interface{}) *Reply

String.SetNX 当key不存在是在设置值

func (String) SetRange

func (k String) SetRange(value interface{}, offset int64) *Reply

String.SetRange 设置子字符串

type Zset

type Zset struct{ Key }

****************************************************************************** Copyright:cloud Author:cloudapex@126.com Version:1.0 Date:2020-05-13 Description: Zset数据结构 ******************************************************************************

func (Zset) ZAdd

func (k Zset) ZAdd(mp map[interface{}]interface{}) *Reply

Zset.ZAdd 添加元素 map[score]member

func (Zset) ZCard

func (k Zset) ZCard() *Reply

Zset.ZCard 增加元素权重

func (Zset) ZCount

func (k Zset) ZCount(min, max interface{}) *Reply

Zset.ZCount 返回集合两个权重间的元素数

func (Zset) ZEank

func (k Zset) ZEank(member interface{}) *Reply

Zset.ZEank 返回指定元素的排名

func (Zset) ZRange

func (k Zset) ZRange(start, stop interface{}, withScore ...bool) *Reply

Zset.ZRange 返回指定区间内的元素

func (Zset) ZRevrange

func (k Zset) ZRevrange(start, stop interface{}, withScore ...bool) *Reply

Zset.ZRevrange 倒序返回指定区间内的元素

func (Zset) ZScore

func (k Zset) ZScore(member interface{}) *Reply

Zset.ZScore 返回指定元素的权重

func (Zset) ZUncrBy

func (k Zset) ZUncrBy(increment, member interface{}) *Reply

Zset.ZUncrBy 增加元素权重

Jump to

Keyboard shortcuts

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