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

Function getRoomFromCache

run/websockets/redis.js:51–59  ·  view source on GitHub ↗
(roomName)

Source from the content-addressed store, hash-verified

49// Query Redis for messages for a specific room
50// If not in Redis, query the database
51async function getRoomFromCache(roomName) {
52 if (!(await redisClient.exists(roomName))) {
53 const room = getRoomFromDatabase(roomName);
54 if (room) {
55 await redisClient.set(roomName, JSON.stringify(room));
56 }
57 }
58 return JSON.parse(await redisClient.get(roomName));
59}
60
61// In-memory database example -
62// Production applications should use a persistent database such as Firestore

Callers 2

app.jsFile · 0.85
addMessageToCacheFunction · 0.85

Calls 3

getRoomFromDatabaseFunction · 0.85
setMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected