client

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FakeClient

type FakeClient struct {
	Responses []FakeResponse
}

func (*FakeClient) Close

func (fc *FakeClient) Close() error

func (*FakeClient) RedisBGSave

func (fc *FakeClient) RedisBGSave(ctx context.Context) error

func (*FakeClient) RedisConfigGet

func (fc *FakeClient) RedisConfigGet(ctx context.Context, parameter string) ([]interface{}, error)

func (*FakeClient) RedisConfigSet

func (fc *FakeClient) RedisConfigSet(ctx context.Context, parameter, value string) error

func (*FakeClient) RedisDebugSleep

func (fc *FakeClient) RedisDebugSleep(ctx context.Context, duration time.Duration) error

WARNING: this command blocks for the duration

func (*FakeClient) RedisDo

func (fc *FakeClient) RedisDo(ctx context.Context, args ...interface{}) (interface{}, error)

func (*FakeClient) RedisInfo

func (fc *FakeClient) RedisInfo(ctx context.Context, section string) (string, error)

func (*FakeClient) RedisLastSave

func (fc *FakeClient) RedisLastSave(ctx context.Context) (int64, error)

func (*FakeClient) RedisRole

func (fc *FakeClient) RedisRole(ctx context.Context) (interface{}, error)

func (*FakeClient) RedisSet

func (fc *FakeClient) RedisSet(ctx context.Context, key string, value interface{}) error

func (*FakeClient) RedisSlaveOf

func (fc *FakeClient) RedisSlaveOf(ctx context.Context, host, port string) error

func (*FakeClient) SentinelDo

func (fc *FakeClient) SentinelDo(ctx context.Context, args ...interface{}) (interface{}, error)

func (*FakeClient) SentinelGetMasterAddrByName

func (fc *FakeClient) SentinelGetMasterAddrByName(ctx context.Context, shard string) ([]string, error)

func (*FakeClient) SentinelInfoCache

func (fc *FakeClient) SentinelInfoCache(ctx context.Context) (interface{}, error)

func (*FakeClient) SentinelMaster

func (fc *FakeClient) SentinelMaster(ctx context.Context, shard string) (*SentinelMasterCmdResult, error)

func (*FakeClient) SentinelMasters

func (fc *FakeClient) SentinelMasters(ctx context.Context) ([]interface{}, error)

func (*FakeClient) SentinelMonitor

func (fc *FakeClient) SentinelMonitor(ctx context.Context, name, host string, port string, quorum int) error

func (*FakeClient) SentinelPSubscribe

func (fc *FakeClient) SentinelPSubscribe(ctx context.Context, events ...string) (<-chan *redis.Message, func() error)

func (*FakeClient) SentinelPing

func (fc *FakeClient) SentinelPing(ctx context.Context) error

func (*FakeClient) SentinelSet

func (fc *FakeClient) SentinelSet(ctx context.Context, shard, parameter, value string) error

func (*FakeClient) SentinelSlaves

func (fc *FakeClient) SentinelSlaves(ctx context.Context, shard string) ([]interface{}, error)

type FakeResponse

type FakeResponse struct {
	InjectResponse func() interface{}
	InjectError    func() error
}

func NewPredefinedRedisFakeResponse

func NewPredefinedRedisFakeResponse(dictionary string, err error) FakeResponse

Some predefined responses used in many tests

type GoRedisClient

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

func MustNewFromConnectionString

func MustNewFromConnectionString(connectionString string) *GoRedisClient

func NewFromConnectionString

func NewFromConnectionString(connectionString string) (*GoRedisClient, error)

func NewFromOptions

func NewFromOptions(opt *redis.Options) *GoRedisClient

func (*GoRedisClient) Close

func (c *GoRedisClient) Close() error

func (*GoRedisClient) CloseRedis

func (c *GoRedisClient) CloseRedis() error

func (*GoRedisClient) CloseSentinel

func (c *GoRedisClient) CloseSentinel() error

func (*GoRedisClient) RedisBGSave

func (c *GoRedisClient) RedisBGSave(ctx context.Context) error

func (*GoRedisClient) RedisConfigGet

func (c *GoRedisClient) RedisConfigGet(ctx context.Context, parameter string) ([]interface{}, error)

func (*GoRedisClient) RedisConfigSet

func (c *GoRedisClient) RedisConfigSet(ctx context.Context, parameter, value string) error

func (*GoRedisClient) RedisDebugSleep

func (c *GoRedisClient) RedisDebugSleep(ctx context.Context, duration time.Duration) error

WARNING: this command blocks for the duration

func (*GoRedisClient) RedisDo

func (c *GoRedisClient) RedisDo(ctx context.Context, args ...interface{}) (interface{}, error)

func (*GoRedisClient) RedisInfo

func (c *GoRedisClient) RedisInfo(ctx context.Context, section string) (string, error)

func (*GoRedisClient) RedisLastSave

func (c *GoRedisClient) RedisLastSave(ctx context.Context) (int64, error)

func (*GoRedisClient) RedisRole

func (c *GoRedisClient) RedisRole(ctx context.Context) (interface{}, error)

func (*GoRedisClient) RedisSet

func (c *GoRedisClient) RedisSet(ctx context.Context, key string, value interface{}) error

func (*GoRedisClient) RedisSlaveOf

func (c *GoRedisClient) RedisSlaveOf(ctx context.Context, host, port string) error

func (*GoRedisClient) SentinelDo

func (c *GoRedisClient) SentinelDo(ctx context.Context, args ...interface{}) (interface{}, error)

func (*GoRedisClient) SentinelGetMasterAddrByName

func (c *GoRedisClient) SentinelGetMasterAddrByName(ctx context.Context, shard string) ([]string, error)

func (*GoRedisClient) SentinelInfoCache

func (c *GoRedisClient) SentinelInfoCache(ctx context.Context) (interface{}, error)

func (*GoRedisClient) SentinelMaster

func (c *GoRedisClient) SentinelMaster(ctx context.Context, shard string) (*SentinelMasterCmdResult, error)

func (*GoRedisClient) SentinelMasters

func (c *GoRedisClient) SentinelMasters(ctx context.Context) ([]interface{}, error)

func (*GoRedisClient) SentinelMonitor

func (c *GoRedisClient) SentinelMonitor(ctx context.Context, name, host string, port string, quorum int) error

func (*GoRedisClient) SentinelPSubscribe

func (c *GoRedisClient) SentinelPSubscribe(ctx context.Context, events ...string) (<-chan *redis.Message, func() error)

func (*GoRedisClient) SentinelPing

func (c *GoRedisClient) SentinelPing(ctx context.Context) error

func (*GoRedisClient) SentinelSet

func (c *GoRedisClient) SentinelSet(ctx context.Context, shard, parameter, value string) error

func (*GoRedisClient) SentinelSlaves

func (c *GoRedisClient) SentinelSlaves(ctx context.Context, shard string) ([]interface{}, error)

type RedisServerInfoCache

type RedisServerInfoCache struct {
	CacheAge time.Duration
	Info     map[string]string
}

type Role

type Role string

Role represents the role of a redis server within a shard

const (
	// Master is the master role in a shard. Under normal circumstances, only
	// a server in the shard can be master at a given time
	Master Role = "master"
	// Slave are servers within the shard that replicate data from the master
	// for data high availabilty purposes
	Slave Role = "slave"
	// Unknown represents a state in which the role of the server is still unknown
	Unknown Role = "unknown"
)

type SentinelInfoCache

type SentinelInfoCache map[string]map[string]RedisServerInfoCache

func (SentinelInfoCache) GetValue

func (sic SentinelInfoCache) GetValue(shard, runID, key string, maxCacheAge time.Duration) (string, error)

type SentinelMasterCmdResult

type SentinelMasterCmdResult struct {
	Name                  string `redis:"name"`
	IP                    string `redis:"ip"`
	Port                  int    `redis:"port"`
	RunID                 string `redis:"runid"`
	Flags                 string `redis:"flags"`
	LinkPendingCommands   int    `redis:"link-pending-commands"`
	LinkRefcount          int    `redis:"link-refcount"`
	LastPingSent          int    `redis:"last-ping-sent"`
	LastOkPingReply       int    `redis:"last-ok-ping-reply"`
	LastPingReply         int    `redis:"last-ping-reply"`
	DownAfterMilliseconds int    `redis:"down-after-milliseconds"`
	InfoRefresh           int    `redis:"info-refresh"`
	RoleReported          string `redis:"role-reported"`
	RoleReportedTime      int    `redis:"role-reported-time"`
	ConfigEpoch           int    `redis:"config-epoch"`
	NumSlaves             int    `redis:"num-slaves"`
	NumOtherSentinels     int    `redis:"num-other-sentinels"`
	Quorum                int    `redis:"quorum"`
	FailoverTimeout       int    `redis:"failover-timeout"`
	ParallelSyncs         int    `redis:"parallel-syncs"`
}

SentinelMasterCmdResult represents the output of the "sentinel master" command

type SentinelSlaveCmdResult

type SentinelSlaveCmdResult struct {
	Name                  string `redis:"name"`
	IP                    string `redis:"ip"`
	Port                  int    `redis:"port"`
	RunID                 string `redis:"runid"`
	Flags                 string `redis:"flags"`
	LinkPendingCommands   int    `redis:"link-pending-commands"`
	LinkRefcount          int    `redis:"link-refcount"`
	LastPingSent          int    `redis:"last-ping-sent"`
	LastOkPingReply       int    `redis:"last-ok-ping-reply"`
	LastPingReply         int    `redis:"last-ping-reply"`
	DownAfterMilliseconds int    `redis:"down-after-milliseconds"`
	InfoRefresh           int    `redis:"info-refresh"`
	RoleReported          string `redis:"role-reported"`
	RoleReportedTime      int    `redis:"role-reported-time"`
	MasterLinkDownTime    int    `redis:"master-link-down-time"`
	MasterLinkStatus      string `redis:"master-link-status"`
	MasterHost            string `redis:"master-host"`
	MasterPort            int    `redis:"master-port"`
	SlavePriority         int    `redis:"slave-priority"`
	SlaveReplOffset       int    `redis:"slave-repl-offset"`
}

SentinelSlaveCmdResult represents the output of the "sentinel slave" command

type TestableInterface

type TestableInterface interface {
	SentinelMaster(context.Context, string) (*SentinelMasterCmdResult, error)
	SentinelMasters(context.Context) ([]interface{}, error)
	SentinelGetMasterAddrByName(ctx context.Context, shard string) ([]string, error)
	SentinelSlaves(context.Context, string) ([]interface{}, error)
	SentinelMonitor(context.Context, string, string, string, int) error
	SentinelSet(context.Context, string, string, string) error
	SentinelPSubscribe(context.Context, ...string) (<-chan *redis.Message, func() error)
	SentinelInfoCache(context.Context) (interface{}, error)
	SentinelDo(context.Context, ...interface{}) (interface{}, error)
	SentinelPing(ctx context.Context) error
	RedisRole(context.Context) (interface{}, error)
	RedisConfigGet(context.Context, string) ([]interface{}, error)
	RedisConfigSet(context.Context, string, string) error
	RedisSlaveOf(context.Context, string, string) error
	RedisDebugSleep(context.Context, time.Duration) error
	RedisDo(context.Context, ...interface{}) (interface{}, error)
	RedisBGSave(context.Context) error
	RedisLastSave(context.Context) (int64, error)
	RedisSet(context.Context, string, interface{}) error
	RedisInfo(ctx context.Context, section string) (string, error)
	Close() error
}

TestableInterface is an interface that both the go-redis and the fake client implement. It's not intended to support client implementations other than go-redis, it just exists to be able to inject redis server responses through the use of the Fake client, for testing purposes.

func NewFakeClient

func NewFakeClient(responses ...FakeResponse) TestableInterface

Jump to

Keyboard shortcuts

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