feature/IO-2742-redis - Checkpoint, Redis fully implemented.

Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
Dave Richer
2024-09-11 19:08:24 -04:00
parent bca0a35cdd
commit f606228792
14 changed files with 1012 additions and 722 deletions

View File

@@ -141,6 +141,36 @@ const main = async () => {
exports.redisClient = pubClient;
// Store session data in Redis
exports.setSessionData = async (socketId, key, value) => {
await pubClient.hSet(`socket:${socketId}`, key, JSON.stringify(value)); // Use Redis pubClient
};
// Retrieve session data from Redis
exports.getSessionData = async (socketId, key) => {
const data = await pubClient.hGet(`socket:${socketId}`, key);
return data ? JSON.parse(data) : null;
};
// Clear session data from Redis
exports.clearSessionData = async (socketId) => {
await pubClient.del(`socket:${socketId}`);
};
// TODO: Remove, just a demo of hGet and hSet
// async function demoSessionData() {
// // Store session data using setSessionData
// await exports.setSessionData("testSocketId", "field1", "Hello, Redis Hash!");
//
// // Retrieve session data using getSessionData
// const value = await exports.getSessionData("testSocketId", "field1");
//
// // Output the retrieved value
// console.log(value);
// }
// demoSessionData().catch(console.error);
// TODO: End of demo
require("./server/web-sockets/web-socket");
applyMiddleware(app);