forked from datawhale/whale-town-end
feat:添加Redis缓存服务
- 实现Redis服务接口和抽象层 - 提供真实Redis服务实现 (RealRedisService) - 提供文件模拟Redis服务 (FileRedisService) 用于开发测试 - 支持基本的Redis操作:get、set、del、exists、ttl - 添加Redis模块配置和依赖注入
This commit is contained in:
53
src/core/redis/redis.interface.ts
Normal file
53
src/core/redis/redis.interface.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Redis接口定义
|
||||
* 定义统一的Redis操作接口,支持文件存储和真实Redis切换
|
||||
*/
|
||||
export interface IRedisService {
|
||||
/**
|
||||
* 设置键值对
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
* @param ttl 过期时间(秒)
|
||||
*/
|
||||
set(key: string, value: string, ttl?: number): Promise<void>;
|
||||
|
||||
/**
|
||||
* 获取值
|
||||
* @param key 键
|
||||
* @returns 值或null
|
||||
*/
|
||||
get(key: string): Promise<string | null>;
|
||||
|
||||
/**
|
||||
* 删除键
|
||||
* @param key 键
|
||||
* @returns 是否删除成功
|
||||
*/
|
||||
del(key: string): Promise<boolean>;
|
||||
|
||||
/**
|
||||
* 检查键是否存在
|
||||
* @param key 键
|
||||
* @returns 是否存在
|
||||
*/
|
||||
exists(key: string): Promise<boolean>;
|
||||
|
||||
/**
|
||||
* 设置过期时间
|
||||
* @param key 键
|
||||
* @param ttl 过期时间(秒)
|
||||
*/
|
||||
expire(key: string, ttl: number): Promise<void>;
|
||||
|
||||
/**
|
||||
* 获取剩余过期时间
|
||||
* @param key 键
|
||||
* @returns 剩余时间(秒),-1表示永不过期,-2表示不存在
|
||||
*/
|
||||
ttl(key: string): Promise<number>;
|
||||
|
||||
/**
|
||||
* 清空所有数据
|
||||
*/
|
||||
flushall(): Promise<void>;
|
||||
}
|
||||
Reference in New Issue
Block a user