redis_client

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: Apache-2.0 Imports: 13 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RedisConn       = "REDIS_CONN"
	RedisConnFail   = "REDIS_CONN_FAIL"
	RedisAuthFail   = "REDIS_AUTH_FAIL"
	RedisExpire     = "REDIS_EXPIRE"
	RedisExpireFail = "REDIS_EXPIRE_FAIL"
	RedisSetex      = "REDIS_SETEX"
	RedisSetexFail  = "REDIS_SETEX_FAIL"
	RedisGet        = "REDIS_GET"
	RedisGetFail    = "REDIS_GET_FAIL"
	RedisGetMiss    = "REDIS_GET_MISS"
	RedisGetHit     = "REDIS_GET_HIT"
	RedisIncr       = "REDIS_INCR"
	RedisIncrFail   = "REDIS_INCR_FAIL"
	RedisDecr       = "REDIS_DECR"
	RedisDecrFail   = "REDIS_DECR_FAIL"
	RedisSendFail   = "REDIS_SEND_FAIL"
	RedisFlushFail  = "REDIS_FLUSH_FAIL"
)

counters for module state 2

View Source
var (
	// default bns update interval 10s
	DfBnsUpdateInterval = 60 * time.Second
	// max value for one redis cluster weight
	MaxWeightValue = 100
	// min value for one redis cluster weight
	MinWeightValue = 1
	// max value for all redis clusters weight sum
	MaxWeightSum = 10000

	RedisGetBnsInstanceErr  = "REDIS_GET_BNS_INSTANCE_ERR"
	RedisNoBnsInstance      = "REDIS_NO_BNS_INSTANCE"
	RedisBnsInstanceChanged = "REDIS_BNS_INSTANCE_CHANGED"
)

Functions

func CheckRedisConf

func CheckRedisConf(redisServersStr string) error

Types

type Client

type Client interface {
	Setex(key string, value []byte, expire int) error
	Get(key string) (interface{}, error)
	Expire(key string, expire int) error
	Incr(key string) (int64, error)
	IncrAndExpire(key string, expire int) (int64, error)
	Decr(key string) (int64, error)
	PIncr([]string) ([]int64, error)
	GetInt64(key string) (int64, error)
	IncrBy(key string, delta int64) (int64, error)
}

Client: redis client interface

func NewRedisClient

func NewRedisClient(options *Options) Client

type Options

type Options struct {
	// ServiceConf: string, bns name or a batch of bns name with weight of redis server
	ServiceConf string

	// MaxIdle: int, max idle connections in connection pool
	MaxIdle int
	// MaxActive: int, max active connections in connection pool
	MaxActive int
	// wait: bool, if wait is true and pool at the maxActive limit,
	// command waits for a connection return to the pool
	Wait bool
	// ConnTimeoutMs: int, connect redis server timeout, in ms
	ConnTimeoutMs int
	// ReadTimeoutMs: int, read redis server timeout, in ms
	ReadTimeoutMs int
	// writeTimeoutMs: int, write redis server timeout, in ms
	WriteTimeoutMs int
	Password       string
	// contains filtered or unexported fields
}

func (*Options) Format

func (opts *Options) Format() error

type RedisClient

type RedisClient struct {
	ConnectTimeout time.Duration // connect timeout (ms)
	ReadTimeout    time.Duration // read timeout (ms)
	WriteTimeout   time.Duration // write timeout (ms)

	Password string // password, ignore if no password

	MaxIdle   int  // max idle conenctions in pool
	MaxActive int  // max active connections in pool
	Wait      bool // if pool meet MaxActive limit, and Wait is true, wait for a connection return to pool
	// contains filtered or unexported fields
}

func NewRedisBnsClient

func NewRedisBnsClient(opts *Options) *RedisClient

NewRedisBnsClient(): create a new redisClient with bns support Notice:

  • if resolve bns error, c.Servers will be empty.

Returns:

  • *redisClient: a new redis client

func NewRedisClient1

func NewRedisClient1(serviceConf string, maxIdle int, ct, rt, wt int) *RedisClient

NewRedisClient(): create a new redisClient with bns support Notice:

  • if resolve bns error, c.Servers will be empty.

Params:

  • serviceConf: string, bns name or a batch of bns name with weight of redis server
  • maxIdle: int, max idle connections in connection pool
  • ct: int, connect redis server timeout, in ms
  • rt: int, read redis server timeout, in ms
  • wt: int, write redis server timeout, in ms

Returns:

  • *redisClient: a new redis client

func NewRedisClient2

func NewRedisClient2(serviceConf string, maxIdle, maxActive int, wait bool, ct, rt, wt int) *RedisClient

NewRedisClient2(): create a new redisClient with bns support Notice:

  • if resolve bns error, c.Servers will be empty.

Params:

  • serviceConf: string, bns name or a batch of bns name with weight of redis server
  • maxIdle: int, max idle connections in connection pool
  • maxActive: int, max active connections in connection pool
  • wait: bool, if wait is true and pool at the maxActive limit, command waits for a connection return to the pool
  • ct: int, connect redis server timeout, in ms
  • rt: int, read redis server timeout, in ms
  • wt: int, write redis server timeout, in ms

Returns:

  • *redisClient: a new redis client

func (*RedisClient) ActiveConnNum

func (c *RedisClient) ActiveConnNum() int

ActiveConnNum returns the num of active connextions

func (*RedisClient) Decr

func (c *RedisClient) Decr(key string) (int64, error)

decr key to redis

func (*RedisClient) Expire

func (c *RedisClient) Expire(key string, expire int) error

set expire to redis

func (*RedisClient) Get

func (c *RedisClient) Get(key string) (interface{}, error)

get value from redis

func (*RedisClient) GetInt64

func (c *RedisClient) GetInt64(key string) (int64, error)

get value from redis

func (*RedisClient) Incr

func (c *RedisClient) Incr(key string) (int64, error)

incr key to redis

func (*RedisClient) IncrAndExpire

func (c *RedisClient) IncrAndExpire(key string, expire int) (int64, error)

incr and expire key to redis

func (*RedisClient) IncrBy

func (c *RedisClient) IncrBy(key string, delta int64) (int64, error)

incr key to redis

func (*RedisClient) PIncr

func (c *RedisClient) PIncr(keyList []string) ([]int64, error)

PIncr incr keys in pipeline mode, seprate keyList by clusterId and do pincr concurrently

func (*RedisClient) SetConnDelay

func (c *RedisClient) SetConnDelay(delayCounter *delay_counter.DelayRecent)

set conn delay counter to redisClient

func (*RedisClient) SetDelay

func (c *RedisClient) SetDelay(delayCounter *delay_counter.DelayRecent)

set delay counter to redisClient

func (*RedisClient) SetModuleState2

func (c *RedisClient) SetModuleState2(state *module_state2.State)

set state of module_state2 to redisClient

func (*RedisClient) Setex

func (c *RedisClient) Setex(key string, value []byte, expire int) (err error)

Setex(): save key:value to redis server, and set expire time Params:

  • key: string
  • value: []byte
  • expire: int, expire time in second

Returns:

  • nil, if success, otherwise return error

save sessionState to session cache

type RedisClusterConf

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

func ParseRedisBnsConf

func ParseRedisBnsConf(serviceConfRawStr string) ([]RedisClusterConf, error)

Jump to

Keyboard shortcuts

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