瀏覽代碼

增加计时redis

gemercheung 2 年之前
父節點
當前提交
ce74dc860c
共有 1 個文件被更改,包括 8 次插入0 次删除
  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));
 };