MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / addMessageToCache

Function addMessageToCache

run/websockets/redis.js:31–47  ·  view source on GitHub ↗
(roomName, msg)

Source from the content-addressed store, hash-verified

29
30// Insert new messages into the Redis cache
31async 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

Callers 1

app.jsFile · 0.85

Calls 3

getRoomFromCacheFunction · 0.85
addMessageToDbFunction · 0.85
setMethod · 0.80

Tested by

no test coverage detected