Skip to content

Commit 1098323

Browse files
committed
chore: merge dev
2 parents fb4e16a + fa1ea30 commit 1098323

31 files changed

+660
-41
lines changed

BE/.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

BE/src/app.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MiddlewareConsumer, Module, ValidationPipe } from '@nestjs/common';
1+
import { MiddlewareConsumer, Module } from '@nestjs/common';
22
import { UserModule } from './user/user.module';
33
import { ShellModule } from './shell/shell.module';
44
import { QueryModule } from './query/query.module';

BE/src/config/query-database/admin-db-manager.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export class AdminDBManager implements OnModuleInit {
1313
constructor(private readonly configService: ConfigService) {}
1414

1515
async onModuleInit() {
16-
this.createAdminConnection();
16+
// 서버 테스트를 위한 주석처리
17+
//this.createAdminConnection();
1718
}
1819

1920
private createAdminConnection() {

BE/src/config/redis/redis.service.ts

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,39 @@ import { ConfigService } from '@nestjs/config';
55

66
@Injectable()
77
export class RedisService {
8-
private defaultConnection: Redis;
8+
private sessionConnection: Redis;
99
private eventConnection: Redis;
10+
private activeUserConnection: Redis;
11+
12+
private readonly SESSION_TTL = 60 * 30;
13+
private readonly ACTIVE_USER_TTL = 60 * 5;
1014

1115
constructor(
1216
private readonly adminDBManager: AdminDBManager,
1317
private readonly configService: ConfigService,
1418
) {
15-
this.setDefaultConnection();
19+
this.setSessionConnection();
1620
this.setEventConnection();
21+
this.setActiveUserConnection();
1722
}
1823

19-
private setDefaultConnection() {
20-
this.defaultConnection = new Redis({
24+
private setSessionConnection() {
25+
this.sessionConnection = new Redis({
2126
host: this.configService.get<string>('REDIS_HOST'),
2227
port: this.configService.get<number>('REDIS_PORT'),
28+
db: this.configService.get<number>('REDIS_DATABASE_SESSION'),
2329
});
2430

25-
this.defaultConnection.on('ready', () => {
26-
this.defaultConnection.config('SET', 'notify-keyspace-events', 'Exg');
31+
this.sessionConnection.on('ready', () => {
32+
this.sessionConnection.config('SET', 'notify-keyspace-events', 'Exg');
33+
});
34+
}
35+
36+
private setActiveUserConnection() {
37+
this.activeUserConnection = new Redis({
38+
host: this.configService.get<string>('REDIS_HOST'),
39+
port: this.configService.get<number>('REDIS_PORT'),
40+
db: this.configService.get<number>('REDIS_DATABASE_ACTIVE_USER'),
2741
});
2842
}
2943

@@ -42,28 +56,24 @@ export class RedisService {
4256
if (!key) {
4357
return null;
4458
}
45-
return this.defaultConnection.hgetall(key);
59+
return this.sessionConnection.hgetall(key);
4660
}
4761

4862
public async existSession(key: string) {
49-
return this.defaultConnection.exists(key);
63+
return this.sessionConnection.exists(key);
5064
}
5165

5266
public async setNewSession(key: string) {
5367
const session = await this.existSession(key);
5468
if (!session) {
55-
await this.defaultConnection.hset(key, 'rowCount', 0);
69+
await this.sessionConnection.hset(key, 'rowCount', 0);
5670
await this.adminDBManager.initUserDatabase(key);
5771
}
58-
await this.setExpireTime(key, 60 * 60);
72+
await this.sessionConnection.expire(key, this.SESSION_TTL);
5973
}
6074

6175
public async deleteSession(key: string) {
62-
await this.defaultConnection.del(key);
63-
}
64-
65-
public async setExpireTime(key: string, ttl: number) {
66-
await this.defaultConnection.expire(key, ttl);
76+
await this.sessionConnection.del(key);
6777
}
6878

6979
private subscribeToExpiredEvents() {
@@ -75,10 +85,14 @@ export class RedisService {
7585
}
7686

7787
public async getRowCount(key: string) {
78-
return this.defaultConnection.hget(key, 'rowCount');
88+
return this.sessionConnection.hget(key, 'rowCount');
7989
}
8090

8191
public async setRowCount(key: string, rowCount: number) {
82-
await this.defaultConnection.hset(key, 'rowCount', rowCount);
92+
await this.sessionConnection.hset(key, 'rowCount', rowCount);
93+
}
94+
95+
public async setActiveUser(key: string) {
96+
this.activeUserConnection.expire(key, this.ACTIVE_USER_TTL);
8397
}
8498
}

BE/src/query/query.service.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@ import { ResultSetHeader, RowDataPacket } from 'mysql2/promise';
66
import { Shell } from '../shell/shell.entity';
77
import { UserDBManager } from '../config/query-database/user-db-manager.service';
88
import { UsageService } from 'src/usage/usage.service';
9+
import { RedisService } from '../config/redis/redis.service';
910

1011
@Injectable()
1112
export class QueryService {
1213
constructor(
1314
private readonly userDBManager: UserDBManager,
1415
private shellService: ShellService,
1516
private readonly usageService: UsageService,
17+
private readonly redisService: RedisService,
1618
) {}
1719

1820
async execute(req: any, shellId: number, queryDto: QueryDto) {
21+
this.redisService.setActiveUser(req.sessionID);
1922
await this.shellService.findShellOrThrow(shellId);
2023

2124
const baseUpdateData = {

0 commit comments

Comments
 (0)