redisc

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: MIT Imports: 9 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config added in v0.4.1

type Config struct {
	// DriverName set it to register to cache manager.
	DriverName string `yaml:"driverName" json:"driverName"`
	UseStats   bool   `yaml:"stats" json:"stats"`
}

type Option added in v0.1.0

type Option func(*Redisc)

func WithRedisClient added in v0.1.0

func WithRedisClient(cli redis.UniversalClient) Option

type Redisc

type Redisc struct {
	Config
	// contains filtered or unexported fields
}

Redisc is a cache implementation of redis.

if you want to register to cache manager, set a `driverName` in configuration

func New

func New(cfg *conf.Configuration, opts ...Option) (*Redisc, error)

New creates a new redis cache with the provided configuration.

Cache Configuration:

driverName: redis # optional, default is redis
addrs: # required
db: 0
... # other redis configuration
local: # local cache,optional, default is nil
  size: 1000 # optional, default is 1000
  samples: 100000 # optional, default is 100000
  ttl: 1m # optional, default is 1m

If you want to register to cache manager, set a `driverName` in configuration.

func (*Redisc) Apply

func (cd *Redisc) Apply(cnf *conf.Configuration) (err error)

Apply conf.configurable

func (*Redisc) CleanLocalCache added in v0.3.0

func (cd *Redisc) CleanLocalCache()

func (*Redisc) Del

func (cd *Redisc) Del(ctx context.Context, key string) error

Del deletes the given key.

func (*Redisc) DeleteFromLocalCache added in v0.3.0

func (cd *Redisc) DeleteFromLocalCache(key string)

func (*Redisc) Get

func (cd *Redisc) Get(ctx context.Context, key string, v any, opts ...cache.Option) error

Get returns the value associated with the given key.

func (*Redisc) Group added in v0.3.0

func (cd *Redisc) Group(ctx context.Context, key string, v any, opt *cache.Options) error

Group is a method use singleflight to get value

func (*Redisc) Has

func (cd *Redisc) Has(ctx context.Context, key string) bool

Has returns true if the given key exists.

func (*Redisc) IsNotFound

func (cd *Redisc) IsNotFound(err error) bool

IsNotFound returns true if the error is cache.ErrCacheMiss.

func (*Redisc) LocalCacheEnabled added in v0.1.0

func (cd *Redisc) LocalCacheEnabled() bool

LocalCacheEnabled returns true if local cache is enabled.

func (*Redisc) RedisClient

func (cd *Redisc) RedisClient() redis.Cmdable

RedisClient returns the underlying redis client.

func (*Redisc) Register

func (cd *Redisc) Register() error

Register cache to cache manager

func (*Redisc) Set

func (cd *Redisc) Set(ctx context.Context, key string, v any, opts ...cache.Option) error

Set sets the value associated with the given key. if ttl < 0 ,will not save to redis,but save to local cache if enabled

func (*Redisc) Stats added in v0.3.0

func (cd *Redisc) Stats() *cache.Stats

Jump to

Keyboard shortcuts

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