redisadapter

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSafeURL

func GetSafeURL(redisURL string) string

func NewRedisPool

func NewRedisPool(dial RedisDialer, config *RedisConfig) *redis.Pool

func RedisDial

func RedisDial(config *RedisConfig) (redis.Conn, error)

Types

type AddrStore

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

AddrStore stores the current proxy address locally. It sets the address in redis and watches the changes.

func NewAddrStore

func NewAddrStore(
	localAddrStore lockproxy.LocalAddrStore,
	redisDialer RedisDialer,
	redisPool *redis.Pool,
	addrKey string,
	retryInitialInterval time.Duration,
	retryMaxElapsedTime time.Duration,
	logger *logrus.Entry,
) *AddrStore

func (*AddrStore) Addr

func (s *AddrStore) Addr(ctx context.Context) string

func (*AddrStore) Refresh added in v0.3.0

func (s *AddrStore) Refresh(ctx context.Context) (addr string, err error)

func (*AddrStore) SetAddr

func (s *AddrStore) SetAddr(ctx context.Context, addr string) error

func (*AddrStore) Start added in v0.3.0

func (s *AddrStore) Start(ctx context.Context, onStarted func()) error

type Locker

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

func NewLocker

func NewLocker(
	redisPool *redis.Pool,
	lockKey string,
	lockTTL int,
	lockRetryDelay time.Duration,
	unlockTimeout time.Duration,
	retryInitialInterval time.Duration,
	retryMaxElapsedTime time.Duration,
	onLocked func(ctx context.Context) error,
	logger *logrus.Entry,
) *Locker

func (*Locker) Start

func (l *Locker) Start(ctx context.Context) error

type RedisAdapter

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

func NewRedisAdapter

func NewRedisAdapter(config *RedisConfig, logger *logrus.Entry) *RedisAdapter

func (*RedisAdapter) Close

func (a *RedisAdapter) Close() error

func (*RedisAdapter) GetLocker

func (a *RedisAdapter) GetLocker(onLocked func(ctx context.Context) error) (lockproxy.Locker, error)

func (*RedisAdapter) GetRemoteAddrStore added in v0.3.0

func (a *RedisAdapter) GetRemoteAddrStore(localAddrStore lockproxy.LocalAddrStore) (lockproxy.RemoteAddrStore, error)

func (*RedisAdapter) Init

func (a *RedisAdapter) Init(ctx context.Context) error

type RedisConfig

type RedisConfig struct {
	// RedisURL is an address of a Redis server.
	// (LOCKPROXY_REDISURL)
	RedisURL string `default:"redis://localhost:6379"`

	// RedisDialTimeout is the timeout for failing to establish a redis
	// connection.
	// (LOCKPROXY_REDISDIALTIMEOUT)
	RedisDialTimeout time.Duration `default:"10s"`

	// RedisDialKeepAliveTime is the time after which client pings the server to
	// see if the transport is alive.
	// (LOCKPROXY_REDISDIALKEEPALIVETIME)
	RedisDialKeepAliveTime time.Duration `default:"10s"`

	// RedisDialClientName is the name of the Redis client (useful for debugging
	// with Redis CLIENT LIST command).
	// (LOCKPROXY_REDISDIALCLIENTNAME)
	RedisDialClientName string `default:"lockproxy"`

	// RedisMaxIdle is the max amount of idle connections to Redis.
	// (LOCKPROXY_REDISMAXIDLE)
	RedisMaxIdle int `default:"10"`

	// RedisIdleTimeout is the duration after which the connections remaining idle
	// will be closed.
	// (LOCKPROXY_REDISIDLETIMEOUT)
	RedisIdleTimeout time.Duration `default:"5m"`

	// RedisLockTTL is the duration of the Redis lock (in seconds). The lock will
	// be refreshed every RedisLockTTL seconds.
	// (LOCKPROXY_REDISLOCKTTL)
	RedisLockTTL int `default:"10"`

	// RedisLockTTL is the duration of the Redis lock (in seconds). The lock will
	// be refreshed every RedisLockTTL seconds.
	// (LOCKPROXY_REDISLOCKTTL)
	RedisLockRetryDelay time.Duration `default:"100ms"`

	// RedisUnlockTimeout is the max duration for waiting etcd to unlock after the
	// Cmd is stopped.
	// (LOCKPROXY_REDISUNLOCKTIMEOUT)
	RedisUnlockTimeout time.Duration `default:"10s"`

	// RedisLockKey is the Redis key used for redis lock.
	// (LOCKPROXY_REDISLOCKKEY)
	RedisLockKey string `required:"true"`

	// RedisAddrKey is the Redis key used to store the address of the current
	// leader.
	// (LOCKPROXY_REDISADDRKEY)
	RedisAddrKey string `required:"true"`

	// RedisRetryInitialInterval is the initial delay for retrying.
	// (LOCKPROXY_REDISRETRYINITIALINTERVAL)
	RedisRetryInitialInterval time.Duration `default:"100ms"`

	// RedisRetryMaxElapsedTime is the max elapsed time for retrying.
	// (LOCKPROXY_REDISRETRYMAXELAPSEDTIME)
	RedisRetryMaxElapsedTime time.Duration `default:"10s"`
}

type RedisDialer

type RedisDialer func() (redis.Conn, error)

func NewRedisDialer

func NewRedisDialer(config *RedisConfig) RedisDialer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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