gored

package
v2.0.15 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MinInterval = time.Second * 3
)

Variables

View Source
var (
	ErrInvalidDataType = errors.New("invalid data type")
	ErrNotFound        = errors.New("redis not found")
)
View Source
var DefaultOptions = func() redis.Options {
	return redis.Options{
		Addr:                  "127.0.0.1:6379",
		DB:                    0,
		MaxRetries:            3,
		DialTimeout:           time.Second,
		ReadTimeout:           time.Second * 3,
		WriteTimeout:          time.Second * 3,
		ContextTimeoutEnabled: true,
		PoolSize:              16,
		MinIdleConns:          1,
		MaxIdleConns:          2,
		MaxActiveConns:        10,
		ConnMaxIdleTime:       time.Second * 30,
		ConnMaxLifetime:       time.Second * 120,
	}
}

Functions

func Acquire

func Acquire(ctx context.Context, red *redis.Client, key string, lockSeconds int64) (intCmd *redis.IntCmd)

Acquire 加锁

func AcquireWithTimeout

func AcquireWithTimeout(timeout time.Duration, red *redis.Client, key string, lockSeconds int64) (intCmd *redis.IntCmd)

func DealCmdErr

func DealCmdErr(cmd Cmd) error

func GetItemWithCache

func GetItemWithCache[V msg.Value](ctx context.Context, red *redis.Client, key string, current, cacheSeconds int64, handler msg.Handler[V]) (item cache.Item, err error)

func GetItemWithCacheTimeout

func GetItemWithCacheTimeout[V msg.Value](timeout time.Duration, red *redis.Client, key string, current, cacheSeconds int64, handler msg.Handler[V]) (item cache.Item, err error)

func GetRedis

func GetRedis(key string) (red *redis.Client, err error)

GetRedis 从容器中随机取*redis.Client

func GetRedisWithIndex

func GetRedisWithIndex(key string, index int) (red *redis.Client, err error)

GetRedisWithIndex 根据索引从容器中取*redis.Client

func GetToken

func GetToken(ctx context.Context, red *redis.Client, key string, current int64, capacity, rate, reqNum, keyTimeoutSecond int) *redis.BoolCmd

func Release

func Release(ctx context.Context, red *redis.Client, key string, token int64) (intCmd *redis.IntCmd)

Release 释放锁

func ReleaseWithTimeout

func ReleaseWithTimeout(timeout time.Duration, red *redis.Client, key string, token int64) (intCmd *redis.IntCmd)

func SecondLimitByToken

func SecondLimitByToken(ctx context.Context, red *redis.Client, key string, limit int, reqNum, burst int) *redis.BoolCmd

func SetConf added in v2.0.5

func SetConf[T kind.RedisValue](c *Conf, key string, value T) (isNew bool, err error)

func SetRedis

func SetRedis(key string, options ...redis.Options)

SetRedis 将*redis.Client放入容器

func TimeoutDo added in v2.0.2

func TimeoutDo(timeout time.Duration, handler func(ctx context.Context))

Types

type Cmd

type Cmd interface {
	Err() error
}

type Conf added in v2.0.5

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

func NewConf added in v2.0.5

func NewConf(key string, interval time.Duration, red *redis.Client) *Conf

func NewConfWithOption added in v2.0.5

func NewConfWithOption(key string, interval time.Duration, opt redis.Options) *Conf

func (*Conf) Bool added in v2.0.5

func (c *Conf) Bool(key string, defaultValue bool) bool

func (*Conf) Del added in v2.0.15

func (c *Conf) Del(timeout time.Duration, key string) (delNum int64, err error)

func (*Conf) Float added in v2.0.5

func (c *Conf) Float(key string, defaultValue float64) float64

func (*Conf) GetAllRemote added in v2.0.14

func (c *Conf) GetAllRemote(timeout time.Duration) (value map[string]string, err error)

func (*Conf) GetRemote added in v2.0.14

func (c *Conf) GetRemote(timeout time.Duration, key string) (value string, err error)

func (*Conf) HashKey added in v2.0.15

func (c *Conf) HashKey() string

func (*Conf) Int added in v2.0.5

func (c *Conf) Int(key string, defaultValue int64) int64

func (*Conf) String added in v2.0.5

func (c *Conf) String(key, defaultValue string) string

func (*Conf) Uint added in v2.0.5

func (c *Conf) Uint(key string, defaultValue uint64) uint64

func (*Conf) Value added in v2.0.5

func (c *Conf) Value() map[string]string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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