Documentation
¶
Index ¶
- func Rand() string
- func RandId() string
- func Randn(n int) string
- func Seed(seed int64)
- type Client
- func (r *Client) Get(ctx context.Context, key string) (res string, err error)
- func (r *Client) HSetFromStruct(ctx context.Context, key string, data interface{}) *redis.IntCmd
- func (r *Client) HSetFromStructByPip(ctx context.Context, pip *redis.Pipeliner, key string, data interface{}) *redis.IntCmd
- func (r *Client) WrapDoWithTracing(ctx context.Context, spanName string, ...)
- type Config
- type Locker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client struct {
redis.UniversalClient
}
func (*Client) HSetFromStruct ¶
HSetFromStruct 把struct按hash结构存入redis
func (*Client) HSetFromStructByPip ¶
func (r *Client) HSetFromStructByPip(ctx context.Context, pip *redis.Pipeliner, key string, data interface{}) *redis.IntCmd
HSetFromStructByPip 使用pipeline把struct按hash结构存入redis
func (*Client) WrapDoWithTracing ¶
func (r *Client) WrapDoWithTracing(ctx context.Context, spanName string, fn func(ctx context.Context, span trace.Span) error)
WrapDoWithTracing 使用链路追踪
@spanName: 链路名称
@fn: func(ctx context.Context, span trace.Span)
example:
cli.WrapDoWithTracing(context.Background(), "redis.Get", func(ctx context.Context, span trace.Span) { r, err := cli.Get(ctx, "KEY") if err != nil { logger.GetLogger().Error(ctx, "redis.Get error", err) span.RecordError(err) return } t.Log("result:", r) })
type Locker ¶
type Locker struct { IsDebug bool // contains filtered or unexported fields }
A Locker is a redis lock.
func NewRedisLock ¶
NewRedisLock returns a Locker.
func NewRedisLockWithContext ¶
NewRedisLockWithContext returns a Locker.
func (*Locker) Acquire ¶
Acquire acquires the lock.
在获取锁之前可调用SetExpire()设置锁时间,默认锁10s
@repeat 重试次数,默认不重试
@wait 重试(repeat>1)时,重试的间隔时间 默认10ms
func (*Locker) AcquireBackoff ¶
AcquireBackoff acquires the lock using 指数退避策略.
在获取锁之前可调用SetExpire()设置锁时间,默认锁10s
@repeat 重试次数,默认不重试
@baseDelay 重试(repeat>1)时,基础延迟时间
@maxDelay 重试(repeat>0)时,最大延迟时间,默认10ms
Click to show internal directories.
Click to hide internal directories.