feat(client): 短信登录、JWT、Redis 与 Spug 短信及流式 Chat
- 新增客户端认证:短信发送/登录、access/refresh JWT、Guard/Strategy\n- Redis 存验证码;可配置 SMS_CODE_TTL_SECONDS;失败时回滚与明确错误\n- 短信改为 Spug 推送助手(code/targets/number/name),移除 UniSMS\n- Chat SSE 接口与 DTO;AppModule 挂载 RedisModule\n- 更新 README 与 project-solution 环境变量说明 Made-with: Cursor
This commit is contained in:
40
src/apps/shared-domain/cache/redis.service.ts
vendored
Normal file
40
src/apps/shared-domain/cache/redis.service.ts
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
import { Injectable, OnModuleDestroy } from '@nestjs/common';
|
||||
import Redis from 'ioredis';
|
||||
|
||||
@Injectable()
|
||||
export class RedisService implements OnModuleDestroy {
|
||||
private readonly client: Redis;
|
||||
|
||||
constructor() {
|
||||
this.client = new Redis({
|
||||
host: process.env.REDIS_HOST || '127.0.0.1',
|
||||
port: Number(process.env.REDIS_PORT || 6379),
|
||||
password: process.env.REDIS_PASSWORD || undefined,
|
||||
db: Number(process.env.REDIS_DB || 0),
|
||||
keyPrefix: '',
|
||||
lazyConnect: false,
|
||||
maxRetriesPerRequest: 2,
|
||||
});
|
||||
}
|
||||
|
||||
getClient() {
|
||||
return this.client;
|
||||
}
|
||||
|
||||
async get(key: string) {
|
||||
return this.client.get(key);
|
||||
}
|
||||
|
||||
async setex(key: string, seconds: number, value: string) {
|
||||
await this.client.set(key, value, 'EX', seconds);
|
||||
}
|
||||
|
||||
async del(key: string) {
|
||||
await this.client.del(key);
|
||||
}
|
||||
|
||||
async onModuleDestroy() {
|
||||
await this.client.quit();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user