Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
*set(sid, sess, ttl) {
// clone original sess
sess = {...sess};
const maxAge = sess.cookie && (sess.cookie.maxAge || sess.cookie.maxage);
const col = yield this.col;
const update = thunkify(col.update.bind(col));
sess.sid = sid;
sess.ttl = new Date((ttl || ('number' == typeof maxAge
? maxAge : ONE_DAY)) + Date.now());
return yield update({sid: sid}, sess, {upsert: true});
}
debug('Redis options:', redisOptions);
const db = redisOptions.db || 0
const ttl = this.ttl = redisOptions.ttl || expiresIn || EXPIRES_IN_SECONDS
//redis client for session
this.client = new redis(redisOptions)
const client = this.client;
client.select(db, function () {
debug('redis changed to db %d', db);
});
client.get = thunkify(client.get);
client.exists = thunkify(client.exists);
client.ttl = ttl ? (key)=>{ client.expire(key, ttl); } : ()=>{};
client.on('connect', function () {
debug('redis is connecting');
});
client.on('ready', function () {
debug('redis ready');
});
client.on('reconnect', function () {
debug('redis is reconnecting');
});
client.on('error', function (err) {
debug('redis encouters error: %j', err.stack || err);
*get(sid) {
const col = yield this.col;
const findOne = thunkify(col.findOne.bind(col));
return yield findOne({sid: sid}, {_id: 0, ttl: 0, sid: 0});
}
let redisOptions = opts || {}
debug('Redis options:', redisOptions);
const db = redisOptions.db || 0
const ttl = this.ttl = redisOptions.ttl || expiresIn || EXPIRES_IN_SECONDS
//redis client for session
this.client = new redis(redisOptions)
const client = this.client;
client.select(db, function () {
debug('redis changed to db %d', db);
});
client.get = thunkify(client.get);
client.exists = thunkify(client.exists);
client.ttl = ttl ? (key)=>{ client.expire(key, ttl); } : ()=>{};
client.on('connect', function () {
debug('redis is connecting');
});
client.on('ready', function () {
debug('redis ready');
});
client.on('reconnect', function () {
debug('redis is reconnecting');
});
client.on('error', function (err) {
*destroy(sid) {
const col = yield this.col;
const remove = thunkify(col.remove.bind(col));
yield remove({sid: sid});
}
}