Documentation
¶
Overview ¶
Package redisdriver provides a Redis-backed implementation of the framework's cache.Cache interface (Has/Get/Set/Forget/EmptyByMatch/Empty).
Index ¶
- func CreateRedisPool(idel, active, timeout, host, username, password string) (*redis.Pool, error)
- type RedisCache
- func (c *RedisCache) Empty() error
- func (c *RedisCache) EmptyByMatch(str string) error
- func (c *RedisCache) Forget(str string) error
- func (c *RedisCache) Get(str string) (interface{}, error)
- func (c *RedisCache) Has(str string) (bool, error)
- func (c *RedisCache) Set(str string, value interface{}, expires ...int) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateRedisPool ¶
CreateRedisPool builds a redis.Pool from string configuration values. The idel, active, and timeout arguments are parsed into MaxIdle, MaxActive, and an IdleTimeout (in seconds); the dial function applies optional username/password auth and a PING-based TestOnBorrow health check. Returns an error if any numeric config string is invalid.
Types ¶
type RedisCache ¶
RedisCache is a Redis-backed implementation of the cache.Cache interface. Conn is the underlying redis connection pool from which connections are borrowed, and Prefix namespaces all keys so multiple caches can share a single Redis instance.
func (*RedisCache) Empty ¶
func (c *RedisCache) Empty() error
Empty deletes every key under this cache's prefix. It scans for all keys beginning with the prefix via getKeys and issues a DEL for each one. Returns an error if scanning or any deletion fails.
func (*RedisCache) EmptyByMatch ¶
func (c *RedisCache) EmptyByMatch(str string) error
EmptyByMatch deletes all keys matching the given prefixed pattern. It collects the matching keys via getKeys (a SCAN cursor walk) and then issues a DEL for each. Returns an error if scanning or any deletion fails.
func (*RedisCache) Forget ¶
func (c *RedisCache) Forget(str string) error
Forget deletes the single prefixed key from Redis using the DEL command.
func (*RedisCache) Get ¶
func (c *RedisCache) Get(str string) (interface{}, error)
Get fetches the cached entry stored under the prefixed key and decodes it. The raw bytes are retrieved with GET and run through cache.Decode, which yields the entry map keyed by the prefixed key. Returns the stored value or an error if the key is missing or decoding fails.
func (*RedisCache) Has ¶
func (c *RedisCache) Has(str string) (bool, error)
Has reports whether the prefixed key exists in Redis using the EXISTS command.
func (*RedisCache) Set ¶
func (c *RedisCache) Set(str string, value interface{}, expires ...int) error
Set encodes the given value and stores it under the prefixed key. The variadic expires argument is a TTL in seconds: when supplied the value is written with SETEX so it expires automatically, otherwise a non-expiring SET is used. Returns an error if encoding or the Redis command fails.