store

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorCacheMiss = errors.New("cache miss error")

Functions

This section is empty.

Types

type CachedResponse

type CachedResponse struct {
	Status int
	Header http.Header

	Data []byte
}

CachedResponse 缓存的响应

type ICacheStore

type ICacheStore interface {
	// Get 获取缓存,如果未获取到,返回 ErrorCacheMiss 错误
	Get(key string, value *CachedResponse) error

	// Set 设置缓存,如果存在,则覆盖
	Set(key string, value *CachedResponse, expire time.Duration) error

	// Delete 删除缓存,如果不存在,则不处理
	Delete(key string) error
}

type RedisStore

type RedisStore struct {
	RedisClient *redis.Client
}

RedisStore store http response in redis

func NewRedisStore

func NewRedisStore(redisClient *redis.Client) *RedisStore

NewRedisStore create a redis memory store with redis client

func (*RedisStore) Delete

func (store *RedisStore) Delete(key string) error

Delete remove key in redis, do nothing if key doesn't exist

func (*RedisStore) Get

func (store *RedisStore) Get(key string, value *CachedResponse) error

Get retrieves an item from redis, if key doesn't exist, return ErrorCacheMiss

func (*RedisStore) Set

func (store *RedisStore) Set(key string, value *CachedResponse, expire time.Duration) error

Set put key value pair to redis, and expire after expireDuration

Jump to

Keyboard shortcuts

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