redis

package
v0.0.0-...-a5319db Latest Latest
Warning

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

Go to latest
Published: May 27, 2024 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

View Source
const (
	REDIS_LOCK_TIMEOUT time.Duration = 10 * time.Second
	REDIS_LOCK_KEY     string        = "REDIS_LOCKS"
)

Variables

View Source
var ErrLockTimeout = errors.New("LockTimeout")

Functions

This section is empty.

Types

type Config

type Config struct {
	Addresses             []string `yaml:"address" json:"address" usage:"List of redis servers (127.0.0.1:6379). Default '127.0.0.1:6379'."`
	DB                    int      `` /* 132-byte string literal not displayed */
	Username              string   `yaml:"username" json:"username" usage:"Username is a user name for authentication."`
	Password              string   `yaml:"password" json:"password" usage:"Password is a password for authentication."`
	SentinelUsername      string   `yaml:"sentinel_username" json:"sentinel_username" usage:""`
	SentinelPassword      string   `yaml:"sentinel_password" json:"sentinel_password" usage:""`
	AllowSSL              bool     `yaml:"allow_ssl" json:"allow_ssl" usage:""`
	TLSServerName         string   `yaml:"tls_server_name" json:"tls_server_name" usage:""`
	TLSCert               string   `yaml:"tls_cert" json:"tls_cert" usage:""`
	TLSKey                string   `yaml:"tls_key" json:"tls_key" usage:""`
	MaxRetries            int      `yaml:"max_retries" json:"max_retries" usage:""`
	MinRetryBackoff       int      `yaml:"min_retry_backoff" json:"min_retry_backoff" usage:""`
	MaxRetryBackoff       int      `yaml:"max_retry_backoff" json:"max_retry_backoff" usage:""`
	DialTimeout           int      `yaml:"dial_timeout" json:"dial_timeout" usage:""`
	ReadTimeout           int      `yaml:"read_timeout" json:"read_timeout" usage:""`
	WriteTimeout          int      `yaml:"write_timeout" json:"write_timeout" usage:""`
	ContextTimeoutEnabled bool     `yaml:"context_timeout_enabled" json:"context_timeout_enabled" usage:""`
	PoolFIFO              bool     `yaml:"pool_fifo" json:"pool_fifo" usage:"PoolFIFO uses FIFO mode for each node connection pool GET/PUT (default LIFO)."`
	PoolSize              int      `yaml:"pool_size" json:"pool_size" usage:""`
	PoolTimeout           int      `yaml:"pool_timeout" json:"pool_timeout" usage:""`
	MinIdleConns          int      `yaml:"min_idle_conns" json:"min_idle_conns" usage:""`
	MaxIdleConns          int      `yaml:"max_idle_conns" json:"max_idle_conns" usage:""`
	ConnMaxIdleTime       int      `yaml:"conn_max_idle_time" json:"conn_max_idle_time" usage:""`
	ConnMaxLifetime       int      `yaml:"conn_max_life_time" json:"conn_max_life_time" usage:""`
	MaxRedirects          int      `yaml:"max_redirects" json:"max_redirects" usage:"Only cluster clients."`
	ReadOnly              bool     `yaml:"read_only" json:"read_only" usage:"Only cluster clients."`
	RouteByLatency        bool     `yaml:"route_by_latency" json:"route_by_latency" usage:"Only cluster clients."`
	RouteRandomly         bool     `yaml:"route_randomly" json:"route_randomly" usage:"Only cluster clients."`
	MasterName            string   `yaml:"master_name" json:"master_name" usage:"The sentinel master name.Only failover clients."`
	Prefix                string   `yaml:"prefix" json:"prefix" usage:"Prefix."`
}

func NewConfig

func NewConfig() *Config

func (*Config) Valid

func (c *Config) Valid() error

type DB

type DB interface {
	Close()
	Context() context.Context
	DB() redis.UniversalClient
	Prefix() string
	Namer(name string, subname ...string) string
	Lock(key string, timeout ...time.Duration) (bool, error)
	LockWithWaitting(ctx context.Context, key string, timeout ...time.Duration) error
	Unlock(key string) error
}

func Connect

func Connect(ctx context.Context, log *zap.Logger, c *Config) DB

type Redis

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

func (*Redis) Close

func (s *Redis) Close()

func (*Redis) Context

func (s *Redis) Context() context.Context

func (*Redis) DB

func (s *Redis) DB() redis.UniversalClient

func (*Redis) Lock

func (s *Redis) Lock(key string, timeout ...time.Duration) (bool, error)

func (*Redis) LockWithWaitting

func (s *Redis) LockWithWaitting(ctx context.Context, key string, timeout ...time.Duration) error

func (*Redis) Namer

func (s *Redis) Namer(name string, subname ...string) string

func (*Redis) Prefix

func (s *Redis) Prefix() string

func (*Redis) Unlock

func (s *Redis) Unlock(key string) error

Jump to

Keyboard shortcuts

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