finesse-toolkit
Version:
useful tools for finesse phone system
48 lines • 1.68 kB
JavaScript
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
const Redis = require("ioredis");
const util_1 = require("./util");
const MONTH_IN_SECONDS = 2592000;
// all methods return Promises
class RedisStore {
constructor(redisUrl) {
this._client = new Redis(redisUrl);
}
add(key, value) {
value = JSON.stringify(value);
return this._client.setex(key, MONTH_IN_SECONDS, value)
.catch(util_1.default._promiseErrorHandler);
}
hAdd(hash, key, value) {
return this._client.hset(hash, key, value).catch(util_1.default._promiseErrorHandler);
}
remove(key) {
return this._client.del(key).catch(util_1.default._promiseErrorHandler);
}
hRemove(hash, key) {
return this._client.hdel(hash, key).catch(util_1.default._promiseErrorHandler);
}
get(key) {
return this._client.get(key).then(JSON.parse).catch(util_1.default._promiseErrorHandler);
}
hGet(hash, key) {
return this._client.hget(hash, key).catch(util_1.default._promiseErrorHandler);
}
hGetAll(hash) {
return this._client.hgetall(hash).catch(util_1.default._promiseErrorHandler);
}
hKeys(hash) {
return this._client.hkeys(hash).catch(util_1.default._promiseErrorHandler);
}
exists(key) {
return this._client.exists(key).catch(util_1.default._promiseErrorHandler);
}
hExists(hash, key) {
return this._client.hexists(hash, key).catch(util_1.default._promiseErrorHandler);
}
get isConnected() {
return this._client.status === 'ready';
}
}
exports.default = RedisStore;
//# sourceMappingURL=redisStore.js.map