Documentation
¶
Overview ¶
*
- @Author: guxline zjguoxin@163.com
- @Date: 2025/7/1 16:21:29
- @LastEditors: guxline zjguoxin@163.com
- @LastEditTime: 2025/7/1 16:21:29
- Description:
- Copyright: Copyright (©) 2025 中易综服. All rights reserved.
*
- @Author: guxline zjguoxin@163.com
- @Date: 2025/7/1 16:22:40
- @LastEditors: guxline zjguoxin@163.com
- @LastEditTime: 2025/7/1 16:22:40
- Description: 内存缓存实现
- Copyright: Copyright (©) 2025 中易综服. All rights reserved.
*
- @Author: guxline zjguoxin@163.com
- @Date: 2025/7/1 16:29:58
- @LastEditors: guxline zjguoxin@163.com
- @LastEditTime: 2025/7/1 16:29:58
- Description: Redis缓存实现
- Copyright: Copyright (©) 2025 中易综服. All rights reserved.
Index ¶
- type CacheConfig
- type CacheInterface
- type CacheType
- type MemoryCache
- func (m *MemoryCache) Close() error
- func (m *MemoryCache) DelHash(key, field string) error
- func (m *MemoryCache) Delete(key string) error
- func (m *MemoryCache) ExistHash(key, field string) (bool, error)
- func (m *MemoryCache) ExpireHash(key string, expiration time.Duration) error
- func (m *MemoryCache) Get(key string) (interface{}, bool, error)
- func (m *MemoryCache) GetHash(key string) (map[string]string, error)
- func (m *MemoryCache) GetHashField(key, field string) (string, error)
- func (m *MemoryCache) MGet(keys []string) (map[string]interface{}, error)
- func (m *MemoryCache) MSet(values map[string]interface{}, expiration time.Duration) error
- func (m *MemoryCache) Set(key string, value interface{}, expiration time.Duration) error
- func (m *MemoryCache) SetHash(key string, value map[string]interface{}, expiration time.Duration) error
- type Option
- type RedisCache
- func (r *RedisCache) Close() error
- func (r *RedisCache) DelHash(key, field string) error
- func (r *RedisCache) Delete(key string) error
- func (r *RedisCache) ExistHash(key, field string) (bool, error)
- func (r *RedisCache) ExpireHash(key string, expiration time.Duration) error
- func (r *RedisCache) Get(key string) (interface{}, bool, error)
- func (r *RedisCache) GetHash(key string) (map[string]string, error)
- func (r *RedisCache) GetHashField(key, field string) (string, error)
- func (r *RedisCache) MGet(keys []string) (map[string]interface{}, error)
- func (r *RedisCache) MSet(values map[string]interface{}, expiration time.Duration) error
- func (r *RedisCache) Set(key string, value interface{}, expiration time.Duration) error
- func (r *RedisCache) SetHash(key string, value map[string]interface{}, expiration time.Duration) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CacheConfig ¶
type CacheConfig struct {
Type string `json:"type"` // 缓存类型: memory 或 redis
URL string `json:"url"` // Redis连接地址
Password string `json:"password"` // Redis密码
DB int `json:"db"` // Redis数据库索引
Prefix string `json:"prefix"` // Redis键前缀
DefaultExp time.Duration `json:"default_exp"` // 默认过期时间
CleanupInt time.Duration `json:"cleanup_int"` // 清理间隔(仅内存缓存)
PoolSize int `json:"pool_size"` // Redis连接池大小
MinIdleConns int `json:"min_idle_conns"` // Redis最小空闲连接数
HashKeyExpiry time.Duration `json:"hash_key_expiry"` // 哈希表过期时间
}
type CacheInterface ¶
type CacheInterface interface {
// 基础操作
Get(key string) (interface{}, bool, error)
Set(key string, value interface{}, expiration time.Duration) error
Delete(key string) error
Close() error
// 哈希表操作
SetHash(key string, value map[string]interface{}, expiration time.Duration) error
GetHash(key string) (map[string]string, error)
GetHashField(key, field string) (string, error)
DelHash(key, field string) error
ExistHash(key, field string) (bool, error)
ExpireHash(key string, expiration time.Duration) error
// 批量操作
MSet(values map[string]interface{}, expiration time.Duration) error
MGet(keys []string) (map[string]interface{}, error)
}
type MemoryCache ¶
type MemoryCache struct {
// contains filtered or unexported fields
}
MemoryCache 内存缓存实现
func NewMemoryCache ¶
func NewMemoryCache(config *CacheConfig) (*MemoryCache, error)
NewMemoryCache 创建新的内存缓存实例
func (*MemoryCache) DelHash ¶
func (m *MemoryCache) DelHash(key, field string) error
DelHash 删除哈希表字段
func (*MemoryCache) ExistHash ¶
func (m *MemoryCache) ExistHash(key, field string) (bool, error)
ExistHash 检查哈希表字段是否存在
func (*MemoryCache) ExpireHash ¶
func (m *MemoryCache) ExpireHash(key string, expiration time.Duration) error
ExpireHash 设置哈希表过期时间
func (*MemoryCache) Get ¶
func (m *MemoryCache) Get(key string) (interface{}, bool, error)
Get 获取缓存值
func (*MemoryCache) GetHash ¶
func (m *MemoryCache) GetHash(key string) (map[string]string, error)
GetHash 获取整个哈希表
func (*MemoryCache) GetHashField ¶
func (m *MemoryCache) GetHashField(key, field string) (string, error)
GetHashField 获取哈希表字段
func (*MemoryCache) MGet ¶
func (m *MemoryCache) MGet(keys []string) (map[string]interface{}, error)
MGet 批量获取缓存值
func (*MemoryCache) MSet ¶
func (m *MemoryCache) MSet(values map[string]interface{}, expiration time.Duration) error
MSet 批量设置缓存值
type Option ¶
type Option func(*CacheConfig)
Option 配置选项函数类型
func WithExpiration ¶
WithExpiration 过期时间配置选项
func WithRedisConfig ¶
WithRedisConfig Redis配置选项
type RedisCache ¶
type RedisCache struct {
// contains filtered or unexported fields
}
RedisCache Redis缓存实现
func NewRedisCache ¶
func NewRedisCache(config *CacheConfig) (*RedisCache, error)
NewRedisCache 创建Redis缓存实例
func (*RedisCache) ExistHash ¶
func (r *RedisCache) ExistHash(key, field string) (bool, error)
ExistHash 检查哈希表字段是否存在
func (*RedisCache) ExpireHash ¶
func (r *RedisCache) ExpireHash(key string, expiration time.Duration) error
ExpireHash 设置哈希表过期时间
func (*RedisCache) GetHash ¶
func (r *RedisCache) GetHash(key string) (map[string]string, error)
GetHash 获取整个哈希表
func (*RedisCache) GetHashField ¶
func (r *RedisCache) GetHashField(key, field string) (string, error)
GetHashField 获取哈希表字段
func (*RedisCache) MGet ¶
func (r *RedisCache) MGet(keys []string) (map[string]interface{}, error)
MGet 批量获取缓存值
func (*RedisCache) MSet ¶
func (r *RedisCache) MSet(values map[string]interface{}, expiration time.Duration) error
MSet 批量设置缓存值
Click to show internal directories.
Click to hide internal directories.