redis

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

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

Go to latest
Published: Sep 3, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TestRole

func TestRole(c redis.Conn, expectedRole string) bool

TestRole wraps GetRole in a test to verify if the role matches an expected role string. If there was any error in querying the supplied connection, the function returns false. Works with Redis >= 2.8.12. It's not goroutine safe, but if you call this method on pooled connections then you are OK.

Types

type NoSentinelsAvailable

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

NoSentinelsAvailable is returned when all sentinels in the list are exhausted (or none configured), and contains the last error returned by Dial (which may be nil)

func (NoSentinelsAvailable) Error

func (ns NoSentinelsAvailable) Error() string

type RedisPool

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

RedisPool Redis资源池结构体

func NewClusterPool

func NewClusterPool(cfg *RedisConfig) (*RedisPool, error)

func NewRedisPool

func NewRedisPool(cfg *StandAloneConfig) (*RedisPool, error)

func NewSentinelPool

func NewSentinelPool(cfg *SentinelConfig) (*RedisPool, error)

func (*RedisPool) Delete

func (r *RedisPool) Delete(key string) error

func (*RedisPool) Exist

func (r *RedisPool) Exist(key string) (bool, error)

func (*RedisPool) Get

func (r *RedisPool) Get(key string) (interface{}, error)

func (*RedisPool) GetBool

func (r *RedisPool) GetBool(key string) (bool, error)

func (*RedisPool) GetBytes

func (r *RedisPool) GetBytes(key string) ([]byte, error)

func (*RedisPool) GetFloat64

func (r *RedisPool) GetFloat64(key string) (float64, error)

func (*RedisPool) GetFloat64s

func (r *RedisPool) GetFloat64s(key string) ([]float64, error)

func (*RedisPool) GetInt

func (r *RedisPool) GetInt(key string) (int, error)

func (*RedisPool) GetInt64

func (r *RedisPool) GetInt64(key string) (int64, error)

func (*RedisPool) GetInt64Map

func (r *RedisPool) GetInt64Map(key string) (map[string]int64, error)

func (*RedisPool) GetInt64s

func (r *RedisPool) GetInt64s(key string) ([]int64, error)

func (*RedisPool) GetIntMap

func (r *RedisPool) GetIntMap(key string) (map[string]int, error)

func (*RedisPool) GetInts

func (r *RedisPool) GetInts(key string) ([]int, error)

func (*RedisPool) GetString

func (r *RedisPool) GetString(key string) (string, error)

func (*RedisPool) GetTTL

func (r *RedisPool) GetTTL(key string) (int, error)

func (*RedisPool) GetUint64

func (r *RedisPool) GetUint64(key string) (uint64, error)

func (*RedisPool) HDel

func (r *RedisPool) HDel(key string, field string) error

func (*RedisPool) HExist

func (r *RedisPool) HExist(key string, fields string) (bool, error)

func (*RedisPool) HGet

func (r *RedisPool) HGet(key string, field string) (interface{}, error)

func (*RedisPool) HGetAllMapInt

func (r *RedisPool) HGetAllMapInt(key string) (map[string]int, error)

func (*RedisPool) HGetAllMapInt64

func (r *RedisPool) HGetAllMapInt64(key string) (map[string]int64, error)

func (*RedisPool) HGetAllMapString

func (r *RedisPool) HGetAllMapString(key string) (map[string]string, error)

func (*RedisPool) HGetAllToStruct

func (r *RedisPool) HGetAllToStruct(key string, m *struct{}) error

func (*RedisPool) HGetBool

func (r *RedisPool) HGetBool(key, field string) (bool, error)

func (*RedisPool) HGetBytes

func (r *RedisPool) HGetBytes(key, field string) ([]byte, error)

func (*RedisPool) HGetFloat64

func (r *RedisPool) HGetFloat64(key, field string) (float64, error)

func (*RedisPool) HGetFloat64s

func (r *RedisPool) HGetFloat64s(key, field string) ([]float64, error)

func (*RedisPool) HGetInt

func (r *RedisPool) HGetInt(key, field string) (int, error)

func (*RedisPool) HGetInt64

func (r *RedisPool) HGetInt64(key, field string) (int64, error)

func (*RedisPool) HGetInt64Map

func (r *RedisPool) HGetInt64Map(key, field string) (map[string]int64, error)

func (*RedisPool) HGetInt64s

func (r *RedisPool) HGetInt64s(key, field string) ([]int64, error)

func (*RedisPool) HGetIntMap

func (r *RedisPool) HGetIntMap(key, field string) (map[string]int, error)

func (*RedisPool) HGetInts

func (r *RedisPool) HGetInts(key, field string) ([]int, error)

func (*RedisPool) HGetString

func (r *RedisPool) HGetString(key, field string) (string, error)

func (*RedisPool) HGetUint64

func (r *RedisPool) HGetUint64(key, field string) (uint64, error)

func (*RedisPool) HMSet

func (r *RedisPool) HMSet(key string, field string, value interface{}) error

func (*RedisPool) HMSetMapField

func (r *RedisPool) HMSetMapField(key string, fields map[string]interface{}) error

func (*RedisPool) HSet

func (r *RedisPool) HSet(key string, field string, value interface{}) error

func (*RedisPool) IsErrNil

func (r *RedisPool) IsErrNil(err error) bool

func (*RedisPool) LPop

func (r *RedisPool) LPop(key string) (interface{}, error)

func (*RedisPool) LPopBool

func (r *RedisPool) LPopBool(key string) (bool, error)

func (*RedisPool) LPopBytes

func (r *RedisPool) LPopBytes(key string) ([]byte, error)

func (*RedisPool) LPopFloat64

func (r *RedisPool) LPopFloat64(key string) (float64, error)

func (*RedisPool) LPopFloat64s

func (r *RedisPool) LPopFloat64s(key string) ([]float64, error)

func (*RedisPool) LPopInt

func (r *RedisPool) LPopInt(key string) (int, error)

func (*RedisPool) LPopInt64

func (r *RedisPool) LPopInt64(key string) (int64, error)

func (*RedisPool) LPopInt64Map

func (r *RedisPool) LPopInt64Map(key string) (map[string]int64, error)

func (*RedisPool) LPopInt64s

func (r *RedisPool) LPopInt64s(key string) ([]int64, error)

func (*RedisPool) LPopIntMap

func (r *RedisPool) LPopIntMap(key string) (map[string]int, error)

func (*RedisPool) LPopInts

func (r *RedisPool) LPopInts(key string) ([]int, error)

func (*RedisPool) LPopString

func (r *RedisPool) LPopString(key string) (string, error)

func (*RedisPool) LPopUint64

func (r *RedisPool) LPopUint64(key string) (uint64, error)

func (*RedisPool) LPush

func (r *RedisPool) LPush(key string, value interface{}) error

func (*RedisPool) Set

func (r *RedisPool) Set(key string, value interface{}) error

func (*RedisPool) SetTTL

func (r *RedisPool) SetTTL(key string, ttl int64) error

func (*RedisPool) SetWithTTL

func (r *RedisPool) SetWithTTL(key string, ttl int64, value interface{}) error

type Sentinel

type Sentinel struct {
	// Addrs is a slice with known Sentinel addresses.
	Addrs []string

	// MasterName is a name of Redis master Sentinel servers monitor.
	MasterName string

	// Dial is a user supplied function to connect to Sentinel on given address. This
	// address will be chosen from Addrs slice.
	// Note that as per the redis-sentinel client guidelines, a timeout is mandatory
	// while connecting to Sentinels, and should not be set to 0.
	Dial func(addr string) (redis.Conn, error)

	// Pool is a user supplied function returning custom connection pool to Sentinel.
	// This can be useful to tune options if you are not satisfied with what default
	// Sentinel pool offers. See defaultPool() method for default pool implementation.
	// In most cases you only need to provide Dial function and let this be nil.
	Pool func(addr string) *redis.Pool
	// contains filtered or unexported fields
}

func (*Sentinel) Close

func (s *Sentinel) Close() error

Close closes current connection to Sentinel.

func (*Sentinel) Discover

func (s *Sentinel) Discover() error

Discover allows to update list of known Sentinel addresses. From docs:

A client may update its internal list of Sentinel nodes following this procedure: 1) Obtain a list of other Sentinels for this master using the command SENTINEL sentinels <master-name>. 2) Add every ip:port pair not already existing in our list at the end of the list.

func (*Sentinel) MasterAddr

func (s *Sentinel) MasterAddr() (string, error)

MasterAddr returns an address of current Redis master instance.

func (*Sentinel) SentinelAddrs

func (s *Sentinel) SentinelAddrs() ([]string, error)

SentinelAddrs returns a slice of known Sentinel addresses Sentinel server aware of.

func (*Sentinel) SlaveAddrs

func (s *Sentinel) SlaveAddrs() ([]string, error)

SlaveAddrs returns a slice with known slave addresses of current master instance.

func (*Sentinel) Slaves

func (s *Sentinel) Slaves() ([]*Slave, error)

Slaves returns a slice with known slaves of master instance.

type SentinelConfig

type SentinelConfig struct {
	Cluster        []string //集群主机列表
	MasterName     string   //集群Master名字
	SentinelPass   string   //哨兵连接密码
	Authpass       string   //Redis连接密码
	KeepAlive      int64    //链接空闲超时时间,单位秒(s)
	MaxIdle        int      //最大空闲连接
	MaxActive      int      //最大活动连接
	ConnectTimeout int      //连接操作超时时间,单位毫秒(ms)
	ReadTimeout    int      //读操作超时时间,单位毫秒(ms)
	WriteTimeout   int      //写操作超时时间,单位毫秒(ms)
}

type Slave

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

Slave represents a Redis slave instance which is known by Sentinel.

func (*Slave) Addr

func (s *Slave) Addr() string

Addr returns an address of slave.

func (*Slave) Available

func (s *Slave) Available() bool

Available returns if slave is in working state at moment based on information in slave flags.

type StandAloneConfig

type StandAloneConfig struct {
	Host           string //单机模式地址
	Authpass       string //Redis连接密码
	KeepAlive      int64  //链接空闲超时时间,单位秒(s)
	MaxIdle        int    //最大空闲连接
	MaxActive      int    //最大活动连接
	ConnectTimeout int    //连接操作超时时间,单位毫秒(ms)
	ReadTimeout    int    //读操作超时时间,单位毫秒(ms)
	WriteTimeout   int    //写操作超时时间,单位毫秒(ms)
}

Jump to

Keyboard shortcuts

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