46 lines
5.4 KiB
JavaScript
46 lines
5.4 KiB
JavaScript
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||
|
});
|
||
|
};
|
||
|
import ApplicationComponent from "../ApplicationComponent";
|
||
|
import redis from "redis";
|
||
|
import config from "config";
|
||
|
import Logger from "../Logger";
|
||
|
import session from "express-session";
|
||
|
import connect_redis from "connect-redis";
|
||
|
const RedisStore = connect_redis(session);
|
||
|
export default class RedisComponent extends ApplicationComponent {
|
||
|
start(app, router) {
|
||
|
return __awaiter(this, void 0, void 0, function* () {
|
||
|
this.redisClient = redis.createClient(config.get('redis.port'), config.get('redis.host'), {});
|
||
|
this.redisClient.on('error', (err) => {
|
||
|
Logger.error(err, 'An error occurred with redis.');
|
||
|
});
|
||
|
this.store = new RedisStore({
|
||
|
client: this.redisClient,
|
||
|
prefix: 'wms-sess:',
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
stop() {
|
||
|
return __awaiter(this, void 0, void 0, function* () {
|
||
|
if (this.redisClient) {
|
||
|
yield this.close('Redis connection', this.redisClient, this.redisClient.quit);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
getStore() {
|
||
|
if (!this.store)
|
||
|
throw `Redis store was not initialized.`;
|
||
|
return this.store;
|
||
|
}
|
||
|
canServe() {
|
||
|
return this.redisClient !== undefined && this.redisClient.connected;
|
||
|
}
|
||
|
}
|
||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUmVkaXNDb21w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