(roomName, msg)
| 29 | |
| 30 | // Insert new messages into the Redis cache |
| 31 | async function addMessageToCache(roomName, msg) { |
| 32 | // Check for current cache |
| 33 | let room = await getRoomFromCache(roomName); |
| 34 | if (room) { |
| 35 | // Update old room |
| 36 | room.messages.push(msg); |
| 37 | } else { |
| 38 | // Create a new room |
| 39 | room = { |
| 40 | room: roomName, |
| 41 | messages: [msg], |
| 42 | }; |
| 43 | } |
| 44 | await redisClient.set(roomName, JSON.stringify(room)); |
| 45 | // Insert message to the database as well |
| 46 | addMessageToDb(room); |
| 47 | } |
| 48 | |
| 49 | // Query Redis for messages for a specific room |
| 50 | // If not in Redis, query the database |
no test coverage detected