Skip to content

Commit

Permalink
fix: redis mget 문제 해결
Browse files Browse the repository at this point in the history
redis에서 mget을 수행할 때 빈 배열이 전달되는 경우 에러가 발생하는 것을
해결했습니다.
  • Loading branch information
JYKIM317 committed Dec 4, 2024
1 parent dfd7cea commit 3ffd07d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
1 change: 1 addition & 0 deletions applicationServer/src/database/redis.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class RedisService {
}

async getMany(keys: string[]) {
if (keys.length === 0) return keys;
return await this.redis.mget(keys);
}

Expand Down
3 changes: 0 additions & 3 deletions applicationServer/src/live/live.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import { Request } from 'express';
import { uploadData } from '@src/storage/storage.repository';
import { RedisService } from '@database/redis.service';

// import { registerMockLive } from './mock/register-mock.util';
// registerMockLive(this.live);

@Injectable()
export class LiveService {
constructor(
Expand Down
39 changes: 24 additions & 15 deletions applicationServer/src/live/mock/register-mock.util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
function registerMockLive(live) {
import { RedisService } from '@database/redis.service';
import { REDIS_LIVE_KEY, REDIS_LIVE_LIST_KEY } from '@src/constants';

function registerMockLive() {
const redisService = new RedisService();

const mockBroadcastIdList = [
'872bc363-0d0c-4bde-a867-7b0edd076ad6',
'9b534e89-a596-436a-b314-65cbe0ff9fab',
Expand All @@ -17,20 +22,24 @@ function registerMockLive(live) {
const contentCategoryList = ['music', 'talk', null, 'cook', 'mukbang'];
const moodCategoryList = [null, 'calm', null, 'happy', null];

mockBroadcastIdList.forEach((data, idx) => {
live.data.set(mockBroadcastIdList[idx], {
broadcastId: mockBroadcastIdList[idx],
broadcastPath: `${mockBroadcastIdList[idx]}`,
title: `${mockNameList[idx]}의 라이브 방송`,
contentCategory: contentCategoryList[idx],
moodCategory: moodCategoryList[idx],
tags: [`방송 ${idx}`],
thumbnailUrl: `https://kr.object.ncloudstorage.com/media-storage/${mockBroadcastIdList[idx]}/dynamic_thumbnail.jpg`,
viewerCount: 0,
userName: mockNameList[idx],
profileImageUrl: 'https://kr.object.ncloudstorage.com/funch-storage/profile/profile_default.png',
});
mockBroadcastIdList.forEach(async (data, idx) => {
await redisService.addSetType(REDIS_LIVE_LIST_KEY, mockBroadcastIdList[idx]);
redisService.set(
`${REDIS_LIVE_KEY}${mockBroadcastIdList[idx]}`,
JSON.stringify({
broadcastId: mockBroadcastIdList[idx],
broadcastPath: `${mockBroadcastIdList[idx]}`,
title: `${mockNameList[idx]}의 라이브 방송`,
contentCategory: contentCategoryList[idx],
moodCategory: moodCategoryList[idx],
tags: [`방송 ${idx}`],
thumbnailUrl: `https://kr.object.ncloudstorage.com/media-storage/${mockBroadcastIdList[idx]}/dynamic_thumbnail.jpg`,
viewerCount: 0,
userName: mockNameList[idx],
profileImageUrl: 'https://kr.object.ncloudstorage.com/funch-storage/profile/profile_default.png',
}),
);
});
}

export { registerMockLive };
registerMockLive();

0 comments on commit 3ffd07d

Please sign in to comment.