redis

package
v2.0.0-...-2e01499 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRedisCache

func NewRedisCache(client redis.Cmdable, opts ...CacheOptions) cache.Cache

NewRedisCache creates a new redis cache with default collection name.

Types

type Cache

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

Cache is Redis cache adapter.

func (*Cache) ClearAll

func (rc *Cache) ClearAll(ctx 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 if you add more prefix-value during calling ClearAll function, those new prefix-value pairs will not be deleted.

func (*Cache) Decr

func (rc *Cache) Decr(ctx context.Context, key string) error

Decr decreases a prefix's counter in redis.

func (*Cache) Delete

func (rc *Cache) Delete(ctx context.Context, key string) error

Delete deletes a prefix's cache in redis.

func (*Cache) Get

func (rc *Cache) Get(ctx context.Context, key string) (interface{}, error)

Get cache from redis.

func (*Cache) GetMulti

func (rc *Cache) GetMulti(ctx context.Context, keys []string) ([]interface{}, error)

GetMulti gets cache from redis.

func (*Cache) Incr

func (rc *Cache) Incr(ctx context.Context, key string) error

Incr increases a prefix's counter in redis.

func (*Cache) IsExist

func (rc *Cache) IsExist(ctx context.Context, key string) (bool, error)

IsExist checks cache's existence in redis.

func (*Cache) Put

func (rc *Cache) Put(ctx context.Context, key string, val interface{}, timeout time.Duration) error

Put puts cache into redis.

func (*Cache) Scan

func (rc *Cache) Scan(ctx context.Context, pattern string) ([]string, error)

Scan scans all keys matching a given pattern. this function will ignore the prefix.

type CacheOptions

type CacheOptions func(c *Cache)

func CacheWithPrefix

func CacheWithPrefix(key string) CacheOptions

CacheWithPrefix configures prefix for redis prefix should not be empty string

func CacheWithScanCount

func CacheWithScanCount(count int64) CacheOptions

CacheWithScanCount configures scan count for redis

Directories

Path Synopsis
internal
mock
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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