cache

package
v0.0.0-...-9528f6d Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	Get(ctx context.Context, key string) (string, bool)
	Set(ctx context.Context, key string, value interface{}, ttl time.Duration)
	Has(ctx context.Context, key string) bool
	Del(ctx context.Context, key string) bool
	TTL(ctx context.Context, key string) time.Duration
}

Cache interface

type Option

type Option struct {
	Prefix string
}

Options for cache

type RedisCache

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

RedisCache is a Redis-based cache.

func NewRedisCache

func NewRedisCache(client *redis.Client, opt *Option) *RedisCache

NewRedisCache creates a new RedisCache instance.

func (*RedisCache) Del

func (r *RedisCache) Del(ctx context.Context, key string) bool

Del deletes the given key, panic when an error occurs.

func (*RedisCache) Get

func (r *RedisCache) Get(ctx context.Context, key string) (string, bool)

Get returns the value for the given key in cache, panic when an error occurs.

func (*RedisCache) Has

func (r *RedisCache) Has(ctx context.Context, key string) bool

Has check if the cache key exists, panic when an error occurs.

func (*RedisCache) Set

func (r *RedisCache) Set(ctx context.Context, key string, value interface{}, ttl time.Duration)

Set sets the value for the given key into cache, panic when an error occurs.

func (*RedisCache) TTL

func (r *RedisCache) TTL(ctx context.Context, key string) time.Duration

TTL returns the remaining time to live of a key, panic when an error occurs.

Jump to

Keyboard shortcuts

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