1234567891011121314151617181920212223242526272829303132 |
- import { pubClient } from "../connection/redis.js";
- const prefix = process.env.REDIS_PREFIX || "chat";
- const getInKey = (realKey) => {
- return `${prefix}:${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));
- };
- export { publishEnterRoom, publishExitRoom };
|