Documentation
¶
Index ¶
- type ICache
- type MemoryCache
- func (m *MemoryCache) Decrement(ctx context.Context, key string, value int64) (int64, error)
- func (m *MemoryCache) Delete(ctx context.Context, key string) error
- func (m *MemoryCache) Exists(ctx context.Context, key string) (bool, error)
- func (m *MemoryCache) Expire(ctx context.Context, key string, expiration time.Duration) error
- func (m *MemoryCache) Get(ctx context.Context, key string) ([]byte, error)
- func (m *MemoryCache) Increment(ctx context.Context, key string, value int64) (int64, error)
- func (m *MemoryCache) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) error
- type RedisCache
- func (r *RedisCache) Decrement(ctx context.Context, key string, value int64) (int64, error)
- func (r *RedisCache) Delete(ctx context.Context, key string) error
- func (r *RedisCache) Exists(ctx context.Context, key string) (bool, error)
- func (r *RedisCache) Expire(ctx context.Context, key string, expiration time.Duration) error
- func (r *RedisCache) Get(ctx context.Context, key string) ([]byte, error)
- func (r *RedisCache) Increment(ctx context.Context, key string, value int64) (int64, error)
- func (r *RedisCache) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ICache ¶
type ICache interface {
// Get 获取缓存值
Get(ctx context.Context, key string) ([]byte, error)
// Set 设置缓存值
Set(ctx context.Context, key string, value interface{}, expiration time.Duration) error
// Delete 删除缓存值
Delete(ctx context.Context, key string) error
// Exists 检查缓存是否存在
Exists(ctx context.Context, key string) (bool, error)
// Increment 对缓存值进行自增操作
Increment(ctx context.Context, key string, value int64) (int64, error)
// Decrement 对缓存值进行自减操作
Decrement(ctx context.Context, key string, value int64) (int64, error)
// Expire 设置缓存过期时间
Expire(ctx context.Context, key string, expiration time.Duration) error
}
Cache 接口定义了缓存的基本操作
type MemoryCache ¶
type MemoryCache struct {
// contains filtered or unexported fields
}
MemoryCache 是基于内存的 Cache 实现
func (*MemoryCache) Delete ¶
func (m *MemoryCache) Delete(ctx context.Context, key string) error
Delete 实现 Cache 接口的 Delete 方法
type RedisCache ¶
type RedisCache struct {
// contains filtered or unexported fields
}
RedisCache 是基于 Go Redis 的 Cache 实现
func NewRedisCache ¶
func NewRedisCache(client *redis.Client) *RedisCache
NewRedisCache 创建一个新的 RedisCache 实例
func (*RedisCache) Delete ¶
func (r *RedisCache) Delete(ctx context.Context, key string) error
Delete 实现 Cache 接口的 Delete 方法
Click to show internal directories.
Click to hide internal directories.