cache

package
v0.0.0-...-8e0263b Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrShotLimits = errors.New("error shot limits")
	ErrTypeError  = errors.New("wrong type")
)
View Source
var (
	MaxRetries       = 3
	DialTimeout      = 100 * time.Millisecond
	ReadWriteTimeout = 100 * time.Millisecond
	PoolSize         = 200
	PoolTimeout      = 100 * time.Millisecond
	IdleTimeout      = 60 * time.Minute
)

Functions

func Init

func Init(addr string)

func IsRedisNil

func IsRedisNil(err error) bool

Types

type Cache

type Cache struct {
	*redis.Client
}

func Client

func Client() *Cache

func NewClient

func NewClient(addr string) *Cache

func NewClientByRedisCli

func NewClientByRedisCli(cli *redis.Client) *Cache

func NewPrefixedCli

func NewPrefixedCli(prefix string) *Cache

func (*Cache) BatchGet

func (cli *Cache) BatchGet(ctx context.Context, shotLimit int, keys ...string) (valuesHit []string, keysMiss []string, err error)

func (*Cache) BatchSave

func (cli *Cache) BatchSave(ctx context.Context, forEachReceiver func(fn func(key, v string) error) error, expiration time.Duration) error

BatchSave save data to redis in batch

func (*Cache) PipeGet

func (cli *Cache) PipeGet(ctx context.Context, keys ...string) (valuesHit []string, keysMiss []string, err error)

PipeGet get values from redis by pipeline

func (*Cache) SingleFlightAPI

func (cli *Cache) SingleFlightAPI() SingleFlight

SingleFlightAPI

 usage:
 ```go
    sf := cli.SingleFlightAPI()
	for _, k := range keys {
	   go ... sf.Get(ctx, k) ...
	}
 ```

type H

type H map[string]any

type Prefix

type Prefix string

func (Prefix) AssembleCMD

func (p Prefix) AssembleCMD(cmd redis.Cmder) redis.Cmder

func (Prefix) ColonStr

func (p Prefix) ColonStr() string

func (Prefix) DialHook

func (p Prefix) DialHook(next redis.DialHook) redis.DialHook

func (Prefix) MakeKey

func (p Prefix) MakeKey(key string) string

func (Prefix) ProcessHook

func (p Prefix) ProcessHook(next redis.ProcessHook) redis.ProcessHook

func (Prefix) ProcessPipelineHook

func (p Prefix) ProcessPipelineHook(next redis.ProcessPipelineHook) redis.ProcessPipelineHook

func (Prefix) String

func (p Prefix) String() string

type SingleFlight

type SingleFlight struct {
	*Cache
	// contains filtered or unexported fields
}

func SingleFlightAPI

func SingleFlightAPI() SingleFlight

func (SingleFlight) Get

func (sf SingleFlight) Get(ctx context.Context, key string) (string, error)

Jump to

Keyboard shortcuts

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