refactor: setex

This commit is contained in:
cha0s 2020-12-14 12:13:28 -06:00
parent b270223f4b
commit 1b18e86a8b

View File

@ -64,24 +64,22 @@ export default (latus) => class MessageServer extends Message(latus) {
uuid, uuid,
}]) }])
)); ));
return new Promise((resolve, reject) => { return new Promise((r, e) => {
const rendered = renderChannel(channel); const rendered = renderChannel(channel);
const serverChannel = 'r' === type const serverChannel = 'r' === type
? rendered ? rendered
: `/u/${[name, req.user.redditUsername].sort().join('$')}`; : `/u/${[name, req.user.redditUsername].sort().join('$')}`;
const key = `${serverChannel}:messages:${uuid}`; const key = `${serverChannel}:messages:${uuid}`;
const ttl = channelIsAnonymous(channel) ? 60 : 600;
pubClient pubClient
.multi() .setex(key, ttl, JSON.stringify({
.set(key, JSON.stringify({
distinction, distinction,
ip: req.ip, ip: req.ip,
message, message,
owner, owner,
socket: socket.id, socket: socket.id,
timestamp, timestamp,
})) }), (error) => (error ? e(error) : r([timestamp, uuid])));
.expire(key, channelIsAnonymous(channel) ? 60 : 600)
.exec((error) => (error ? reject(error) : resolve([timestamp, uuid])));
}); });
} }