Skip to content

Import path: gitlab.soludian.com/soludian/fountain/libs/cache/redis_cache

redis_cache

go
import "gitlab.soludian.com/soludian/fountain/libs/cache/redis_cache"

Index

Variables

go
var (
    KPackageName = "redis_cache"
    // DefaultKey the collection name of redis for cache adapter.
    DefaultKey = "fountain"
)

go
var DefaultConfig = `{"addr": "127.0.0.1:6379"}`

func NewRedisCache

go
func NewRedisCache() cache.Cache

NewRedisCache create new redis cache with default collection name.

type Cache

Cache is Redis cache adapter.

go
type Cache struct {
    // contains filtered or unexported fields
}

func (*Cache) ClearAll

go
func (rc *Cache) ClearAll(context.Context) error

ClearAll deletes all cache in the redis collection Be careful about this method, because it scans all keys and the delete them one by one

func (*Cache) Close

go
func (rc *Cache) Close() error

Close

func (*Cache) Decr

go
func (rc *Cache) Decr(key string) (int64, error)

Decr decreases a key's counter in redis.

func (*Cache) Delete

go
func (rc *Cache) Delete(key string) error

Delete deletes a key's cache in redis.

func (*Cache) Get

go
func (rc *Cache) Get(key string) ([]byte, error)

Get gets a key's value from memcache.

func (*Cache) GetDefaultConfig

go
func (rc *Cache) GetDefaultConfig() string

func (*Cache) GetMulti

go
func (rc *Cache) GetMulti(keys []string) ([][]byte, error)

GetMulti gets one or keys values from ssdb.

func (*Cache) Has

go
func (rc *Cache) Has(key string) bool

Has checks cache's existence in redis.

func (*Cache) Incr

go
func (rc *Cache) Incr(key string) (int64, error)

Incr increases a key's counter in redis.

func (*Cache) Peek

go
func (rc *Cache) Peek(key string) (any, error)

Peek cache from redis.

func (*Cache) PeekMulti

go
func (rc *Cache) PeekMulti(keys []string) ([]any, error)

PeekMulti gets cache from redis.

func (*Cache) Put

go
func (rc *Cache) Put(key string, val any, timeout time.Duration) error

Put puts cache into redis.

func (*Cache) PutMulti

go
func (rc *Cache) PutMulti(values map[string]any, ttl time.Duration) error

func (*Cache) Reset

go
func (rc *Cache) Reset() error

func (*Cache) Set

go
func (rc *Cache) Set(key string, val []byte, ttl time.Duration) error

func (*Cache) SetMulti

go
func (rc *Cache) SetMulti(values map[string][]byte, ttl time.Duration) error

func (*Cache) SetName

go
func (rc *Cache) SetName(name string)

func (*Cache) StartAndGC

go
func (rc *Cache) StartAndGC(configs ...string) error

StartAndGC start redis cache adapter. config is like {"name": "cache", "key":"collection key","addr":"127.0.0.1:6379","db_num":"0"} the cache item in redis are stored forever, so no gc operation.

Generated by gomarkdoc