Documentation
¶
Index ¶
- type Config
- type GoRedisAdapter
- func (g *GoRedisAdapter) Del(ctx context.Context, keys ...string) (int64, error)
- func (g *GoRedisAdapter) Exists(ctx context.Context, keys ...string) (int64, error)
- func (g *GoRedisAdapter) Get(ctx context.Context, key string) (string, error)
- func (g *GoRedisAdapter) Keys(ctx context.Context, pattern string) ([]string, error)
- func (g *GoRedisAdapter) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) error
- type Handler
- type Manager
- type MockStore
- func (m *MockStore) Clear(ctx context.Context, prefix string) error
- func (m *MockStore) Delete(ctx context.Context, key string) error
- func (m *MockStore) Exists(ctx context.Context, key string) (bool, error)
- func (m *MockStore) Get(ctx context.Context, key string) (string, error)
- func (m *MockStore) GetStats() map[string]interface{}
- func (m *MockStore) Set(ctx context.Context, key string, value string, ttl time.Duration) error
- type NoCacheHandler
- func (n *NoCacheHandler) Close() error
- func (n *NoCacheHandler) Del(keys ...[]byte) error
- func (n *NoCacheHandler) Exists(key []byte) (bool, error)
- func (n *NoCacheHandler) Get(key []byte) ([]byte, error)
- func (n *NoCacheHandler) Set(key, value []byte, ttl time.Duration) error
- func (n *NoCacheHandler) SetWithTTL(key, value []byte, ttl time.Duration) error
- type RedisClientInterface
- type RedisStore
- func (r *RedisStore) Clear(ctx context.Context, prefix string) error
- func (r *RedisStore) Delete(ctx context.Context, key string) error
- func (r *RedisStore) Exists(ctx context.Context, key string) (bool, error)
- func (r *RedisStore) Get(ctx context.Context, key string) (string, error)
- func (r *RedisStore) Set(ctx context.Context, key string, value string, ttl time.Duration) error
- type Stats
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Enabled bool // 是否启用缓存
TTL time.Duration // 默认缓存过期时间
KeyPrefix string // 缓存键前缀
}
Config 缓存配置
func (*Config) WithKeyPrefix ¶
WithKeyPrefix 设置键前缀
type GoRedisAdapter ¶
type GoRedisAdapter struct {
// contains filtered or unexported fields
}
GoRedisAdapter go-redis v9 库的适配器实现
type Handler ¶
type Handler interface {
Get(key []byte) ([]byte, error)
Set(key, value []byte, ttl time.Duration) error
SetWithTTL(key, value []byte, ttl time.Duration) error
Del(keys ...[]byte) error
Exists(key []byte) (bool, error)
Close() error
}
Handler 缓存处理器接口
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager 缓存管理器 - 提供线程安全的统计和管理功能
func (*Manager) InvalidatePattern ¶
InvalidatePattern 使匹配模式的缓存失效 (线程安全)
type MockStore ¶
type MockStore struct {
// contains filtered or unexported fields
}
MockStore 模拟缓存存储实现(用于开发和测试)
type NoCacheHandler ¶
type NoCacheHandler struct{}
NoCacheHandler 无缓存实现 - 所有操作都直接返回
func (*NoCacheHandler) Close ¶
func (n *NoCacheHandler) Close() error
func (*NoCacheHandler) Del ¶
func (n *NoCacheHandler) Del(keys ...[]byte) error
func (*NoCacheHandler) Set ¶
func (n *NoCacheHandler) Set(key, value []byte, ttl time.Duration) error
func (*NoCacheHandler) SetWithTTL ¶
func (n *NoCacheHandler) SetWithTTL(key, value []byte, ttl time.Duration) error
type RedisClientInterface ¶
type RedisClientInterface interface {
Get(ctx context.Context, key string) (string, error)
Set(ctx context.Context, key string, value interface{}, expiration time.Duration) error
Del(ctx context.Context, keys ...string) (int64, error)
Exists(ctx context.Context, keys ...string) (int64, error)
Keys(ctx context.Context, pattern string) ([]string, error)
}
RedisClientInterface Redis 客户端接口 - 支持多种 Redis 库的适配
func NewGoRedisAdapter ¶
func NewGoRedisAdapter(redisClient interface{}) (RedisClientInterface, error)
NewGoRedisAdapter 创建 go-redis 适配器 使用方式: adapter := NewGoRedisAdapter(redisClient) 注意:这是一个模板实现,需要根据实际的 redis 库版本完成具体方法
type RedisStore ¶
type RedisStore struct {
// contains filtered or unexported fields
}
RedisStore Redis 缓存存储实现
func NewRedisStore ¶
func NewRedisStore(client RedisClientInterface, prefix string) *RedisStore
NewRedisStore 创建 Redis 缓存存储
func (*RedisStore) Clear ¶
func (r *RedisStore) Clear(ctx context.Context, prefix string) error
Clear 清除所有缓存(按前缀)
func (*RedisStore) Delete ¶
func (r *RedisStore) Delete(ctx context.Context, key string) error
Delete 删除缓存
type Stats ¶
type Stats struct {
TotalHits int64 // 总命中数
TotalMisses int64 // 总未命中数
HitRate float64 // 命中率
AvgTTL time.Duration // 平均 TTL
}
Stats 缓存统计信息
type Store ¶
type Store interface {
// Get 获取缓存值
Get(ctx context.Context, key string) (string, error)
// Set 设置缓存值
Set(ctx context.Context, key string, value string, ttl time.Duration) error
// Delete 删除缓存
Delete(ctx context.Context, key string) error
// Exists 检查缓存是否存在
Exists(ctx context.Context, key string) (bool, error)
// Clear 清除所有缓存(按前缀)
Clear(ctx context.Context, prefix string) error
}
Store 缓存存储接口 - 定义所有缓存操作的合约
Click to show internal directories.
Click to hide internal directories.