Explorar el Código

增加计时redis

gemercheung hace 2 años
padre
commit
ce74dc860c
Se han modificado 1 ficheros con 8 adiciones y 0 borrados
  1. 8 0
      src/service/publishService.js

+ 8 - 0
src/service/publishService.js

@@ -7,17 +7,25 @@ const getInKey = (realKey) => {
 };
 
 const publishEnterRoom = (userId, roomId) => {
+  const onlineConfigKey = `online:${roomId}:${userId}`;
   const payLoad = {
     userId,
     roomId,
+    type: 0,
+    createTime: Date.now(),
   };
+  pubClient.hSet(getInKey(onlineConfigKey), `${payLoad.createTime}`, JSON.stringify(payLoad));
   pubClient.publish("enterRoom", JSON.stringify(payLoad));
 };
 const publishExitRoom = (userId, roomId) => {
+  const onlineConfigKey = `online:${roomId}:${userId}`;
   const payLoad = {
     userId,
     roomId,
+    type: 0,
+    createTime: Date.now(),
   };
+  pubClient.hSet(getInKey(onlineConfigKey), `${payLoad.createTime}`, JSON.stringify(payLoad));
   pubClient.publish("exitRoom", JSON.stringify(payLoad));
 };