redis

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultKey = "gocache"

DefaultKey defines the collection name of redis for the cache adapter.

Functions

func New

func New(opts ...CacheOptions) cache.Cache

New creates a new redis cache with default collection name.

Types

type Cache

type Cache struct {
	Redis     *redis.Pool // redis connection pool
	Key       string
	CacheItem cache.ICacheItem
}

func (*Cache) Clear

func (c *Cache) Clear() error

Clear 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) Decrement

func (c *Cache) Decrement(key string, step int) error

Decrement decreases a key's counter in redis.

func (*Cache) Delete

func (c *Cache) Delete(key string) error

Delete deletes a key's cache in redis.

func (*Cache) Get

func (c *Cache) Get(key string) (any, error)

Get cache from redis.

func (*Cache) GetMulti

func (c *Cache) GetMulti(keys []string) ([]any, error)

GetMulti gets cache from redis.

func (*Cache) Has

func (c *Cache) Has(key string) (bool, error)

func (*Cache) Increment

func (c *Cache) Increment(key string, step int) error

Increment increases a key's counter in redis.

func (*Cache) Name

func (c *Cache) Name() string

func (*Cache) Scan

func (c *Cache) Scan(pattern string) (keys []string, err error)

Scan scans all keys matching a given pattern.

func (*Cache) Set

func (c *Cache) Set(key string, value any, ttl time.Duration) error

Set puts cache into redis.

type CacheOptions

type CacheOptions func(c *Cache)

func CacheWithCacheItem

func CacheWithCacheItem(cacheItem cache.ICacheItem) CacheOptions

func CacheWithKey

func CacheWithKey(key string) CacheOptions

CacheWithKey configures key for redis

func CacheWithRedisPool

func CacheWithRedisPool(pool *redis.Pool) CacheOptions

CacheWithRedisPool configures prefix for redis

Jump to

Keyboard shortcuts

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