redis

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Addrs []string `envconfig:"REDIS_ADDRS"`

	// Database to be selected after connecting to the server.
	// Only single-node and failover clients.
	DB int `envconfig:"REDIS_DB"`

	Username string `envconfig:"REDIS_USERNAME"`
	Password string `envconfig:"REDIS_PASSWORD"`

	MaxRetries      int           `envconfig:"REDIS_MAX_RETRIES" default:"3"`
	MinRetryBackoff time.Duration `envconfig:"REDIS_MIN_RETRY_BACKOFF" default:"5s"`
	MaxRetryBackoff time.Duration `envconfig:"REDIS_MAX_RETRY_BACKOFF" default:"30s"`

	DialTimeout  time.Duration `envconfig:"REDIS_DIAL_TIMEOUT" default:"30s"`
	ReadTimeout  time.Duration `envconfig:"REDIS_READ_TIMEOUT" default:"30s"`
	WriteTimeout time.Duration `envconfig:"REDIS_WRITE_TIMEOUT" default:"30s"`

	PoolSize           int           `envconfig:"REDIS_POOL_SIZE"`
	MinIdleConns       int           `envconfig:"REDIS_MIN_IDLE_CONNS"`
	MaxConnAge         time.Duration `envconfig:"REDIS_MAX_CONN_AGE"`
	PoolTimeout        time.Duration `envconfig:"REDIS_POOL_TIMEOUT"`
	IdleTimeout        time.Duration `envconfig:"REDIS_IDLE_TIMEOUT"`
	IdleCheckFrequency time.Duration `envconfig:"REDIS_IDLE_CHECK_FREQUENCY"`

	MaxRedirects   int  `envconfig:"REDIS_MAX_REDIRECTS"`
	ReadOnly       bool `envconfig:"REDIS_READ_ONLY"`
	RouteByLatency bool `envconfig:"REDIS_ROUTE_BY_LATENCY"`
	RouteRandomly  bool `envconfig:"REDIS_ROUTE_RANDOMLY"`

	// The sentinel master name.
	// Only failover clients.
	MasterName string `envconfig:"REDIS_MASTER_NAME"`
}

Config holds Redis cache configuration.

func ReadConfigFromEnv added in v0.1.7

func ReadConfigFromEnv(opts ...config.ReadOption) Config

ReadConfigFromEnv read Redis configuration from environment variables.

type Option

type Option func(*Redis)

Option is Redis configuration option.

func FromConfig

func FromConfig(conf Config) Option

FromConfig is an option to configure the Redis cache from a custom config.

func FromEnv

func FromEnv(opts ...config.ReadOption) Option

FromEnv is an option to configure the Redis cache from environment variables.

func FromUniversalOptions

func FromUniversalOptions(opts *redis.UniversalOptions) Option

FromUniversalOptions is an option to configure Redis cache from the given options.

type Redis

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

Redis is an implementation of cache.Cacher using Redis.

func New

func New(opts ...Option) *Redis

New return a cacher using Redis.

func (*Redis) Delete

func (r *Redis) Delete(ctx context.Context, key string) error

Delete a value

func (*Redis) Get

func (r *Redis) Get(ctx context.Context, key string) ([]byte, error)

Get a value, return cache.ErrNotFound if key not found.

func (*Redis) Set

func (r *Redis) Set(ctx context.Context, key string, val []byte, opts ...cache.SetOption) error

Set a value

Jump to

Keyboard shortcuts

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