redisx

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2023 License: MIT Imports: 7 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 {
	Mode              RedisMode `default:"NormalDsn"` // 模式,支持NormalDsn、NormalAddr、Sentinel
	IsNeedFillDefault bool      // 是否需要填充默认参数

	// dial
	Dsn            string        // 用于NormalDsn模式
	Addr           string        // redis地址,用于NormalAddr模式
	Password       string        // redis密码
	Db             int           // db库
	ConnectTimeout time.Duration `default:"3s"`
	ReadTimeout    time.Duration `default:"3s"`
	WriteTimeout   time.Duration `default:"3s"`

	// pool
	MaxIdle     int           `default:"3"`
	MaxActive   int           `default:"64"`
	IdleTimeout time.Duration `default:"240s"`

	// sentinel
	Sentinel *Sentinel // 用于Sentinel
}

Config Redis的配置

type Pool

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

Pool redis connection struct

func NewPool

func NewPool(conf *Config) *Pool

NewPool 初始化redis连接池结构 c.Addr like: redis://user:secret@localhost:6379/0?foo=bar&qux=baz

func (*Pool) Close

func (p *Pool) Close() error

Close closes the connection pool.

func (*Pool) Del

func (p *Pool) Del(key string) error

Del redis key

func (*Pool) DoScript

func (p *Pool) DoScript(keyCount int, src string, keysAndArgs ...interface{}) (interface{}, error)

DoScript

func (*Pool) Expire

func (p *Pool) Expire(key string, ttl int32) error

expire key

func (*Pool) ExpireAt

func (p *Pool) ExpireAt(key string, expireTime time.Time) error

expire at

func (*Pool) Get

func (p *Pool) Get(key string) (reply interface{}, err error)

Get get []byte value from redis key

func (*Pool) HDel

func (p *Pool) HDel(key string, field string) error

hdel

func (*Pool) HGet

func (p *Pool) HGet(key string, field string) (interface{}, error)

hget

func (*Pool) HGetall

func (p *Pool) HGetall(key string) (interface{}, error)

hgetall

func (*Pool) HIncr

func (p *Pool) HIncr(key string, field string, addValue int64) (int64, error)

HINCR

func (*Pool) HMDel

func (p *Pool) HMDel(key string, fields []string) (interface{}, error)

hmdel

func (*Pool) HMGet

func (p *Pool) HMGet(key string, fields []string) (interface{}, error)

hmget

func (*Pool) HMSet

func (p *Pool) HMSet(key string, fields map[string]interface{}) error

hmset

func (*Pool) HSet

func (p *Pool) HSet(key string, field string, value interface{}) error

hset

func (*Pool) Hkeys

func (p *Pool) Hkeys(key string) (interface{}, error)

HKEYS

func (*Pool) INCR

func (p *Pool) INCR(key string, addValue int64) (int64, error)

INCR

func (*Pool) Keys

func (p *Pool) Keys(pattern string) (interface{}, error)

KEYS

func (*Pool) Llen

func (p *Pool) Llen(key string) (int64, error)

Llen LLEN redis list

func (*Pool) Lpush

func (p *Pool) Lpush(key string, val interface{}) error

Lpush LPUSH []byte value to redis key list

func (*Pool) MDel

func (p *Pool) MDel(keys []string) error

batch del

func (*Pool) MGet

func (p *Pool) MGet(keys []string) (reply interface{}, err error)

func (*Pool) MSet

func (p *Pool) MSet(vals map[string]interface{}) error

BatchSet

func (*Pool) NewMutex

func (p *Pool) NewMutex(name string, options ...redsync.Option) *redsync.Mutex

func (*Pool) Ping

func (p *Pool) Ping() error

Set set []byte value to redis key

func (*Pool) Pool

func (p *Pool) Pool() *redis.Pool

Pool 获取redis连接池

func (*Pool) Rename

func (p *Pool) Rename(oldKey string, newKey string) error

RENAME

func (*Pool) RenameEx

func (p *Pool) RenameEx(oldKey string, newKey string) error

RENAMENX

func (*Pool) Rpop

func (p *Pool) Rpop(key string) (reply interface{}, err error)

Rpop RPOP []byte value from redis key list

func (*Pool) Scan

func (p *Pool) Scan(pattern string, count int64) ([]interface{}, error)

func (*Pool) Set

func (p *Pool) Set(key string, val interface{}) error

Set set []byte value to redis key

func (*Pool) SetEx

func (p *Pool) SetEx(key string, ttl int32, val interface{}) error

setex

func (*Pool) UnlockMutex

func (p *Pool) UnlockMutex(mutex *redsync.Mutex) (err error)

type RedisClient

type RedisClient interface {
	Close() error
	Ping() error
	Get(key string) (interface{}, error)
	MGet(keys []string) (interface{}, error)
	Set(key string, value interface{}) error
	SetEx(key string, ttl int32, value interface{}) error
	MSet(vals map[string]interface{}) error
	Del(key string) error
	MDel(keys []string) error
	INCR(key string, addValue int64) (int64, error)
	Expire(key string, ttl int32) error
	ExpireAt(key string, expireTime time.Time) error
	HSet(key string, field string, value interface{}) error
	HMSet(key string, fields map[string]interface{}) error
	HDel(key string, field string) error
	HMDel(key string, fields []string) (interface{}, error)
	HGet(key string, field string) (interface{}, error)
	HMGet(key string, fields []string) (interface{}, error)
	HGetall(key string) (interface{}, error)
	Hkeys(key string) (interface{}, error)
	HIncr(key string, field string, addValue int64) (int64, error)
	Keys(pattern string) (interface{}, error)
	Scan(pattern string, count int64) ([]interface{}, error)
	DoScript(keyCount int, src string, keysAndArgs ...interface{}) (interface{}, error)
	NewMutex(name string, options ...redsync.Option) *redsync.Mutex
	UnlockMutex(mutex *redsync.Mutex) error
	Rename(oldKey string, newKey string) error
	RenameEx(oldKey string, newKey string) error
	Lpush(key string, val interface{}) error
	Rpop(key string) (interface{}, error)
	Llen(key string) (int64, error)
}

func NewRedisClient

func NewRedisClient(conf *Config) (RedisClient, error)

type RedisMode

type RedisMode = string
const (
	ModeNormalDsn  RedisMode = "NormalDsn"
	ModeNormalAddr RedisMode = "NormalAddr"
	ModeSentinel   RedisMode = "Sentinel"
)

type Sentinel

type Sentinel struct {
	Addrs          []string
	MasterName     string
	Password       string        // sentinel密码
	ConnectTimeout time.Duration `default:"3s"`
	ReadTimeout    time.Duration `default:"3s"`
	WriteTimeout   time.Duration `default:"3s"`
}

Jump to

Keyboard shortcuts

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