Documentation ¶
Index ¶
- Constants
- Variables
- func Acquire(ctx context.Context, red *redis.Client, key string, lockSeconds int64) (intCmd *redis.IntCmd)
- func AcquireWithTimeout(timeout time.Duration, red *redis.Client, key string, lockSeconds int64) (intCmd *redis.IntCmd)
- func DealCmdErr(cmd Cmd) error
- func GetItemWithCache[V msg.Value](ctx context.Context, red *redis.Client, key string, ...) (item cache.Item, err error)
- func GetItemWithCacheTimeout[V msg.Value](timeout time.Duration, red *redis.Client, key string, ...) (item cache.Item, err error)
- func GetRedis(key string) (red *redis.Client, err error)
- func GetRedisWithIndex(key string, index int) (red *redis.Client, err error)
- func GetToken(ctx context.Context, red *redis.Client, key string, current int64, ...) *redis.BoolCmd
- func Release(ctx context.Context, red *redis.Client, key string, token int64) (intCmd *redis.IntCmd)
- func ReleaseWithTimeout(timeout time.Duration, red *redis.Client, key string, token int64) (intCmd *redis.IntCmd)
- func SecondLimitByToken(ctx context.Context, red *redis.Client, key string, limit int, ...) *redis.BoolCmd
- func SetConf[T kind.RedisValue](c *Conf, key string, value T) (isNew bool, err error)
- func SetRedis(key string, options ...redis.Options)
- func TimeoutDo(timeout time.Duration, handler func(ctx context.Context))
- type Cmd
- type Conf
- func (c *Conf) Bool(key string, defaultValue bool) bool
- func (c *Conf) Del(timeout time.Duration, key string) (delNum int64, err error)
- func (c *Conf) Float(key string, defaultValue float64) float64
- func (c *Conf) GetAllRemote(timeout time.Duration) (value map[string]string, err error)
- func (c *Conf) GetRemote(timeout time.Duration, key string) (value string, err error)
- func (c *Conf) HashKey() string
- func (c *Conf) Int(key string, defaultValue int64) int64
- func (c *Conf) String(key, defaultValue string) string
- func (c *Conf) Uint(key string, defaultValue uint64) uint64
- func (c *Conf) Value() map[string]string
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 DealCmdErr ¶
func GetItemWithCache ¶
func GetItemWithCacheTimeout ¶
func GetRedisWithIndex ¶
GetRedisWithIndex 根据索引从容器中取*redis.Client
func Release ¶
func Release(ctx context.Context, red *redis.Client, key string, token int64) (intCmd *redis.IntCmd)
Release 释放锁
func ReleaseWithTimeout ¶
func SecondLimitByToken ¶
Types ¶
Source Files ¶
Click to show internal directories.
Click to hide internal directories.