redis

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	RedisType string `mapstructure:"redis_type"`

	Network  string `mapstructure:"network"`
	Addr     string `mapstructure:"addr"`
	Password string `mapstructure:"password"`
	DB       int    `mapstructure:"db"`

	Addresses          []string `mapstructure:"addresses"`
	Username           string   `mapstructure:"username"`
	SentinelPassword   string   `mapstructure:"sentinel_password"`
	MaxRetries         int      `mapstructure:"max_retries"`
	MinRetryBackoff    string   `mapstructure:"min_retry_backoff"`
	MaxRetryBackoff    string   `mapstructure:"max_retry_backoff"`
	DialTimeout        string   `mapstructure:"dial_timeout"`
	ReadTimeout        string   `mapstructure:"read_timeout"`
	WriteTimeout       string   `mapstructure:"write_timeout"`
	PoolSize           int      `mapstructure:"pool_size"`
	MinIdleConns       int      `mapstructure:"min_idle_conns"`
	MaxConnAge         string   `mapstructure:"max_conn_age"`
	PoolTimeout        string   `mapstructure:"pool_timeout"`
	IdleTimeout        string   `mapstructure:"idle_timeout"`
	IdleCheckFrequency string   `mapstructure:"idle_check_frequency"`
	MaxRedirects       int      `mapstructure:"max_redirects"`
	ReadOnly           bool     `mapstructure:"read_only"`
	RouteByLatency     bool     `mapstructure:"route_by_latency"`
	RouteRandomly      bool     `mapstructure:"route_randomly"`
	SlaveOnly          bool     `mapstructure:"slave_only"`
	Randomly           bool     `mapstructure:"randomly"`
	MasterName         string   `mapstructure:"master_name"`

	NewClient    func(opt *redis.Options) *redis.Client
	TLSConfig    *tls.Config
	Dialer       func(ctx context.Context, network, addr string) (net.Conn, error)
	OnConnect    func(ctx context.Context, cn *redis.Conn) error
	Limiter      redis.Limiter
	ClusterSlots func(ctx context.Context) ([]redis.ClusterSlot, error)
}

Config redis config

func (Config) NewRedis

func (config Config) NewRedis() redis.Cmdable

NewRedis instantiate a new redis operation object according to the configuration information

type DefaultLogger

type DefaultLogger struct {
}

DefaultLogger default logger

func NewDefaultLogger

func NewDefaultLogger() *DefaultLogger

NewDefaultLogger default logger

func (DefaultLogger) Error

func (d DefaultLogger) Error(args ...interface{})

Error error...

func (DefaultLogger) Warn

func (d DefaultLogger) Warn(args ...interface{})

Warn warn...

type ILogger

type ILogger interface {
	Warn(args ...interface{})
	Error(args ...interface{})
}

ILogger logger interface

type List

type List struct {
	// contains filtered or unexported fields
}

List redis list 数据结构

func (*List) LPop

func (l *List) LPop(val interface{}) error

LPop redis Left pop

func (*List) LPush

func (l *List) LPush(values ...interface{})

LPush redis Left Push

func (*List) Len

func (l *List) Len() int64

Len list len

func (*List) RPop

func (l *List) RPop(val interface{}) error

RPop redis right pop

func (*List) RPush

func (l *List) RPush(values ...interface{})

RPush redis right Push

type RBinding

type RBinding struct {
	// contains filtered or unexported fields
}

RBinding redis go type binding

Using gob serialization, gob is an operation provided by golang to serialize golang, but interface{} cannot be serialized. For example, you have the following structure,
 type User struct {
     Username string
     FieldAny interface{}
 }

In fact, when using gob to serialize and deserialize the structure object, an error will be returned, because gob will not automatically help you deal with type problems, but gob provides two methods, gob.Register and gob.RegisterName , These two methods are an operation to register your type to gob global, which is recommended gob.RegisterName Although there is little difference between them, gob.RegisterName internal use sync.Map manage the type of registration, So in fact, it doesn't have to do with where to register and concurrency, So you can choose to register in the controller or anywhere, but remember to register before you use serialization and deserialization, It should be noted that, gob.RegisterName will not accept the problem that the type of registration before and after the same name is different, such as gob.RegisterName("a", A{}); gob.RegisterName("a", B{}), If you do this, will panic

func NewDefaultRBinding

func NewDefaultRBinding(ctx context.Context, r *Redis) *RBinding

NewDefaultRBinding Gets a default binding for the rbinding operation

func (*RBinding) Del

func (r *RBinding) Del(key string)

Del redis del

func (*RBinding) Get

func (r *RBinding) Get(key string, val interface{}) (err error)

Get redis get

func (*RBinding) GetSet

func (r *RBinding) GetSet(key string, val interface{}) (err error)

GetSet redis getset

将 val 的写入到 redis , 并将 redis 之前此 key 的值绑定到 val, val 必须是一个引用

func (*RBinding) List

func (r *RBinding) List(key string) *List

List 返回一个指定 key 的 list 操作

返回的 push 和 pop 操作, 需要保证 val 为同一类型

func (*RBinding) LoadOrStorage

func (r *RBinding) LoadOrStorage(key string, val interface{}, f func() (expiration time.Duration, data interface{})) error

LoadOrStorage 获取指定key的值,如果值不存在,就执行f方法将返回值存入redis

func (*RBinding) MGet

func (r *RBinding) MGet(keys ...string) map[string]Value

MGet redis mGet

func (*RBinding) Set

func (r *RBinding) Set(key string, val interface{}, expiration time.Duration) (err error)

Set redis set

func (*RBinding) SetNX

func (r *RBinding) SetNX(key string, val interface{}, expiration time.Duration) (rs bool, err error)

SetNX set nx

func (*RBinding) Sets

func (r *RBinding) Sets(key string) *Set

Sets redis set 结构

type Redis

type Redis struct {
	Config Config
	// contains filtered or unexported fields
}

Redis redis

func (*Redis) Instance

func (s *Redis) Instance() redis.Cmdable

Instance get redis instance

func (*Redis) OnChange

func (s *Redis) OnChange(viper *viper.Viper)

OnChange when the configuration file changes, a redis object will be re instantiated

func (*Redis) SetLogger

func (s *Redis) SetLogger(logger ILogger)

SetLogger set logger

type Set

type Set struct {
	// contains filtered or unexported fields
}

Set redis set 操作

func (*Set) SAdd

func (set *Set) SAdd(members ...interface{})

SAdd 向集合添加一个或多个成员

func (*Set) SCard

func (set *Set) SCard() int64

SCard 向集合添加一个或多个成员

func (*Set) SDiff

func (set *Set) SDiff(container interface{}, diffKeys ...string) interface{}

SDiff 返回第一个集合与其他集合之间的差异。

container 是一个结构, 比如这个 set 的值是 string, container 就是 string, 值是struct,container就传struct, 不需要是个引用

func (*Set) SInter

func (set *Set) SInter(container interface{}, diffKeys ...string) interface{}

SInter 返回给定所有集合的交集

func (*Set) SMembers

func (set *Set) SMembers(container interface{}) interface{}

SMembers 返回集合中的所有成员

func (*Set) SMove

func (set *Set) SMove(destination string, member interface{}) error

SMove 将 member 元素从 source 集合移动到 destination 集合

func (*Set) SPop

func (set *Set) SPop(container interface{}, n ...int64) interface{}

SPop 移除并返回集合中的一个或多个随机元素

func (*Set) SRem

func (set *Set) SRem(members ...interface{}) int64

SRem 移除集合中一个或多个成员

func (*Set) SUnion

func (set *Set) SUnion(container interface{}, diffKeys ...string) interface{}

SUnion 返回所有给定集合的并集

type Value

type Value struct {
	// contains filtered or unexported fields
}

Value gob 转一些基础类型

func (Value) Bool

func (v Value) Bool() (val bool, err error)

Bool 与其他类型转换不同, Bool 直接使用redis原始string值做 ParseBool 操作

func (Value) Decode

func (v Value) Decode(val interface{}) error

Decode 解析 redis 原始值, 调用此方法需要明确的知道在该值存入 redis 是以什么类型序列化存入的, 否则会解析失败

func (Value) DecodeValue

func (v Value) DecodeValue(val reflect.Value) error

DecodeValue 同 Decode, 不过这里的 val 是传入的类型的 reflect.Value

func (Value) Float32

func (v Value) Float32() (val float32, err error)

Float32 将 redis 的原始值转为 float32

func (Value) Float64

func (v Value) Float64() (val float64, err error)

Float64 将 redis 的原始值转为 float64

func (Value) Int

func (v Value) Int() (val int, err error)

Int 将 redis 的原始值转为 int

func (Value) Int16

func (v Value) Int16() (val int16, err error)

Int16 将 redis 的原始值转为 int16

func (Value) Int32

func (v Value) Int32() (val int32, err error)

Int32 将 redis 的原始值转为 int32

func (Value) Int64

func (v Value) Int64() (val int64, err error)

Int64 将 redis 的原始值转为 int64

func (Value) Int8

func (v Value) Int8() (val int8, err error)

Int8 将 redis 的原始值转为 int8

func (Value) String

func (v Value) String() (val string, err error)

String 将 redis 的原始值直接以 string 返回

func (Value) Uint

func (v Value) Uint() (val uint, err error)

Uint 将 redis 的原始值转为 uint

func (Value) Uint16

func (v Value) Uint16() (val uint16, err error)

Uint16 将 redis 的原始值转为 uint16

func (Value) Uint32

func (v Value) Uint32() (val uint32, err error)

Uint32 将 redis 的原始值转为 uint32

func (Value) Uint64

func (v Value) Uint64() (val uint64, err error)

Uint64 将 redis 的原始值转为 uint64

func (Value) Uint8

func (v Value) Uint8() (val uint8, err error)

Uint8 将 redis 的原始值转为 uint8

Jump to

Keyboard shortcuts

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