kredis

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//ClusterMode using clusterClient
	ClusterMode string = "cluster"
	//StubMode using reidsClient
	StubMode string = "stub"
)

Variables

This section is empty.

Functions

func ValueDecode

func ValueDecode(coder ValueCoder, o []byte, v interface{}) error

func ValueEncode

func ValueEncode(coder ValueCoder, v interface{}) interface{}

Types

type CompressCoder

type CompressCoder struct {
}

func (*CompressCoder) DeCoder

func (c *CompressCoder) DeCoder(o []byte, v interface{}) error

func (*CompressCoder) Encoder

func (c *CompressCoder) Encoder(v interface{}) (bytes []byte, err error)

type Config

type Config struct {
	// Addrs 实例配置地址
	Addrs []string `json:"addrs" toml:"addrs"`
	// Mode Redis模式 cluster|stub
	Mode string `json:"mode" toml:"mode"`
	// Password 密码
	Password string `json:"password" toml:"password"`
	// DB,默认为0, 一般应用不推荐使用DB分片
	DB int `json:"db" toml:"db"`
	// PoolSize 集群内每个节点的最大连接池限制 默认每个CPU10个连接
	PoolSize int `json:"poolSize" toml:"poolSize"`
	// MaxRetries 网络相关的错误最大重试次数 默认8次
	MaxRetries int `json:"maxRetries" toml:"maxRetries"`
	// MinIdleConns 最小空闲连接数
	MinIdleConns int `json:"minIdleConns" toml:"minIdleConns"`
	// DialTimeout 拨超时时间
	DialTimeout time.Duration `json:"dialTimeout" toml:"dialTimeout"`
	// ReadTimeout 读超时 默认3s
	ReadTimeout time.Duration `json:"readTimeout" toml:"readTimeout"`
	// WriteTimeout 读超时 默认3s
	WriteTimeout time.Duration `json:"writeTimeout" toml:"writeTimeout"`
	// IdleTimeout 连接最大空闲时间,默认60s, 超过该时间,连接会被主动关闭
	IdleTimeout time.Duration `json:"idleTimeout" toml:"idleTimeout"`
	// 慢日志门限值,超过该门限值的请求,将被记录到慢日志中
	SlowThreshold time.Duration `json:"slowThreshold" toml:"slowThreshold"`
	// contains filtered or unexported fields
}

Config for kredis, contains RedisStubConfig and RedisClusterConfig

func DefaultRedisConfig

func DefaultRedisConfig() *Config

DefaultRedisConfig default config ...

func (*Config) Build

func (config *Config) Build() *Redis

Build ...

func (*Config) SetLogger

func (self *Config) SetLogger(logger logger.Logger) *Config

type JsonCoder

type JsonCoder struct {
}

func (*JsonCoder) DeCoder

func (c *JsonCoder) DeCoder(o []byte, t interface{}) error

func (*JsonCoder) Encoder

func (c *JsonCoder) Encoder(v interface{}) ([]byte, error)

type Redis

type Redis struct {
	redis.Cmdable
	Config     *Config
	ValueCoder ValueCoder
}

Redis client (cmdable and config)

func (*Redis) GetByCoder

func (r *Redis) GetByCoder(key string, val interface{}) error

Get(key string) *StringCmd

func (*Redis) GetRaw

func (r *Redis) GetRaw(key string) ([]byte, error)

func (*Redis) GetSetByCoder

func (r *Redis) GetSetByCoder(key string, val interface{}, newVal interface{}) error

func (*Redis) HGetByCoder

func (r *Redis) HGetByCoder(key, field string, val interface{}) error

func (*Redis) HGetRaw

func (r *Redis) HGetRaw(key string, fields string) ([]byte, error)

func (*Redis) HSetByCoder

func (r *Redis) HSetByCoder(key, field string, value interface{}) error

func (*Redis) SetByCoder

func (r *Redis) SetByCoder(key string, value interface{}, expire time.Duration) error

func (*Redis) UseValueCoder

func (self *Redis) UseValueCoder(coder ValueCoder) *Redis

type ValueCoder

type ValueCoder interface {
	// 将对象转成字节组
	Encoder(interface{}) ([]byte, error)
	// 将字节组转成对象
	DeCoder([]byte, interface{}) error
}

Jump to

Keyboard shortcuts

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