mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-12 04:25:31 +08:00
29 lines
786 B
JavaScript
29 lines
786 B
JavaScript
const bluebird = require('bluebird')
|
|
const redis = require("redis");
|
|
bluebird.promisifyAll(redis.RedisClient.prototype);
|
|
bluebird.promisifyAll(redis.Multi.prototype);
|
|
|
|
class DeltaStreamQueue {
|
|
setup() {
|
|
this.client = redis.createClient();
|
|
this.client.on("error", console.error);
|
|
this.client.on("ready", () => console.log("Redis ready"));
|
|
}
|
|
|
|
key(accountId) {
|
|
return `delta-${accountId}`
|
|
}
|
|
|
|
hasSubscribers(accountId) {
|
|
return this.client.existsAsync(this.key(accountId))
|
|
}
|
|
|
|
notify(accountId, data) {
|
|
return this.hasSubscribers(accountId).then((hasSubscribers) => {
|
|
if (!hasSubscribers) return Promise.resolve()
|
|
return this.client.rpushAsync(this.key(accountId), JSON.stringify(data))
|
|
})
|
|
}
|
|
}
|
|
|
|
module.exports = new DeltaStreamQueue()
|