Documentation ¶
Index ¶
- Constants
- Variables
- func IsNilError(err error) bool
- type Config
- type Redis
- func (r *Redis) CreateRegister(key string, cfg *RegistryInfo) *Register
- func (r *Redis) CreateRegisterEx(key string, cfgs []*RegistryInfo) *Register
- func (r *Redis) Do(ctx context.Context, cmd string, args ...interface{}) (interface{}, error)
- func (r *Redis) Do2(ctx context.Context, cmd string, args ...interface{}) RedisResultBind
- func (r *Redis) DoCmdBool(ctx context.Context, cmd string, args ...interface{}) (bool, error)
- func (r *Redis) DoCmdByteSlices(ctx context.Context, cmd string, args ...interface{}) ([][]byte, error)
- func (r *Redis) DoCmdBytes(ctx context.Context, cmd string, args ...interface{}) ([]byte, error)
- func (r *Redis) DoCmdFloat64(ctx context.Context, cmd string, args ...interface{}) (float64, error)
- func (r *Redis) DoCmdFloat64s(ctx context.Context, cmd string, args ...interface{}) ([]float64, error)
- func (r *Redis) DoCmdInt(ctx context.Context, cmd string, args ...interface{}) (int, error)
- func (r *Redis) DoCmdInt64(ctx context.Context, cmd string, args ...interface{}) (int64, error)
- func (r *Redis) DoCmdInt64Map(ctx context.Context, cmd string, args ...interface{}) (map[string]int64, error)
- func (r *Redis) DoCmdInt64s(ctx context.Context, cmd string, args ...interface{}) ([]int64, error)
- func (r *Redis) DoCmdIntMap(ctx context.Context, cmd string, args ...interface{}) (map[string]int, error)
- func (r *Redis) DoCmdInts(ctx context.Context, cmd string, args ...interface{}) ([]int, error)
- func (r *Redis) DoCmdString(ctx context.Context, cmd string, args ...interface{}) (string, error)
- func (r *Redis) DoCmdStringMap(ctx context.Context, cmd string, args ...interface{}) (map[string]string, error)
- func (r *Redis) DoCmdStrings(ctx context.Context, cmd string, args ...interface{}) ([]string, error)
- func (r *Redis) DoCmdUint64(ctx context.Context, cmd string, args ...interface{}) (uint64, error)
- func (r *Redis) DoScript(ctx context.Context, script *RedisScript, keysAndArgs ...interface{}) (interface{}, error)
- func (r *Redis) DoScript2(ctx context.Context, script *RedisScript, keysAndArgs ...interface{}) RedisResultBind
- func (r *Redis) DoScriptBool(ctx context.Context, script *RedisScript, keysAndArgs ...interface{}) (bool, error)
- func (r *Redis) DoScriptByteSlices(ctx context.Context, script *RedisScript, keysAndArgs ...interface{}) ([][]byte, error)
- func (r *Redis) DoScriptBytes(ctx context.Context, script *RedisScript, keysAndArgs ...interface{}) ([]byte, error)
- func (r *Redis) DoScriptFloat64(ctx context.Context, script *RedisScript, keysAndArgs ...interface{}) (float64, error)
- func (r *Redis) DoScriptFloat64s(ctx context.Context, script *RedisScript, keysAndArgs ...interface{}) ([]float64, error)
- func (r *Redis) DoScriptInt(ctx context.Context, script *RedisScript, keysAndArgs ...interface{}) (int, error)
- func (r *Redis) DoScriptInt64(ctx context.Context, script *RedisScript, keysAndArgs ...interface{}) (int64, error)
- func (r *Redis) DoScriptInt64Map(ctx context.Context, script *RedisScript, keysAndArgs ...interface{}) (map[string]int64, error)
- func (r *Redis) DoScriptInt64s(ctx context.Context, script *RedisScript, keysAndArgs ...interface{}) ([]int64, error)
- func (r *Redis) DoScriptIntMap(ctx context.Context, script *RedisScript, keysAndArgs ...interface{}) (map[string]int, error)
- func (r *Redis) DoScriptInts(ctx context.Context, script *RedisScript, keysAndArgs ...interface{}) ([]int, error)
- func (r *Redis) DoScriptString(ctx context.Context, script *RedisScript, keysAndArgs ...interface{}) (string, error)
- func (r *Redis) DoScriptStringMap(ctx context.Context, script *RedisScript, keysAndArgs ...interface{}) (map[string]string, error)
- func (r *Redis) DoScriptStrings(ctx context.Context, script *RedisScript, keysAndArgs ...interface{}) ([]string, error)
- func (r *Redis) DoScriptUint64(ctx context.Context, script *RedisScript, keysAndArgs ...interface{}) (uint64, error)
- func (r *Redis) HMGetObj(ctx context.Context, key string, v interface{}) error
- func (r *Redis) HMSetObj(ctx context.Context, key string, v interface{}) error
- func (r *Redis) HasKey(ctx context.Context, key string) bool
- func (r *Redis) Lock(ctx context.Context, key string, timeout time.Duration) (func(), error)
- func (r *Redis) NewPipeline() *RedisPipeline
- func (r *Redis) Pool() *redis.Pool
- func (r *Redis) ReadServices(ctx context.Context, key string, serverNames []string) ([]*RegistryInfo, error)
- func (r *Redis) RegHook(f func(ctx context.Context, cmd *RedisCommond))
- func (r *Redis) TryLock(ctx context.Context, key string, timeout time.Duration) (func(), error)
- func (r *Redis) WatchServices(key string, serverNames []string, fun func(infos []*RegistryInfo))
- func (r *Redis) WatchServices2(key string, serverNames []string, fun func(addInfos, delInfos []*RegistryInfo))
- type RedisCommond
- func (c *RedisCommond) Bind(v interface{}) error
- func (c *RedisCommond) BindJsonObj(v interface{}) error
- func (c *RedisCommond) BindJsonObjSlice(v interface{}) error
- func (c *RedisCommond) BindMap(v interface{}) error
- func (c *RedisCommond) BindSlice(v interface{}) error
- func (c *RedisCommond) CmdString() string
- func (c *RedisCommond) ReplyString() string
- type RedisPipeline
- func (p *RedisPipeline) Cmd(commandName string, args ...interface{}) RedisResultBind
- func (p *RedisPipeline) Do(ctx context.Context) error
- func (p *RedisPipeline) DoEx(ctx context.Context) ([]*RedisCommond, error)
- func (p *RedisPipeline) HMGetObj(key string, v interface{}) error
- func (p *RedisPipeline) HMSetObj(key string, v interface{}) bool
- type RedisResultBind
- type RedisScript
- type Register
- type RegistryInfo
Constants ¶
const CtxKey_caller = utils.CtxKey("caller") // 值:CallerDesc对象 一般情况内部使用
const CtxKey_cmddesc = utils.CtxKey("cmddesc") // 值:字符串 命令描述 一般情况内部使用
const CtxKey_nolog = utils.CtxKey_nolog // 不打印日志,错误日志还会打印 值:不受限制 一般写1
Variables ¶
var RegExprieTime = 8
多长时间没更新就认为是取消注册了,单位秒, 允许外部修改 Register对象的注册频率:RegExprieTime/2
var RegSep string = "&"
Reids中存储注册服务器各字段的分割符号,所以也要要求服务器字符串字段不能包含下面这个分隔符, 允许外部修改
Functions ¶
Types ¶
type Redis ¶
type Redis struct {
// contains filtered or unexported fields
}
func DefaultRedis ¶
func DefaultRedis() *Redis
func InitDefaultRedis ¶
func (*Redis) CreateRegister ¶
func (r *Redis) CreateRegister(key string, cfg *RegistryInfo) *Register
key是按照zset写入
func (*Redis) CreateRegisterEx ¶
func (r *Redis) CreateRegisterEx(key string, cfgs []*RegistryInfo) *Register
func (*Redis) Do2 ¶
func (r *Redis) Do2(ctx context.Context, cmd string, args ...interface{}) RedisResultBind
func (*Redis) DoCmdByteSlices ¶
func (*Redis) DoCmdBytes ¶
func (*Redis) DoCmdFloat64 ¶
func (*Redis) DoCmdFloat64s ¶
func (*Redis) DoCmdInt64 ¶
func (*Redis) DoCmdInt64Map ¶
func (*Redis) DoCmdInt64s ¶
func (*Redis) DoCmdIntMap ¶
func (*Redis) DoCmdString ¶
func (*Redis) DoCmdStringMap ¶
func (*Redis) DoCmdStrings ¶
func (*Redis) DoCmdUint64 ¶
func (*Redis) DoScript ¶
func (r *Redis) DoScript(ctx context.Context, script *RedisScript, keysAndArgs ...interface{}) (interface{}, error)
func (*Redis) DoScript2 ¶
func (r *Redis) DoScript2(ctx context.Context, script *RedisScript, keysAndArgs ...interface{}) RedisResultBind
func (*Redis) DoScriptBool ¶
func (*Redis) DoScriptByteSlices ¶
func (*Redis) DoScriptBytes ¶
func (*Redis) DoScriptFloat64 ¶
func (*Redis) DoScriptFloat64s ¶
func (*Redis) DoScriptInt ¶
func (*Redis) DoScriptInt64 ¶
func (*Redis) DoScriptInt64Map ¶
func (*Redis) DoScriptInt64s ¶
func (*Redis) DoScriptIntMap ¶
func (*Redis) DoScriptInts ¶
func (*Redis) DoScriptString ¶
func (*Redis) DoScriptStringMap ¶
func (*Redis) DoScriptStrings ¶
func (*Redis) DoScriptUint64 ¶
func (*Redis) HMGetObj ¶
针对HMGET命令 调用Cmd时,参数不需要包括field 结构成员首字母需要大写,tag中必须是包含 `redis:"hello"` 其中hello就表示在redis中存储的field名称 结构成员类型 : Bool, Int, Int8, Int16, Int32, Int64, Uint, Uint8, Uint16, Uint32, Uint64, Uintptr, Float32, Float64, String, []byte 结构成员其他类型 : 通过Json转化 传入的参数为结构的地址 参数组织调用 hmsetObjArgs hmgetObjArgs
func (*Redis) NewPipeline ¶
func (r *Redis) NewPipeline() *RedisPipeline
func (*Redis) ReadServices ¶
func (r *Redis) ReadServices(ctx context.Context, key string, serverNames []string) ([]*RegistryInfo, error)
读取一次服务器列表
func (*Redis) WatchServices ¶
func (r *Redis) WatchServices(key string, serverNames []string, fun func(infos []*RegistryInfo))
WatchService 监控服务器变化 RegistryConfig值填充Registry前缀的变量 回调外部不要修改infos参数 key 表示服务器发现的key serverName 表示监听哪些服务器 为空表示监听全部的服务器
func (*Redis) WatchServices2 ¶
func (r *Redis) WatchServices2(key string, serverNames []string, fun func(addInfos, delInfos []*RegistryInfo))
WatchService 监控服务器变化,通知变化,增加或者删除 key 表示服务器发现的key serverName 表示监听哪些服务器 为空表示监听全部的服务器
type RedisCommond ¶
type RedisCommond struct { // 命令名和参数 Cmd string Args []interface{} CmdDesc string // 命令的描述 Caller *utils.CallerDesc // 执行结果 Reids直接调用命令使用,如果Reply和Err说明命令没有执行 Reply interface{} Err error Elapsed time.Duration // contains filtered or unexported fields }
Redis命令封装 并实现RedisResultBind接口 注意Redis执行结果为空时(ErrNil),并不认为是错误
func (*RedisCommond) Bind ¶
func (c *RedisCommond) Bind(v interface{}) error
func (*RedisCommond) BindJsonObj ¶
func (c *RedisCommond) BindJsonObj(v interface{}) error
func (*RedisCommond) BindJsonObjSlice ¶
func (c *RedisCommond) BindJsonObjSlice(v interface{}) error
func (*RedisCommond) BindMap ¶
func (c *RedisCommond) BindMap(v interface{}) error
func (*RedisCommond) BindSlice ¶
func (c *RedisCommond) BindSlice(v interface{}) error
func (*RedisCommond) CmdString ¶
func (c *RedisCommond) CmdString() string
func (*RedisCommond) ReplyString ¶
func (c *RedisCommond) ReplyString() string
type RedisPipeline ¶
type RedisPipeline struct { // 支持特殊情况下指定超时,如 BLPOP 命令 Timeout time.Duration // contains filtered or unexported fields }
func (*RedisPipeline) Cmd ¶
func (p *RedisPipeline) Cmd(commandName string, args ...interface{}) RedisResultBind
统一的命令
func (*RedisPipeline) DoEx ¶
func (p *RedisPipeline) DoEx(ctx context.Context) ([]*RedisCommond, error)
任何一条命令错误,都会返回错误
func (*RedisPipeline) HMGetObj ¶
func (p *RedisPipeline) HMGetObj(key string, v interface{}) error
参数v 参考Redis.HMGetObj的说明
func (*RedisPipeline) HMSetObj ¶
func (p *RedisPipeline) HMSetObj(key string, v interface{}) bool
参数v 参考Redis.HMGetObj的说明
type RedisResultBind ¶
type RedisResultBind interface { // BindKind : Bool, Int, Int8, Int16, Int32, Int64, Uint, Uint8, Uint16, Uint32, Uint64, Uintptr, Float32, Float64, String, []byte // 其他类型 : 通过Json转化 // 传入的参数为对象的地址 Bind(v interface{}) error // BindKind : Slice // SliceElemKind : Bool, Int, Int8, Int16, Int32, Int64, Uint, Uint8, Uint16, Uint32, Uint64, Uintptr, Float32, Float64, String // 其他类型 : 通过Json转化 // 传入的参数为Slice的地址 nil的Slice也可以 BindSlice(v interface{}) error // BindType : Map // MapElemType : Bool, Int, Int8, Int16, Int32, Int64, Uint, Uint8, Uint16, Uint32, Uint64, Uintptr, Float32, Float64, String // 其他类型 : 通过Json转化 // 传入的参数为Map的地址 nil的Map也可以 BindMap(v interface{}) error // BindType : Struct // 结构支持json格式化 // 传入的参数为结构的地址 BindJsonObj(v interface{}) error // BindType : []Struct 或者 []*Struct // SliceElemType 支持json格式化 // 传入的参数为Slice的地址 nil的Slice也可以 BindJsonObjSlice(v interface{}) error }
Redis结果绑定,用这种方式认为不需要太关心Redis执行结果真的正确与否
type RedisScript ¶
type RedisScript struct {
// contains filtered or unexported fields
}
func NewScript ¶
func NewScript(keyCount int, src string) *RedisScript
type RegistryInfo ¶
type RegistryInfo struct { RegistryName string `json:"registryname,omitempty"` // 注册的名字 组名 RegistryID string `json:"registryid,omitempty"` // 注册的ID 服务器唯一ID RegistryAddr string `json:"registryaddr,omitempty"` // 服务器对外暴露的地址 RegistryPort int `json:"registryport,omitempty"` // 服务器对外暴露的端口 RegistryScheme string `json:"registryscheme,omitempty"` // 服务器使用的协议 }
RegistryInfo 服务注册信息
func (*RegistryInfo) MarshalZerologObject ¶
func (r *RegistryInfo) MarshalZerologObject(e *zerolog.Event)