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,
}])
));
return new Promise((resolve, reject) => {
return new Promise((r, e) => {
const rendered = renderChannel(channel);
const serverChannel = 'r' === type
? rendered
: `/u/${[name, req.user.redditUsername].sort().join('$')}`;
const key = `${serverChannel}:messages:${uuid}`;
const ttl = channelIsAnonymous(channel) ? 60 : 600;
pubClient
.multi()
.set(key, JSON.stringify({
.setex(key, ttl, JSON.stringify({
distinction,
ip: req.ip,
message,
owner,
socket: socket.id,
timestamp,
}))
.expire(key, channelIsAnonymous(channel) ? 60 : 600)
.exec((error) => (error ? reject(error) : resolve([timestamp, uuid])));
}), (error) => (error ? e(error) : r([timestamp, uuid])));
});
}