redis

package
v0.0.40 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2021 License: MIT Imports: 15 Imported by: 2

Documentation

Index

Constants

View Source
const (
	DefaultMinIdleConns = 10
	DefaultPoolSize     = 10
	DefaultDialTimeout  = 5 * time.Second
	DefaultReadTimeout  = 5 * time.Second
	DefaultWriteTimeout = 5 * time.Second
	DefaultMasterName   = "mymaster"
)

Default values for Redis.

Variables

View Source
var File_pkg_database_redis_redis_proto protoreflect.FileDescriptor

Functions

func GetDB

func GetDB() *redis.Client

func GetValue added in v0.0.34

func GetValue(ctx context.Context, db *redis.Client, key string) ([]string, error)

func GetValues added in v0.0.34

func GetValues(ctx context.Context, db *redis.Client, keys ...string) ([][]string, error)

func HSetStruct added in v0.0.34

func HSetStruct(ctx context.Context, db *redis.Client, key string, arg interface{}) error

only get export Fields from arg set tag-values for field-value to hash

Types

type CompletedConfig added in v0.0.34

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

func (CompletedConfig) New added in v0.0.34

func (c CompletedConfig) New(ctx context.Context) (*redis.Client, error)

type Config

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

func NewConfig added in v0.0.34

func NewConfig(options ...ConfigOption) *Config

func (*Config) ApplyOptions added in v0.0.34

func (o *Config) ApplyOptions(options ...ConfigOption) *Config

func (*Config) Complete added in v0.0.34

func (c *Config) Complete() CompletedConfig

Complete set default ServerRunOptions.

type ConfigOption added in v0.0.34

type ConfigOption interface {
	// contains filtered or unexported methods
}

A ConfigOption sets options.

func WithViper added in v0.0.34

func WithViper(v *viper.Viper) ConfigOption

type ConfigOptionFunc added in v0.0.34

type ConfigOptionFunc func(*Config)

ConfigOptionFunc wraps a function that modifies Client into an implementation of the ConfigOption interface.

type DBConfig added in v0.0.34

type DBConfig struct {
	Addresses []string
	UserName  string
	Password  string
	DB        int
}

type EmptyConfigOption added in v0.0.34

type EmptyConfigOption struct{}

EmptyConfigOption does not alter the configuration. It can be embedded in another structure to build custom options.

This API is EXPERIMENTAL.

type EmptyRedisOption

type EmptyRedisOption struct{}

EmptyRedisUrlOption does not alter the Redisuration. It can be embedded in another structure to build custom options.

This API is EXPERIMENTAL.

type Redis added in v0.0.34

type Redis struct {
	Enabled bool `protobuf:"varint,1,opt,name=enabled,proto3" json:"enabled,omitempty"`
	// Either a single address or a seed list of host:port addresses
	// of cluster/sentinel nodes.
	Addresses []string `protobuf:"bytes,2,rep,name=addresses,proto3" json:"addresses,omitempty"`
	// Database to be selected after connecting to the server.
	// Only single-node and failover clients.
	Db int64 `protobuf:"varint,3,opt,name=db,proto3" json:"db,omitempty"`
	// Use the specified Username to authenticate the current connection
	// with one of the connections defined in the ACL list when connecting
	// to a Redis 6.0 instance, or greater, that is using the Redis ACL system.
	Username string `protobuf:"bytes,4,opt,name=username,proto3" json:"username,omitempty"`
	// Optional password. Must match the password specified in the
	// requirepass server configuration option (if connecting to a Redis 5.0
	// instance, or lower), or the User Password when connecting to a Redis 6.0
	// instance, or greater, that is using the Redis ACL system.
	Password string `protobuf:"bytes,5,opt,name=password,proto3" json:"password,omitempty"`
	// Maximumumber of retries before giving up.
	// Default is 3 retries.
	MaxRetries int64 `protobuf:"varint,7,opt,name=max_retries,json=maxRetries,proto3" json:"max_retries,omitempty"`
	// Minimum backoff between each retry.
	// Default is 8 milliseconds; -1 disables backoff.
	MinRetryBackoff *duration.Duration `protobuf:"bytes,8,opt,name=min_retry_backoff,json=minRetryBackoff,proto3" json:"min_retry_backoff,omitempty"`
	// Maximum backoff between each retry.
	// Default is 512 milliseconds; -1 disables backoff.
	MaxRetryBackoff *duration.Duration `protobuf:"bytes,9,opt,name=max_retry_backoff,json=maxRetryBackoff,proto3" json:"max_retry_backoff,omitempty"`
	// Dial timeout for establishing new connections.
	// Default is 5 seconds.
	DialTimeout *duration.Duration `protobuf:"bytes,10,opt,name=dial_timeout,json=dialTimeout,proto3" json:"dial_timeout,omitempty"`
	// Timeout for socket reads. If reached, commands will fail
	// with a timeout instead of blocking. Use value -1 for no timeout and 0 for
	// default. Default is 3 seconds.
	ReadTimeout *duration.Duration `protobuf:"bytes,11,opt,name=read_timeout,json=readTimeout,proto3" json:"read_timeout,omitempty"`
	// Timeout for socket writes. If reached, commands will fail
	// with a timeout instead of blocking.
	// Default is ReadTimeout.
	WriteTimeout *duration.Duration `protobuf:"bytes,12,opt,name=write_timeout,json=writeTimeout,proto3" json:"write_timeout,omitempty"`
	// Maximum number of socket connections.
	// Default is 10 connections per every available CPU as reported by
	// runtime.GOMAXPROCS.
	PoolSize int64 `protobuf:"varint,13,opt,name=pool_size,json=poolSize,proto3" json:"pool_size,omitempty"`
	// Minimum number of idle connections which is useful when establishing
	// new connection is slow.
	MinIdleConns int64 `protobuf:"varint,14,opt,name=min_idle_conns,json=minIdleConns,proto3" json:"min_idle_conns,omitempty"`
	// Connection age at which client retires (closes) the connection.
	// Default is to not close aged connections.
	MaxConnAge *duration.Duration `protobuf:"bytes,15,opt,name=max_conn_age,json=maxConnAge,proto3" json:"max_conn_age,omitempty"`
	// Amount of time client waits for connection if all connections
	// are busy before returning an error.
	// Default is ReadTimeout + 1 second.
	PoolTimeout *duration.Duration `protobuf:"bytes,16,opt,name=pool_timeout,json=poolTimeout,proto3" json:"pool_timeout,omitempty"`
	// Amount of time after which client closes idle connections.
	// Should be less than server's timeout.
	// Default is 5 minutes. -1 disables idle timeout check.
	IdleTimeout *duration.Duration `protobuf:"bytes,17,opt,name=idle_timeout,json=idleTimeout,proto3" json:"idle_timeout,omitempty"`
	// Frequency of idle checks made by idle connections reaper.
	// Default is 1 minute. -1 disables idle connections reaper,
	// but idle connections are still discarded by the client
	// if IdleTimeout is set.
	IdleCheckFrequency *duration.Duration `protobuf:"bytes,18,opt,name=idle_check_frequency,json=idleCheckFrequency,proto3" json:"idle_check_frequency,omitempty"`
	// Only cluster clients.
	MaxRedirects int64 `protobuf:"varint,19,opt,name=max_redirects,json=maxRedirects,proto3" json:"max_redirects,omitempty"`
	ReadOnly     bool  `protobuf:"varint,20,opt,name=read_only,json=readOnly,proto3" json:"read_only,omitempty"`
	// Allows routing read-only commands to the closest master or slave node.
	// This option only works with NewFailoverClusterClient.
	RouteByLatency bool `protobuf:"varint,21,opt,name=route_by_latency,json=routeByLatency,proto3" json:"route_by_latency,omitempty"`
	// Allows routing read-only commands to the random master or slave node.
	// This option only works with NewFailoverClusterClient.
	RouteRandomly bool `protobuf:"varint,22,opt,name=route_randomly,json=routeRandomly,proto3" json:"route_randomly,omitempty"` // Route all commands to slave read-only nodes.
	// The sentinel master name.
	// Only failover clients.
	// The master name.
	MasterName        string             `protobuf:"bytes,23,opt,name=master_name,json=masterName,proto3" json:"master_name,omitempty"`
	MaxWaitDuration   *duration.Duration `protobuf:"bytes,24,opt,name=max_wait_duration,json=maxWaitDuration,proto3" json:"max_wait_duration,omitempty"`
	FailAfterDuration *duration.Duration `protobuf:"bytes,25,opt,name=fail_after_duration,json=failAfterDuration,proto3" json:"fail_after_duration,omitempty"`
	// contains filtered or unexported fields
}

https://github.com/go-redis/redis/blob/ce40cd942a72c4a93f9025047e6fd3f510700ab3/options.go

func (*Redis) Descriptor deprecated added in v0.0.34

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

Deprecated: Use Redis.ProtoReflect.Descriptor instead.

func (*Redis) GetAddresses added in v0.0.34

func (x *Redis) GetAddresses() []string

func (*Redis) GetDb added in v0.0.34

func (x *Redis) GetDb() int64

func (*Redis) GetDialTimeout added in v0.0.34

func (x *Redis) GetDialTimeout() *duration.Duration

func (*Redis) GetEnabled added in v0.0.34

func (x *Redis) GetEnabled() bool

func (*Redis) GetFailAfterDuration added in v0.0.34

func (x *Redis) GetFailAfterDuration() *duration.Duration

func (*Redis) GetIdleCheckFrequency added in v0.0.34

func (x *Redis) GetIdleCheckFrequency() *duration.Duration

func (*Redis) GetIdleTimeout added in v0.0.34

func (x *Redis) GetIdleTimeout() *duration.Duration

func (*Redis) GetMasterName added in v0.0.34

func (x *Redis) GetMasterName() string

func (*Redis) GetMaxConnAge added in v0.0.34

func (x *Redis) GetMaxConnAge() *duration.Duration

func (*Redis) GetMaxRedirects added in v0.0.34

func (x *Redis) GetMaxRedirects() int64

func (*Redis) GetMaxRetries added in v0.0.34

func (x *Redis) GetMaxRetries() int64

func (*Redis) GetMaxRetryBackoff added in v0.0.34

func (x *Redis) GetMaxRetryBackoff() *duration.Duration

func (*Redis) GetMaxWaitDuration added in v0.0.34

func (x *Redis) GetMaxWaitDuration() *duration.Duration

func (*Redis) GetMinIdleConns added in v0.0.34

func (x *Redis) GetMinIdleConns() int64

func (*Redis) GetMinRetryBackoff added in v0.0.34

func (x *Redis) GetMinRetryBackoff() *duration.Duration

func (*Redis) GetPassword added in v0.0.34

func (x *Redis) GetPassword() string

func (*Redis) GetPoolSize added in v0.0.34

func (x *Redis) GetPoolSize() int64

func (*Redis) GetPoolTimeout added in v0.0.34

func (x *Redis) GetPoolTimeout() *duration.Duration

func (*Redis) GetReadOnly added in v0.0.34

func (x *Redis) GetReadOnly() bool

func (*Redis) GetReadTimeout added in v0.0.34

func (x *Redis) GetReadTimeout() *duration.Duration

func (*Redis) GetRouteByLatency added in v0.0.34

func (x *Redis) GetRouteByLatency() bool

func (*Redis) GetRouteRandomly added in v0.0.34

func (x *Redis) GetRouteRandomly() bool

func (*Redis) GetUsername added in v0.0.34

func (x *Redis) GetUsername() string

func (*Redis) GetWriteTimeout added in v0.0.34

func (x *Redis) GetWriteTimeout() *duration.Duration

func (*Redis) ProtoMessage added in v0.0.34

func (*Redis) ProtoMessage()

func (*Redis) ProtoReflect added in v0.0.34

func (x *Redis) ProtoReflect() protoreflect.Message

func (*Redis) Reset added in v0.0.34

func (x *Redis) Reset()

func (*Redis) String added in v0.0.34

func (x *Redis) String() string

type RedisClient

type RedisClient struct {
	Conf DBConfig
	// contains filtered or unexported fields
}

func NewRedisClient

func NewRedisClient(conf DBConfig, opts ...RedisOption) *RedisClient

func (*RedisClient) ApplyOptions

func (o *RedisClient) ApplyOptions(options ...RedisOption) *RedisClient

func (*RedisClient) Close added in v0.0.34

func (r *RedisClient) Close() error

func (*RedisClient) GetDatabaseUntil added in v0.0.34

func (r *RedisClient) GetDatabaseUntil(
	ctx context.Context,
	maxWaitInterval time.Duration, failAfter time.Duration) (*redis.Client, error)

func (*RedisClient) GetRedis

func (r *RedisClient) GetRedis(ctx context.Context) (*redis.Client, error)

type RedisDB

type RedisDB atomic.Value

func (*RedisDB) Load

func (m *RedisDB) Load() *redis.Client

func (*RedisDB) Store

func (m *RedisDB) Store(value *redis.Client)

type RedisOption

type RedisOption interface {
	// contains filtered or unexported methods
}

A RedisOption sets options.

func WithDialTimeout added in v0.0.34

func WithDialTimeout(dialTimeout time.Duration) RedisOption

func WithMasterName added in v0.0.34

func WithMasterName(masterName string) RedisOption

func WithMinIdleConnections added in v0.0.34

func WithMinIdleConnections(minIdleConns int) RedisOption

func WithPoolSize added in v0.0.34

func WithPoolSize(poolSize int) RedisOption

func WithReadTimeout added in v0.0.34

func WithReadTimeout(readTimeout time.Duration) RedisOption

func WithWriteTimeout added in v0.0.34

func WithWriteTimeout(writeTimeout time.Duration) RedisOption

type RedisOptionFunc

type RedisOptionFunc func(*RedisClient)

RedisOptionFunc wraps a function that modifies Redis into an implementation of the RedisOption interface.

Jump to

Keyboard shortcuts

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