gxredis

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2020 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

2017-08-12 11:57 Package gxredis provides a redis driver by sentinel ref: https://github.com/alexstocks/go-sentinel/blob/master/sentinel.go

Package gxredis is a generated protocol buffer package.

It is generated from these files:
	redis_meta.proto

It has these top-level messages:
	IPAddr
	Slave
	Instance
	RawInstance

Package gxredis is a generated protocol buffer package.

It is generated from these files:

redis_meta.proto

It has these top-level messages:

IPAddr
Slave
Instance
RawInstance

2017-08-12 11:57 Package gxredis provides a redis driver by sentinel ref: https://github.com/alexstocks/go-sentinel/blob/master/role.go

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidLengthRedisMeta = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowRedisMeta   = fmt.Errorf("proto: integer overflow")
)
View Source
var RedisRole_name = map[int32]string{
	0: "RR_Default",
	1: "RR_Master",
	2: "RR_Slave",
	3: "RR_Sentinel",
}
View Source
var RedisRole_value = map[string]int32{
	"RR_Default":  0,
	"RR_Master":   1,
	"RR_Slave":    2,
	"RR_Sentinel": 3,
}

Functions

func CheckRole

func CheckRole(c redis.Conn, redisRole RedisRole) bool

CheckRole 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 IPAddr

type IPAddr struct {
	IP   string `protobuf:"bytes,1,opt,name=IP,proto3" json:"IP,omitempty"`
	Port uint32 `protobuf:"varint,2,opt,name=Port,proto3" json:"Port,omitempty"`
}

TCPAddr represents the address of a TCP end point.

func (*IPAddr) Descriptor

func (*IPAddr) Descriptor() ([]byte, []int)

func (*IPAddr) Equal

func (this *IPAddr) Equal(that interface{}) bool

func (*IPAddr) GoString

func (this *IPAddr) GoString() string

func (*IPAddr) Marshal

func (m *IPAddr) Marshal() (dAtA []byte, err error)

func (*IPAddr) MarshalTo

func (m *IPAddr) MarshalTo(dAtA []byte) (int, error)

func (*IPAddr) ProtoMessage

func (*IPAddr) ProtoMessage()

func (*IPAddr) Reset

func (m *IPAddr) Reset()

func (*IPAddr) Size

func (m *IPAddr) Size() (n int)

func (*IPAddr) String

func (this *IPAddr) String() string

func (*IPAddr) TcpAddr

func (m *IPAddr) TcpAddr() *net.TCPAddr

func (*IPAddr) Unmarshal

func (m *IPAddr) Unmarshal(dAtA []byte) error

func (*IPAddr) Validate

func (this *IPAddr) Validate() error

func (*IPAddr) VerboseEqual

func (this *IPAddr) VerboseEqual(that interface{}) error

type Instance

type Instance struct {
	Name   string   `protobuf:"bytes,1,opt,name=Name,proto3" json:"Name,omitempty"`
	Master *IPAddr  `protobuf:"bytes,2,opt,name=Master" json:"Master,omitempty"`
	Slaves []*Slave `protobuf:"bytes,3,rep,name=Slaves" json:"Slaves,omitempty"`
}

func (*Instance) Descriptor

func (*Instance) Descriptor() ([]byte, []int)

func (*Instance) Equal

func (this *Instance) Equal(that interface{}) bool

func (*Instance) GoString

func (this *Instance) GoString() string

func (*Instance) Marshal

func (m *Instance) Marshal() (dAtA []byte, err error)

func (*Instance) MarshalTo

func (m *Instance) MarshalTo(dAtA []byte) (int, error)

func (*Instance) ProtoMessage

func (*Instance) ProtoMessage()

func (*Instance) Reset

func (m *Instance) Reset()

func (*Instance) Size

func (m *Instance) Size() (n int)

func (*Instance) String

func (this *Instance) String() string

func (*Instance) Unmarshal

func (m *Instance) Unmarshal(dAtA []byte) error

func (*Instance) Validate

func (this *Instance) Validate() error

func (*Instance) VerboseEqual

func (this *Instance) VerboseEqual(that interface{}) error

type MasterSwitchInfo

type MasterSwitchInfo struct {
	Name      string
	OldMaster IPAddr
	NewMaster IPAddr
}

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 RawInstance

type RawInstance struct {
	Name            string  `protobuf:"bytes,1,opt,name=Name,proto3" json:"Name,omitempty"`
	Addr            *IPAddr `protobuf:"bytes,2,opt,name=Addr" json:"Addr,omitempty"`
	Epoch           int32   `protobuf:"varint,3,opt,name=Epoch,proto3" json:"Epoch,omitempty"`
	Sdowntime       int32   `protobuf:"varint,4,opt,name=Sdowntime,proto3" json:"Sdowntime,omitempty"`
	FailoverTimeout int32   `protobuf:"varint,5,opt,name=FailoverTimeout,proto3" json:"FailoverTimeout,omitempty"`
	NotifyScript    string  `protobuf:"bytes,6,opt,name=NotifyScript,proto3" json:"NotifyScript,omitempty"`
}

func (*RawInstance) Descriptor

func (*RawInstance) Descriptor() ([]byte, []int)

func (*RawInstance) Equal

func (this *RawInstance) Equal(that interface{}) bool

func (*RawInstance) GoString

func (this *RawInstance) GoString() string

func (*RawInstance) Marshal

func (m *RawInstance) Marshal() (dAtA []byte, err error)

func (*RawInstance) MarshalTo

func (m *RawInstance) MarshalTo(dAtA []byte) (int, error)

func (*RawInstance) ProtoMessage

func (*RawInstance) ProtoMessage()

func (*RawInstance) Reset

func (m *RawInstance) Reset()

func (*RawInstance) Size

func (m *RawInstance) Size() (n int)

func (*RawInstance) String

func (this *RawInstance) String() string

func (*RawInstance) Unmarshal

func (m *RawInstance) Unmarshal(dAtA []byte) error

func (*RawInstance) Validate

func (this *RawInstance) Validate() error

func (*RawInstance) VerboseEqual

func (this *RawInstance) VerboseEqual(that interface{}) error

type RedisRole

type RedisRole int32
const (
	RR_Default  RedisRole = 0
	RR_Master   RedisRole = 1
	RR_Slave    RedisRole = 2
	RR_Sentinel RedisRole = 3
)

func (RedisRole) EnumDescriptor

func (RedisRole) EnumDescriptor() ([]byte, []int)

func (RedisRole) String

func (x RedisRole) String() string

type SdownInfo

type SdownInfo struct {
	Name string
	Addr IPAddr
	Role RedisRole
}

type Sentinel

type Sentinel struct {
	// Addrs is a slice with known Sentinel addresses.
	Addrs []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 NewSentinel

func NewSentinel(addrs []string) *Sentinel

func (*Sentinel) AddInstance

func (s *Sentinel) AddInstance(inst RawInstance) error

AddInstance adds a redis intance to sentinel to monitor it

func (*Sentinel) Close

func (s *Sentinel) Close() error

Close closes current connection to Sentinel.

func (*Sentinel) Discover

func (s *Sentinel) Discover(name string, excludeIPArray []string) 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) GetConn

func (s *Sentinel) GetConn(addr string) redis.Conn

func (*Sentinel) GetConnByRole

func (s *Sentinel) GetConnByRole(addr string, role RedisRole) (redis.Conn, error)

func (*Sentinel) GetInstanceNames

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

func (*Sentinel) GetInstances

func (s *Sentinel) GetInstances() ([]Instance, error)

GetInstances returns redis instances

func (*Sentinel) GetSentinels

func (s *Sentinel) GetSentinels() []string

GetSentinels retruns redis sentinels

func (*Sentinel) MakeMasterSwitchSentinelWatcher

func (s *Sentinel) MakeMasterSwitchSentinelWatcher() (*SentinelWatcher, error)

func (*Sentinel) MakeSdownSentinelWatcher

func (s *Sentinel) MakeSdownSentinelWatcher() (*SentinelWatcher, error)

func (*Sentinel) MasterAddr

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

MasterAddr returns an address of @name Redis master instance.

func (*Sentinel) RemoveInstance

func (s *Sentinel) RemoveInstance(name string) error

RemoveInstance removes a redis intance from sentinel

func (*Sentinel) SentinelAddrs

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

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

func (*Sentinel) SlaveAddrs

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

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

func (*Sentinel) Slaves

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

Slaves returns a slice with known slaves of master instance.

type SentinelWatcher

type SentinelWatcher struct {
	sync.Mutex
	sync.WaitGroup
	// contains filtered or unexported fields
}

func NewSentinelWatcher

func NewSentinelWatcher(redisChannel string, conn redis.PubSubConn) *SentinelWatcher

func (*SentinelWatcher) Close

func (s *SentinelWatcher) Close() error

func (*SentinelWatcher) Watch

func (s *SentinelWatcher) Watch() (<-chan interface{}, error)

type Slave

type Slave struct {
	Addr  *IPAddr `protobuf:"bytes,1,opt,name=Addr" json:"Addr,omitempty"`
	Flags string  `protobuf:"bytes,2,opt,name=Flags,proto3" json:"Flags,omitempty"`
}

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

func (*Slave) Address

func (s *Slave) Address() 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.

func (*Slave) Descriptor

func (*Slave) Descriptor() ([]byte, []int)

func (*Slave) Equal

func (this *Slave) Equal(that interface{}) bool

func (*Slave) GoString

func (this *Slave) GoString() string

func (*Slave) Marshal

func (m *Slave) Marshal() (dAtA []byte, err error)

func (*Slave) MarshalTo

func (m *Slave) MarshalTo(dAtA []byte) (int, error)

func (*Slave) ProtoMessage

func (*Slave) ProtoMessage()

func (*Slave) Reset

func (m *Slave) Reset()

func (*Slave) Size

func (m *Slave) Size() (n int)

func (*Slave) String

func (this *Slave) String() string

func (*Slave) Unmarshal

func (m *Slave) Unmarshal(dAtA []byte) error

func (*Slave) Validate

func (this *Slave) Validate() error

func (*Slave) VerboseEqual

func (this *Slave) VerboseEqual(that interface{}) error

Jump to

Keyboard shortcuts

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