cache

package
v1.4.7 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const VersionName = "0.1.0"

Variables

This section is empty.

Functions

func Version

func Version() string

Types

type AdapterConfig

type AdapterConfig struct {
	Addr     string
	Password string
	DB       int

	// Type of connection pool.
	// true for FIFO pool, false for LIFO pool.
	// Note that fifo has higher overhead compared to lifo.
	PoolFIFO bool
	// Maximum number of socket connections.
	// Default is 10 connections per every available CPU as reported by runtime.GOMAXPROCS.
	PoolSize int
	// Minimum number of idle connections which is useful when establishing
	// new connection is slow.
	MinIdleConns int

	// redis://user:password@localhost:6789/3?dial_timeout=3&db=1&read_timeout=6s&max_retries=2
	// url, 如果使用url,其他配置无效, url的优先级高于其他配置
	Url string
}

AdapterConfig holds redis connection settings.

type Cache

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

Cache is a redis-backed cache. It wraps a Store and delegates all operations.

func NewCache

func NewCache(options Options) (*Cache, error)

NewCache creates a new redis-backed cache.

func (*Cache) Client added in v0.5.1

func (this *Cache) Client() *redis.Client

func (*Cache) Close added in v1.2.1

func (this *Cache) Close() error

func (*Cache) Decr

func (this *Cache) Decr(key string) (int64, error)

func (*Cache) Del added in v1.0.6

func (this *Cache) Del(keys ...string) (int64, error)

func (*Cache) Delete

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

func (*Cache) DeleteByPrefix

func (this *Cache) DeleteByPrefix(prefix string) error

func (*Cache) Exist added in v1.0.6

func (this *Cache) Exist(key string) bool

func (*Cache) Exists added in v1.0.6

func (this *Cache) Exists(keys ...string) (int64, error)

func (*Cache) Expire added in v1.0.6

func (this *Cache) Expire(key string, expiration time.Duration) (bool, error)

func (*Cache) Get

func (this *Cache) Get(key string) (string, error)

func (*Cache) Incr

func (this *Cache) Incr(key string) (int64, error)

func (*Cache) Key added in v0.5.2

func (this *Cache) Key(key string) string

func (*Cache) Set

func (this *Cache) Set(key, val string, expiration time.Duration) error

func (*Cache) TTL added in v1.0.6

func (this *Cache) TTL(key string) (time.Duration, error)

type Options

type Options struct {
	// alias
	Alias string
	// Adapter configuration.
	AdapterConfig AdapterConfig
	// key prefix Default is ""
	Section string
}

Options configures a Cache instance.

type RedisCache

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

RedisCache implements the Store interface backed by redis.

func NewRedisCache

func NewRedisCache() *RedisCache

NewRedisCache creates and returns a new redis cache.

func (*RedisCache) Client added in v0.5.0

func (r *RedisCache) Client() *redis.Client

func (*RedisCache) Close added in v1.2.1

func (r *RedisCache) Close() error

func (*RedisCache) Decr

func (r *RedisCache) Decr(key string) (int64, error)

func (*RedisCache) Del added in v1.0.5

func (r *RedisCache) Del(keys ...string) (int64, error)

func (*RedisCache) Delete

func (r *RedisCache) Delete(key string) error

func (*RedisCache) DeleteByPrefix

func (r *RedisCache) DeleteByPrefix(prefix string) error

DeleteByPrefix deletes cached values by given prefix key.

func (*RedisCache) Exist added in v1.0.6

func (r *RedisCache) Exist(key string) bool

func (*RedisCache) Exists added in v1.0.5

func (r *RedisCache) Exists(keys ...string) (int64, error)

func (*RedisCache) Expire added in v1.0.5

func (r *RedisCache) Expire(key string, expiration time.Duration) (bool, error)

func (*RedisCache) Get

func (r *RedisCache) Get(key string) (string, error)

func (*RedisCache) Incr

func (r *RedisCache) Incr(key string) (int64, error)

func (*RedisCache) Key added in v0.5.2

func (r *RedisCache) Key(key string) string

func (*RedisCache) Set

func (r *RedisCache) Set(key, val string, expiration time.Duration) error

func (*RedisCache) TTL added in v1.0.5

func (r *RedisCache) TTL(key string) (time.Duration, error)

type Store

type Store interface {
	Client() *redis.Client
	Close() error

	Key(key string) string

	Set(key, val string, expiration time.Duration) error
	Get(key string) (string, error)

	Del(keys ...string) (int64, error)
	Delete(key string) error
	DeleteByPrefix(prefix string) error

	Expire(key string, expiration time.Duration) (bool, error)
	TTL(key string) (time.Duration, error)
	Exists(keys ...string) (int64, error)
	Exist(key string) bool

	Incr(key string) (int64, error)
	Decr(key string) (int64, error)
}

Store is a thin key-value cache abstraction. Redis-specific commands (hash/list/set/zset/bitmap/script) are intentionally NOT part of this interface; use Client() to access them directly.

Jump to

Keyboard shortcuts

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