Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function create(nsp, fn){
var srv = http();
var sio = io(srv);
sio.adapter(adapter({
pubClient: redis(),
subClient: redis(null, null, { return_buffers: true }),
subEvent: 'messageBuffer'
}));
srv.listen(function(err){
if (err) throw err; // abort tests
if ('function' == typeof nsp) {
fn = nsp;
nsp = '';
}
nsp = nsp || '/';
var addr = srv.address();
var url = 'http://localhost:' + addr.port + nsp;
fn(sio.of(nsp), ioc(url));
});
}
'use strict';
var express = require('express');
var router = express.Router();
var redis = require('ioredis');
var redisServer = process.env.redis_server || 'redis-cache';
console.log("Trying to create redis client");
var client = redis.createClient(6379, redisServer);
console.log("Redis Client created");
/* GET home page. */
router.get('/', function (req, res) {
console.log("Index route");
client.incr('viewCount', function (err, result) {
res.render('index', { message: "Total Visits: " + result });
});
});
module.exports = router;
this.instance.storeSubscriptions(client, function() {
var redisClient = redis.createClient();
redisClient.select(opts.db);
redisClient.exists(redisClientSubscriptionKey, function(err, existence) {
expect(!!existence).to.eql(true);
redisClient.quit(done);
});
});
});
'use strict'
const redis = require('ioredis')
const assert = require('assert')
const _ = require('lodash')
const Store = require('../lib/store')
const client = redis.createClient()
describe('Store', () => {
const store = createStore({
references: {
user_id: true,
ip: true
}
})
let id
it('should create a session id', () => {
id = store.createSessionId()
assert.equal('string', typeof id)
})
it('non-existent sessions should return an empty object', () => {
function flush(cb) {
var client = redis.createClient();
client.select(opts.db);
client.flushdb(function() {
client.quit(cb);
});
}
function flush() {
var client = redis.createClient();
client.flushdb(function() {
client.quit(cb);
});
}
tracing: {
forceTransmissionStartingAt: 1
}
});
var bodyParser = require('body-parser');
var express = require('express');
var morgan = require('morgan');
var redis = require('ioredis');
var request = require('request-promise');
var app = express();
var logPrefix = 'Express / Redis App (' + process.pid + '):\t';
var connectedToRedis = true;
var client = redis.createClient('//' + process.env.REDIS);
client.on('ready', function() {
connectedToRedis = true;
});
if (process.env.WITH_STDOUT) {
app.use(morgan(logPrefix + ':method :url :status'));
}
app.use(bodyParser.json());
app.get('/', function(req, res) {
if (!connectedToRedis) {
res.sendStatus(500);
} else {
res.sendStatus(200);
connect: async function () {
this.redis = Redis.createClient(this.connectionDetails.port, this.connectionDetails.host, this.connectionDetails.options)
this.redis.setMaxListeners(0)
if (this.connectionDetails.password !== null && this.connectionDetails.password !== '') {
await this.redis.auth(this.connectionDetails.password)
}
await this.redis.select(this.connectionDetails.database)
this.connectionDetails.redis = this.redis
},
'use strict'
const _request = require('supertest')
const assert = require('assert')
const redis = require('ioredis')
const Koa = require('koa')
const Session = require('..')
const client = redis.createClient()
const keys = ['asdf', '1234']
beforeAll(() => client.flushall())
describe('context.session', () => {
describe('should get and set the session', () => {
const app = new Koa()
app.keys = keys
app.use(Session(app, {
maxAge: '28 days',
signed: false,
prefix: 'asdf',
references: {
string: {}
},
client
this.connected = false
this.emit('error', error)
}
}
if (this.options.redis) {
this.redis = this.options.redis
await connectionTest()
} else {
if (this.options.pkg === 'ioredis') {
const Pkg = require('ioredis')
this.options.options.db = this.options.database
this.redis = new Pkg(this.options.host, this.options.port, this.options.options)
} else {
const Pkg = require(this.options.pkg)
this.redis = Pkg.createClient(this.options.port, this.options.host, this.options.options)
}
}
this.listeners.error = (error) => { this.emit('error', error) }
this.listeners.end = () => { this.connected = false }
this.redis.on('error', this.listeners.error)
this.redis.on('end', this.listeners.end)
if (!this.options.redis) { await this.redis.select(this.options.database) }
await connectionTest()
}