redisdriver

package
v1.0.12 Latest Latest
Warning

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

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

Documentation

Overview

Package redisdriver provides a Redis-backed implementation of the framework's cache.Cache interface (Has/Get/Set/Forget/EmptyByMatch/Empty).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateRedisPool

func CreateRedisPool(idel, active, timeout, host, username, password string) (*redis.Pool, error)

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

type RedisCache struct {
	Conn   *redis.Pool
	Prefix string
}

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.

Jump to

Keyboard shortcuts

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