redis

package module
v0.0.0-...-9bbb3dd Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package redis MIT License

# Copyright (c) 2024 go-fox Author https://github.com/go-fox/fox

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Package redis MIT License

# Copyright (c) 2024 go-fox Author https://github.com/go-fox/fox

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Package redis MIT License

# Copyright (c) 2024 go-fox Author https://github.com/go-fox/fox

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client = redis.UniversalClient

Client redis client

func New

func New(opts ...Option) Client

New create Client with option

func NewWithConfig

func NewWithConfig(configs ...*Config) Client

NewWithConfig create Client with Config

type Config

type Config struct {
	Address    []string `json:"address"`
	ClientName string   `json:"client_name"`
	// Database to be selected after connecting to the server.
	// Only single-node and failover clients.
	DB int `json:"db"`

	Dialer    func(ctx context.Context, network, addr string) (net.Conn, error) `json:"-"`
	OnConnect func(ctx context.Context, cn *redis.Conn) error                   `json:"-"`

	Protocol         int    `json:"protocol"`
	Username         string `json:"username"`
	Password         string `json:"password"`
	SentinelUsername string `json:"sentinel_username"`
	SentinelPassword string `json:"sentinel_password"`

	MaxRetries      int           `json:"max_retries"`
	MinRetryBackoff time.Duration `json:"min_retry_backoff"`
	MaxRetryBackoff time.Duration `json:"max_retry_backoff"`

	DialTimeout           config.Duration `json:"dial_timeout"`
	ReadTimeout           config.Duration `json:"read_timeout"`
	WriteTimeout          config.Duration `json:"write_timeout"`
	ContextTimeoutEnabled bool            `json:"context_timeout_enabled"`

	// PoolFIFO uses FIFO mode for each node connection pool GET/PUT (default LIFO).
	PoolFIFO bool `json:"pool_fifo"`

	PoolSize        int             `json:"pool_size"`
	PoolTimeout     config.Duration `json:"pool_timeout"`
	MinIdleConns    int             `json:"min_idle_conns"`
	MaxIdleConns    int             `json:"max_idle_conns"`
	MaxActiveConns  int             `json:"max_active_conns"`
	ConnMaxIdleTime config.Duration `json:"conn_max_idle_time"`
	ConnMaxLifetime config.Duration `json:"conn_max_lifetime"`

	// TLS config
	TLSConfig *tls.Config `json:"-"`
	CertFile  string      `json:"cert_file"`
	KeyFile   string      `json:"key_file"`

	MaxRedirects   int  `json:"max_redirects"`
	ReadOnly       bool `json:"read_only"`
	RouteByLatency bool `json:"route_by_latency"`
	RouteRandomly  bool `json:"route_randomly"`

	MasterName string `json:"master_name"`

	DisableIndentity bool   `json:"disable_indentity"`
	IdentitySuffix   string `json:"identity_suffix"`
}

Config redis config

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig default config

func RawConfig

func RawConfig(key string) *Config

RawConfig scan config key to Config value

func ScanConfig

func ScanConfig(names ...string) *Config

ScanConfig scan config name to Config value

func (*Config) Build

func (c *Config) Build() Client

Build create a redis client with this config

func (*Config) WithOption

func (c *Config) WithOption(opts ...Option) *Config

WithOption apply option

type Option

type Option func(c *Config)

Option create a redis client option

func WithAddress

func WithAddress(address []string) Option

WithAddress with a redis address option

func WithClientName

func WithClientName(clientName string) Option

WithClientName with a redis client name option

func WithConnMaxIdleTime

func WithConnMaxIdleTime(connMaxIdleTime time.Duration) Option

WithConnMaxIdleTime with a redis conn max idle time option

func WithConnMaxLifetime

func WithConnMaxLifetime(connMaxLifetime time.Duration) Option

WithConnMaxLifetime with a redis conn max lifet time option

func WithContextTimeoutEnabled

func WithContextTimeoutEnabled(contextTimeoutEnabled bool) Option

WithContextTimeoutEnabled with a context timout enable

func WithDB

func WithDB(db int) Option

WithDB Database to be selected after connecting to the server. Only single-node and failover clients.

func WithDialTimeout

func WithDialTimeout(dialTimeout time.Duration) Option

WithDialTimeout with a redis clint dial timeout option

func WithDialer

func WithDialer(dialer func(ctx context.Context, network, addr string) (net.Conn, error)) Option

WithDialer with a client Dialer option

func WithMMaxIdleConns

func WithMMaxIdleConns(maxIdleConns int) Option

WithMMaxIdleConns with a redis client MaxIdleConns option

func WithMasterName

func WithMasterName(masterName string) Option

WithMasterName with MasterName option

func WithMaxActiveConns

func WithMaxActiveConns(maxActiveConns int) Option

WithMaxActiveConns with a redis client MaxActiveConns option

func WithMaxRedirects

func WithMaxRedirects(maxRedirects int) Option

WithMaxRedirects with a redis client MaxRedirects option

func WithMaxRetries

func WithMaxRetries(maxRetries int) Option

WithMaxRetries with a redis client max retries

func WithMaxRetryBackoff

func WithMaxRetryBackoff(maxRetryBackoff time.Duration) Option

WithMaxRetryBackoff with a redis client MaxRetryBackoff option

func WithMinIdleConns

func WithMinIdleConns(minIdleConns int) Option

WithMinIdleConns with a redis client minIdleConns

func WithMinRetryBackoff

func WithMinRetryBackoff(minRetryBackoff time.Duration) Option

WithMinRetryBackoff with a redis client MinRetryBackoff option

func WithOnConnect

func WithOnConnect(onConnect func(ctx context.Context, cn *redis.Conn) error) Option

WithOnConnect with a client connect callback option

func WithPassword

func WithPassword(password string) Option

WithPassword with a redis password option

func WithPoolSize

func WithPoolSize(poolSize int) Option

WithPoolSize with a redis client pool size option

func WithProtocol

func WithProtocol(protocol int) Option

WithProtocol with a client protocol option

func WithReadOnly

func WithReadOnly(readOnly bool) Option

WithReadOnly with a redis client readOnly option

func WithReadTimeout

func WithReadTimeout(readTimeout time.Duration) Option

WithReadTimeout with a redis client read timeout option

func WithRouteByLatency

func WithRouteByLatency(routeByLatency bool) Option

WithRouteByLatency with a redis client RouteByLatency option

func WithRouteRandomly

func WithRouteRandomly(routeRandomly bool) Option

WithRouteRandomly with a redis client RouteByLatency option

func WithSentinelPassword

func WithSentinelPassword(sentinelUsername string) Option

WithSentinelPassword with a redis SentinelPassword option

func WithSentinelUsername

func WithSentinelUsername(sentinelUsername string) Option

WithSentinelUsername with a redis SentinelUsername option

func WithTLSConfig

func WithTLSConfig(tLSConfig *tls.Config) Option

WithTLSConfig with tls.Config option

func WithTLSFile

func WithTLSFile(certFile, keyFile string) Option

WithTLSFile with TLS file path option

func WithUsername

func WithUsername(username string) Option

WithUsername with a redis client username option

func WithWriteTimeout

func WithWriteTimeout(writeTimeout time.Duration) Option

WithWriteTimeout with a redis client writeTimeout option

Jump to

Keyboard shortcuts

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