Skip to content

Commit fca48c4

Browse files
author
성현주
committed
Fix: redis
redis는 콜백 방식이라 Promis로 감싸서 후처리를 해 줘야 한다... ioredis 쓸걸...
1 parent 58a6a97 commit fca48c4

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/routes/room.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,19 @@ router.get('/list', async (req, res) => {
156156
const rooms = await Room.find();
157157
const roomInfo = await Promise.all(
158158
rooms.map(async (room) => {
159+
const length = await new Promise((resolve, reject) => {
160+
redisCli.LLEN(`room:${room._id.toString()}`, (err, length) => {
161+
if (err) reject(err);
162+
resolve(length); // Redis의 연결된 소켓 수를 반환
163+
});
164+
});
159165
return {
160166
id: room._id.toString(),
161167
title: room.title,
162168
thumbnail: room.thumbnail,
163169
description: room.description,
164170
isPrivate: room.isPrivate,
165-
knitters: (await redisCli).LLEN(`room:${room._id.toString()}`), // 현재 소켓 연결 수
171+
knitters: length, // 현재 소켓 연결 수
166172
};
167173
})
168174
);

0 commit comments

Comments
 (0)