mirror of
https://github.com/abrendan/MicDropMessages.git
synced 2025-08-25 05:52:02 +02:00
Initial commit
This commit is contained in:
11
node_modules/connect-redis/.eslintrc
generated
vendored
Normal file
11
node_modules/connect-redis/.eslintrc
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"env": {
|
||||
"node": true
|
||||
},
|
||||
"extends": "eslint:recommended",
|
||||
"rules": {
|
||||
"semi": 2,
|
||||
"quotes": [2, "single"],
|
||||
"no-console": 0
|
||||
}
|
||||
}
|
211
node_modules/connect-redis/History.md
generated
vendored
Normal file
211
node_modules/connect-redis/History.md
generated
vendored
Normal file
@@ -0,0 +1,211 @@
|
||||
# 3.4.1 / 2018-09-28
|
||||
|
||||
- Update debug dependency
|
||||
- Do not require node_redis dependency
|
||||
|
||||
# 3.4.0 / 2018-09-28
|
||||
|
||||
- Update dependencies [knoxcard]
|
||||
- Corrected session maxAge const path [rudfoss]
|
||||
|
||||
# 3.3.3 / 2018-01-02
|
||||
|
||||
- Fix error when no keys [ranjan14196]
|
||||
- Ensure resave value is defined [kevinsimper]
|
||||
|
||||
# 3.3.2 / 2017-09-28
|
||||
|
||||
- Allow strings for store.ttl [tswaters]
|
||||
|
||||
# 3.3.1 / 2017-09-28
|
||||
|
||||
- Updated Dependency Version [MeesterHok]
|
||||
- Add support for store.ttl fn. [STRML]
|
||||
|
||||
# 3.3.0 / 2017-05-02
|
||||
|
||||
- Update tests.
|
||||
- Use Redis SCAN and MGET commands in ids() and all() [naholyr]
|
||||
|
||||
# 3.2.0 / 2016-12-24
|
||||
|
||||
- Implement .all(), introduce .ids() [anotherpit]
|
||||
- Allow .destroy to take an array of sids [barisusakli]
|
||||
- Update docs [kidlj]
|
||||
- Document defaults for ttl and db [pasieronen]
|
||||
|
||||
# 3.1.0 / 2016-06-16
|
||||
|
||||
- Add logErrors option [r3wt]
|
||||
|
||||
# 3.0.2 / 2016-01-08
|
||||
|
||||
- Do not pass prefix option to redis client [Josh-a-e]
|
||||
|
||||
# 3.0.1 / 2015-10-15
|
||||
|
||||
- Remove attempts option added in 3.0 to enable reconnect again [fintura]
|
||||
|
||||
# 3.0.0 / 2015-10-03
|
||||
|
||||
- Update node_redis to 2.0, reinstate `url` option [fintura]
|
||||
|
||||
# 2.5.1 / 2015-09-18
|
||||
|
||||
- Prevent RedisStore constructor from being called as a normal function [venning]
|
||||
|
||||
# 2.5.0 / 2015-08-28
|
||||
|
||||
- Add support to override serializer
|
||||
- Add io-redis test
|
||||
|
||||
# 2.4.1 / 2015-07-24
|
||||
|
||||
- Make touch a noop when disableTTY is set
|
||||
|
||||
# 2.4.0 / 2015-07-10
|
||||
|
||||
- Add custom client support
|
||||
- Add debug statement for redis client errors [scriptoLLC]
|
||||
- Fix use Math.floor instead of |0 trick
|
||||
- Removed send_anyway magic (unused)
|
||||
|
||||
# 2.3.0 / 2015-04-28
|
||||
|
||||
- add; `touch` / support `resave: false` [stuartpb]
|
||||
- mod; package.json license [mikaturunen]
|
||||
|
||||
# 2.2.0 / 2015-01-26
|
||||
|
||||
- add; option to disable setting a TTL [despairblue]
|
||||
- mod; forward redis errors to session callbacks
|
||||
- mod; pass error object on disconnect
|
||||
|
||||
# 2.1.0 / 2014-08-29
|
||||
|
||||
- add; unref option
|
||||
- dep; redis@0.12.x
|
||||
- mod; deprecate warning for url param
|
||||
|
||||
# 2.0.0 / 2014-03-06
|
||||
|
||||
- update to express 4x
|
||||
|
||||
# 1.4.7 / 2014-03-06
|
||||
|
||||
- allow redis url
|
||||
|
||||
# 1.4.6 / 2013-11-13
|
||||
|
||||
- lazy load redis. fixes #56
|
||||
- update redis to 0.9.0
|
||||
- added Unit tests ready for travis
|
||||
- added repository field to package.json
|
||||
|
||||
# 1.4.5 / 2012-11-02
|
||||
|
||||
- revert to redis 0.7.x which actually works...
|
||||
|
||||
# 1.4.4 / 2012-09-12
|
||||
|
||||
- update redis to 0.8.1 for "import bug fix?"
|
||||
|
||||
# 1.4.3 / 2012-09-11
|
||||
|
||||
- add license. Closes #58
|
||||
- peg redis to 0.8.0
|
||||
|
||||
# 1.4.2 / 2012-09-05
|
||||
|
||||
- add disconnect / connect events
|
||||
|
||||
# 1.4.1 / 2012-07-26
|
||||
|
||||
- fix ignoring of .get() error
|
||||
|
||||
# 1.4.0 / 2012-06-14
|
||||
|
||||
- Added `ttl` option [Vyacheslav Bazhinov]
|
||||
|
||||
# 1.3.0 / 2012-03-23
|
||||
|
||||
- Added debug() instrumentation
|
||||
|
||||
# 1.2.0 / 2011-11-17
|
||||
|
||||
- Added an option 'client' to reuse an existing redis Client [Thomas Fritz]
|
||||
|
||||
# 1.1.0 / 2011-10-05
|
||||
|
||||
- Added `prefix` option
|
||||
- Removed `clear()` and `length()` methods
|
||||
|
||||
# 1.0.7 / 2011-08-04
|
||||
|
||||
- Fixed: re-select db on connection (reconnection logic issue with node_redis)
|
||||
|
||||
# 1.0.6 / 2011-06-21
|
||||
|
||||
- Added `socket` option so that we can connect to a sockets as well [mekwall]
|
||||
|
||||
# 1.0.5 / 2011-06-02
|
||||
|
||||
- Implemented `require("connect-redis")(connect)` for npm 1.x. Closes #23
|
||||
|
||||
# 1.0.4 / 2011-05-01
|
||||
|
||||
- Changed; issue SELECT immediately since it is queued
|
||||
|
||||
# 1.0.3 / 2011-04-17
|
||||
|
||||
- Fixed auth support again [garrensmith]
|
||||
|
||||
# 1.0.2 / 2011-04-15
|
||||
|
||||
- Fixed auth support [garrensmith]
|
||||
|
||||
# 1.0.1 / 2011-04-14
|
||||
|
||||
- Added authentication support [garrensmith]
|
||||
|
||||
# 1.0.0 / 2011-02-25
|
||||
|
||||
- Added connect 1.0 support. This release will _not_ work with older versions of connect.
|
||||
|
||||
# 0.2.3 / 2011-02-01
|
||||
|
||||
- Refactoring
|
||||
|
||||
# 0.2.2 / 2011-01-02
|
||||
|
||||
- Added `db` option [Clément]
|
||||
|
||||
# 0.2.1 / 2010-12-20
|
||||
|
||||
- Redis is now an npm dep
|
||||
|
||||
# 0.2.0 / 2010-11-01
|
||||
|
||||
- Use **SETEX** instead of **SET** / **EXPIRE** combo this should be reasonably faster.
|
||||
|
||||
# 0.1.3 / 2010-10-25
|
||||
|
||||
- Updated redis
|
||||
|
||||
# 0.1.2 / 2010-09-22
|
||||
|
||||
- Updated redis
|
||||
|
||||
# 0.1.1 / 2010-09-20
|
||||
|
||||
- Fixed expires, `maxAge` in seconds
|
||||
- Updated redis
|
||||
|
||||
# 0.1.0 / 2010-09-17
|
||||
|
||||
- Now using node_redis as the client, much faster
|
||||
|
||||
# 0.0.2 / 2010-07-27
|
||||
|
||||
- Moved redis to lib/redis
|
||||
- Added lib/connect-redis.js
|
87
node_modules/connect-redis/Readme.md
generated
vendored
Normal file
87
node_modules/connect-redis/Readme.md
generated
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
[](https://npmjs.com/package/connect-redis) [](https://david-dm.org/tj/connect-redis) 
|
||||
|
||||
**connect-redis** is a Redis session store backed by [node_redis](http://github.com/mranney/node_redis), and is insanely fast :). Requires redis >= `2.0.0` for the *SETEX* command.
|
||||
|
||||
Setup
|
||||
-----
|
||||
|
||||
```sh
|
||||
npm install connect-redis express-session
|
||||
```
|
||||
|
||||
Pass the `express-session` store into `connect-redis` to create a `RedisStore` constructor.
|
||||
|
||||
```js
|
||||
var session = require('express-session');
|
||||
var RedisStore = require('connect-redis')(session);
|
||||
|
||||
app.use(session({
|
||||
store: new RedisStore(options),
|
||||
secret: 'keyboard cat',
|
||||
resave: false
|
||||
}));
|
||||
```
|
||||
|
||||
Options
|
||||
-------
|
||||
|
||||
A Redis client is required. An existing client can be passed directly using the `client` param or created for you using the `host`, `port`, or `socket` params.
|
||||
|
||||
- `client` An existing client
|
||||
- `host` Redis server hostname
|
||||
- `port` Redis server portno
|
||||
- `socket` Redis server unix_socket
|
||||
- `url` Redis server url
|
||||
|
||||
The following additional params may be included:
|
||||
|
||||
- `ttl` Redis session TTL (expiration) in seconds. Defaults to session.cookie.maxAge (if set), or one day.
|
||||
- This may also be set to a function of the form `(store, sess, sessionID) => number`.
|
||||
- `disableTTL` Disables setting TTL, keys will stay in redis until evicted by other means (overides `ttl`\)
|
||||
- `db` Database index to use. Defaults to Redis's default (0).
|
||||
- `pass` Password for Redis authentication
|
||||
- `prefix` Key prefix defaulting to "sess:"
|
||||
- `unref` Set `true` to unref the Redis client. **Warning**: this is [an experimental feature](https://github.com/mranney/node_redis#clientunref).
|
||||
- `serializer` An object containing `stringify` and `parse` methods compatible with Javascript's `JSON` to override the serializer used
|
||||
- `logErrors` Whether or not to log client errors. (default: `false`\)
|
||||
- If `true`, a default logging function (`console.error`) is provided.
|
||||
- If a function, it is called anytime an error occurs (useful for custom logging)
|
||||
- If `false`, no logging occurs.
|
||||
- `scanCount` Value used for *count* parameter in [Redis `SCAN` command](https://redis.io/commands/scan#the-count-option) (used in `ids()` and `all()` methods, defaults to 100).
|
||||
|
||||
Any options not included in this list will be passed to the redis `createClient()` method directly.
|
||||
|
||||
Custom Redis clients
|
||||
--------------------
|
||||
|
||||
Clients other than `node_redis` will work if they support the same interface. Just pass the client instance as the `client` configuration option. Known supported clients include:
|
||||
|
||||
- [ioredis](https://github.com/luin/ioredis) - adds support for Redis Sentinel and Cluster
|
||||
|
||||
#### Testing / Development
|
||||
|
||||
You can use [redis-mock](https://github.com/yeahoffline/redis-mock) as the client instead of connecting to an actual redis server for automated testing and development purposes.
|
||||
|
||||
FAQ
|
||||
---
|
||||
|
||||
#### How do I handle lost connections to Redis?
|
||||
|
||||
By default, the `node_redis` client will [auto-reconnect](https://github.com/mranney/node_redis#overloading) when a connection is lost. But requests may come in during that time. In Express, this scenario can be handled by including a "session check".
|
||||
|
||||
```js
|
||||
app.use(session( /* setup session here */ ))
|
||||
app.use(function (req, res, next) {
|
||||
if (!req.session) {
|
||||
return next(new Error('oh no')) // handle error
|
||||
}
|
||||
next() // otherwise continue
|
||||
})
|
||||
```
|
||||
|
||||
If you want to retry, here is [another option](https://github.com/expressjs/session/issues/99#issuecomment-63853989).
|
||||
|
||||
License
|
||||
=======
|
||||
|
||||
MIT
|
23
node_modules/connect-redis/bench/redisbench.js
generated
vendored
Normal file
23
node_modules/connect-redis/bench/redisbench.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
var P = require('bluebird');
|
||||
var session = require('express-session');
|
||||
var RedisStore = require('../')(session);
|
||||
|
||||
var count = 100000;
|
||||
var i = 0;
|
||||
var tasks = [];
|
||||
|
||||
console.time('bench ' + count);
|
||||
|
||||
var store = P.promisifyAll(new RedisStore({
|
||||
host: 'localhost',
|
||||
port: 6379
|
||||
}));
|
||||
|
||||
for (; i < count; i++) {
|
||||
tasks.push(store.setAsync('testsession' + i, { cookie: { maxAge: 2000 }, name: 'sample name' }));
|
||||
}
|
||||
|
||||
P.all(tasks).then(function () {
|
||||
console.timeEnd('bench ' + count);
|
||||
process.exit(0);
|
||||
});
|
1
node_modules/connect-redis/index.js
generated
vendored
Normal file
1
node_modules/connect-redis/index.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = require('./lib/connect-redis');
|
375
node_modules/connect-redis/lib/connect-redis.js
generated
vendored
Normal file
375
node_modules/connect-redis/lib/connect-redis.js
generated
vendored
Normal file
@@ -0,0 +1,375 @@
|
||||
/*!
|
||||
* Connect - Redis
|
||||
* Copyright(c) 2012 TJ Holowaychuk <tj@vision-media.ca>
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
var debug = require('debug')('connect:redis');
|
||||
var util = require('util');
|
||||
var noop = function(){};
|
||||
|
||||
/**
|
||||
* One day in seconds.
|
||||
*/
|
||||
|
||||
var oneDay = 86400;
|
||||
|
||||
function getTTL(store, sess, sid) {
|
||||
if (typeof store.ttl === 'number' || typeof store.ttl === 'string') return store.ttl;
|
||||
if (typeof store.ttl === 'function') return store.ttl(store, sess, sid);
|
||||
if (store.ttl) throw new TypeError('`store.ttl` must be a number or function.');
|
||||
|
||||
var maxAge = sess.cookie.maxAge;
|
||||
return (typeof maxAge === 'number'
|
||||
? Math.floor(maxAge / 1000)
|
||||
: oneDay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the `RedisStore` extending `express`'s session Store.
|
||||
*
|
||||
* @param {object} express session
|
||||
* @return {Function}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
module.exports = function (session) {
|
||||
|
||||
/**
|
||||
* Express's session Store.
|
||||
*/
|
||||
|
||||
var Store = session.Store;
|
||||
|
||||
/**
|
||||
* Initialize RedisStore with the given `options`.
|
||||
*
|
||||
* @param {Object} options
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function RedisStore (options) {
|
||||
if (!(this instanceof RedisStore)) {
|
||||
throw new TypeError('Cannot call RedisStore constructor as a function');
|
||||
}
|
||||
|
||||
var self = this;
|
||||
|
||||
options = options || {};
|
||||
Store.call(this, options);
|
||||
this.prefix = options.prefix == null
|
||||
? 'sess:'
|
||||
: options.prefix;
|
||||
|
||||
delete options.prefix;
|
||||
|
||||
this.scanCount = Number(options.scanCount) || 100;
|
||||
delete options.scanCount;
|
||||
|
||||
this.serializer = options.serializer || JSON;
|
||||
|
||||
if (options.url) {
|
||||
options.socket = options.url;
|
||||
}
|
||||
|
||||
// convert to redis connect params
|
||||
if (options.client) {
|
||||
this.client = options.client;
|
||||
} else {
|
||||
var redis = require('redis');
|
||||
|
||||
if (options.socket) {
|
||||
this.client = redis.createClient(options.socket, options);
|
||||
}
|
||||
else {
|
||||
this.client = redis.createClient(options);
|
||||
}
|
||||
}
|
||||
|
||||
// logErrors
|
||||
if(options.logErrors){
|
||||
// if options.logErrors is function, allow it to override. else provide default logger. useful for large scale deployment
|
||||
// which may need to write to a distributed log
|
||||
if(typeof options.logErrors != 'function'){
|
||||
options.logErrors = function (err) {
|
||||
console.error('Warning: connect-redis reported a client error: ' + err);
|
||||
};
|
||||
}
|
||||
this.client.on('error', options.logErrors);
|
||||
}
|
||||
|
||||
if (options.pass) {
|
||||
this.client.auth(options.pass, function (err) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.ttl = options.ttl;
|
||||
this.disableTTL = options.disableTTL;
|
||||
|
||||
if (options.unref) this.client.unref();
|
||||
|
||||
if ('db' in options) {
|
||||
if (typeof options.db !== 'number') {
|
||||
console.error('Warning: connect-redis expects a number for the "db" option');
|
||||
}
|
||||
|
||||
self.client.select(options.db);
|
||||
self.client.on('connect', function () {
|
||||
self.client.select(options.db);
|
||||
});
|
||||
}
|
||||
|
||||
self.client.on('error', function (er) {
|
||||
debug('Redis returned err', er);
|
||||
self.emit('disconnect', er);
|
||||
});
|
||||
|
||||
self.client.on('connect', function () {
|
||||
self.emit('connect');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `Store`.
|
||||
*/
|
||||
|
||||
util.inherits(RedisStore, Store);
|
||||
|
||||
/**
|
||||
* Attempt to fetch session by the given `sid`.
|
||||
*
|
||||
* @param {String} sid
|
||||
* @param {Function} fn
|
||||
* @api public
|
||||
*/
|
||||
|
||||
RedisStore.prototype.get = function (sid, fn) {
|
||||
var store = this;
|
||||
var psid = store.prefix + sid;
|
||||
if (!fn) fn = noop;
|
||||
debug('GET "%s"', sid);
|
||||
|
||||
store.client.get(psid, function (er, data) {
|
||||
if (er) return fn(er);
|
||||
if (!data) return fn();
|
||||
|
||||
var result;
|
||||
data = data.toString();
|
||||
debug('GOT %s', data);
|
||||
|
||||
try {
|
||||
result = store.serializer.parse(data);
|
||||
}
|
||||
catch (er) {
|
||||
return fn(er);
|
||||
}
|
||||
return fn(null, result);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Commit the given `sess` object associated with the given `sid`.
|
||||
*
|
||||
* @param {String} sid
|
||||
* @param {Session} sess
|
||||
* @param {Function} fn
|
||||
* @api public
|
||||
*/
|
||||
|
||||
RedisStore.prototype.set = function (sid, sess, fn) {
|
||||
var store = this;
|
||||
var args = [store.prefix + sid];
|
||||
if (!fn) fn = noop;
|
||||
|
||||
try {
|
||||
var jsess = store.serializer.stringify(sess);
|
||||
}
|
||||
catch (er) {
|
||||
return fn(er);
|
||||
}
|
||||
|
||||
args.push(jsess);
|
||||
|
||||
if (!store.disableTTL) {
|
||||
var ttl = getTTL(store, sess, sid);
|
||||
args.push('EX', ttl);
|
||||
debug('SET "%s" %s ttl:%s', sid, jsess, ttl);
|
||||
} else {
|
||||
debug('SET "%s" %s', sid, jsess);
|
||||
}
|
||||
|
||||
store.client.set(args, function (er) {
|
||||
if (er) return fn(er);
|
||||
debug('SET complete');
|
||||
fn.apply(null, arguments);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Destroy the session associated with the given `sid`.
|
||||
*
|
||||
* @param {String} sid
|
||||
* @api public
|
||||
*/
|
||||
|
||||
RedisStore.prototype.destroy = function (sid, fn) {
|
||||
debug('DEL "%s"', sid);
|
||||
if (!fn) fn = noop;
|
||||
|
||||
if (Array.isArray(sid)) {
|
||||
var multi = this.client.multi();
|
||||
var prefix = this.prefix;
|
||||
sid.forEach(function (s) {
|
||||
multi.del(prefix + s);
|
||||
});
|
||||
multi.exec(fn);
|
||||
} else {
|
||||
sid = this.prefix + sid;
|
||||
this.client.del(sid, fn);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Refresh the time-to-live for the session with the given `sid`.
|
||||
*
|
||||
* @param {String} sid
|
||||
* @param {Session} sess
|
||||
* @param {Function} fn
|
||||
* @api public
|
||||
*/
|
||||
|
||||
RedisStore.prototype.touch = function (sid, sess, fn) {
|
||||
var store = this;
|
||||
var psid = store.prefix + sid;
|
||||
if (!fn) fn = noop;
|
||||
if (store.disableTTL) return fn();
|
||||
|
||||
var ttl = getTTL(store, sess);
|
||||
|
||||
debug('EXPIRE "%s" ttl:%s', sid, ttl);
|
||||
store.client.expire(psid, ttl, function (er) {
|
||||
if (er) return fn(er);
|
||||
debug('EXPIRE complete');
|
||||
fn.apply(this, arguments);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Fetch all sessions' Redis keys using non-blocking SCAN command
|
||||
*
|
||||
* @param {Function} fn
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function allKeys (store, cb) {
|
||||
var keysObj = {}; // Use an object to dedupe as scan can return duplicates
|
||||
var pattern = store.prefix + '*';
|
||||
var scanCount = store.scanCount;
|
||||
debug('SCAN "%s"', pattern);
|
||||
(function nextBatch (cursorId) {
|
||||
store.client.scan(cursorId, 'match', pattern, 'count', scanCount, function (err, result) {
|
||||
if (err) return cb(err);
|
||||
|
||||
var nextCursorId = result[0];
|
||||
var keys = result[1];
|
||||
|
||||
debug('SCAN complete (next cursor = "%s")', nextCursorId);
|
||||
|
||||
keys.forEach(function (key) {
|
||||
keysObj[key] = 1;
|
||||
});
|
||||
|
||||
if (nextCursorId != 0) {
|
||||
// next batch
|
||||
return nextBatch(nextCursorId);
|
||||
}
|
||||
|
||||
// end of cursor
|
||||
return cb(null, Object.keys(keysObj));
|
||||
});
|
||||
})(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch all sessions' ids
|
||||
*
|
||||
* @param {Function} fn
|
||||
* @api public
|
||||
*/
|
||||
|
||||
RedisStore.prototype.ids = function (fn) {
|
||||
var store = this;
|
||||
var prefixLength = store.prefix.length;
|
||||
if (!fn) fn = noop;
|
||||
|
||||
allKeys(store, function (err, keys) {
|
||||
if (err) return fn(err);
|
||||
|
||||
keys = keys.map(function (key) {
|
||||
return key.substr(prefixLength);
|
||||
});
|
||||
return fn(null, keys);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Fetch count of all sessions
|
||||
*
|
||||
* @param {Function} fn
|
||||
* @api public
|
||||
*/
|
||||
|
||||
RedisStore.prototype.length = function (fn) {
|
||||
var store = this;
|
||||
if (!fn) fn = noop;
|
||||
|
||||
allKeys(store, function (err, keys) {
|
||||
if (err) return fn(err);
|
||||
|
||||
return fn(null, keys.length);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Fetch all sessions
|
||||
*
|
||||
* @param {Function} fn
|
||||
* @api public
|
||||
*/
|
||||
|
||||
RedisStore.prototype.all = function (fn) {
|
||||
var store = this;
|
||||
var prefixLength = store.prefix.length;
|
||||
if (!fn) fn = noop;
|
||||
|
||||
allKeys(store, function (err, keys) {
|
||||
if (err) return fn(err);
|
||||
|
||||
if (keys.length === 0) return fn(null,[]);
|
||||
|
||||
store.client.mget(keys, function (err, sessions) {
|
||||
if (err) return fn(err);
|
||||
|
||||
var result;
|
||||
try {
|
||||
result = sessions.map(function (data, index) {
|
||||
data = data.toString();
|
||||
data = store.serializer.parse(data);
|
||||
data.id = keys[index].substr(prefixLength);
|
||||
return data;
|
||||
});
|
||||
} catch (e) {
|
||||
err = e;
|
||||
}
|
||||
|
||||
return fn(err, result);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
return RedisStore;
|
||||
};
|
73
node_modules/connect-redis/package.json
generated
vendored
Normal file
73
node_modules/connect-redis/package.json
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
{
|
||||
"_from": "connect-redis@^3.3.0",
|
||||
"_id": "connect-redis@3.4.2",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-ozA1Z0GDnsCJECfNyNJOqPuW3Fk43fUbKC65Sa/V9hkCBNtXsFU2xtTOVsQGUsflpywuJMgGOV4xrnKzIPFqvA==",
|
||||
"_location": "/connect-redis",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "connect-redis@^3.3.0",
|
||||
"name": "connect-redis",
|
||||
"escapedName": "connect-redis",
|
||||
"rawSpec": "^3.3.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^3.3.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/server"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/connect-redis/-/connect-redis-3.4.2.tgz",
|
||||
"_shasum": "e339fd0b00e1381e130101556657669cc855417e",
|
||||
"_spec": "connect-redis@^3.3.0",
|
||||
"_where": "/home/runner/Socketio-Chat-Template/node_modules/server",
|
||||
"author": {
|
||||
"name": "TJ Holowaychuk",
|
||||
"email": "tj@vision-media.ca"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/visionmedia/connect-redis/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Marc Harter",
|
||||
"email": "wavded@gmail.com"
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"debug": "^4.1.1",
|
||||
"redis": "^2.8.0"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Redis session store for Connect",
|
||||
"devDependencies": {
|
||||
"blue-tape": "^1.0.0",
|
||||
"bluebird": "^3.5.5",
|
||||
"eslint": "^3.19.0",
|
||||
"express-session": "^1.16.2",
|
||||
"ioredis": "^4.10.0",
|
||||
"istanbul": "^0.4.5",
|
||||
"sinon": "^2.3.4",
|
||||
"tape": "^4.2.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": "*"
|
||||
},
|
||||
"homepage": "https://github.com/visionmedia/connect-redis#readme",
|
||||
"license": "MIT",
|
||||
"main": "./index.js",
|
||||
"name": "connect-redis",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@github.com/visionmedia/connect-redis.git"
|
||||
},
|
||||
"scripts": {
|
||||
"bench": "node bench/redisbench.js",
|
||||
"lint": "eslint index.js test lib bench",
|
||||
"test": "istanbul cover tape \"test/*-test.js\"",
|
||||
"test-debug": "DEBUG=* istanbul cover tape \"test/*-test.js\""
|
||||
},
|
||||
"version": "3.4.2"
|
||||
}
|
212
node_modules/connect-redis/test/connect-redis-test.js
generated
vendored
Normal file
212
node_modules/connect-redis/test/connect-redis-test.js
generated
vendored
Normal file
@@ -0,0 +1,212 @@
|
||||
/* eslint-env es6 */
|
||||
var test = require('blue-tape');
|
||||
var redisSrv = require('./redis-server');
|
||||
var session = require('express-session');
|
||||
var RedisStore = require('../')(session);
|
||||
var redis = require('redis');
|
||||
var ioRedis = require('ioredis');
|
||||
var sinon = require('sinon');
|
||||
var P = require('bluebird');
|
||||
|
||||
var lifecycleTest = P.coroutine(function *(store, t) {
|
||||
P.promisifyAll(store);
|
||||
|
||||
var ok = yield store.setAsync('123', { cookie: { maxAge: 2000 }, name: 'tj' });
|
||||
t.equal(ok, 'OK', '#set() ok');
|
||||
|
||||
var data = yield store.getAsync('123');
|
||||
t.deepEqual({ cookie: { maxAge: 2000 }, name: 'tj' }, data, '#get() ok');
|
||||
|
||||
ok = yield store.setAsync('123', { cookie: { maxAge: undefined }, name: 'tj' });
|
||||
t.equal(ok, 'OK', '#set() no maxAge ok');
|
||||
|
||||
data = yield store.allAsync();
|
||||
t.deepEqual([{ id: '123', cookie: {}, name: 'tj' }], data, '#all() ok');
|
||||
|
||||
data = yield store.idsAsync();
|
||||
t.deepEqual(['123'], data, '#ids() ok');
|
||||
|
||||
data = yield store.lengthAsync();
|
||||
t.deepEqual(1, data, '#length() ok');
|
||||
|
||||
ok = yield store.destroyAsync('123');
|
||||
t.equal(ok, 1, '#destroy() ok');
|
||||
|
||||
store.client.end(false);
|
||||
});
|
||||
|
||||
test('setup', redisSrv.connect);
|
||||
|
||||
test('defaults', function (t) {
|
||||
var store = new RedisStore();
|
||||
t.equal(store.prefix, 'sess:', 'defaults to sess:');
|
||||
t.notOk(store.ttl, 'ttl not set');
|
||||
t.notOk(store.disableTTL, 'disableTTL not set');
|
||||
t.ok(store.client, 'creates client');
|
||||
|
||||
store.client.end(false);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('basic', function (t) {
|
||||
t.throws(RedisStore, TypeError, 'constructor not callable as function');
|
||||
var store = new RedisStore({ port: redisSrv.port });
|
||||
return lifecycleTest(store, t);
|
||||
});
|
||||
|
||||
test('existing client', function (t) {
|
||||
var client = redis.createClient(redisSrv.port, 'localhost');
|
||||
var store = new RedisStore({ client: client });
|
||||
return lifecycleTest(store, t);
|
||||
});
|
||||
|
||||
test('io redis client', function (t) {
|
||||
var client = ioRedis.createClient(redisSrv.port, 'localhost');
|
||||
var store = new RedisStore({ client: client });
|
||||
return lifecycleTest(store, t).then(function () {
|
||||
t.test('#destroy()', function (p) {
|
||||
var spy = sinon.spy(ioRedis.prototype, 'sendCommand');
|
||||
var sidName = 'randomname';
|
||||
store.destroy(sidName);
|
||||
p.deepEqual(
|
||||
spy.firstCall.args[0].args,
|
||||
[store.prefix + sidName]
|
||||
);
|
||||
spy.restore();
|
||||
p.end();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('options', function (t) {
|
||||
var store = new RedisStore({
|
||||
host: 'localhost',
|
||||
port: redisSrv.port,
|
||||
prefix: 'tobi',
|
||||
ttl: 1000,
|
||||
disableTTL: true,
|
||||
db: 1,
|
||||
scanCount: 32,
|
||||
unref: true,
|
||||
pass: 'secret'
|
||||
});
|
||||
|
||||
t.equal(store.prefix, 'tobi', 'uses provided prefix');
|
||||
t.equal(store.ttl, 1000, 'ttl set');
|
||||
t.ok(store.disableTTL, 'disableTTL set');
|
||||
t.ok(store.client, 'creates client');
|
||||
t.equal(store.client.address, 'localhost:'+redisSrv.port, 'sets host and port');
|
||||
t.equal(store.scanCount, 32, 'sets scan count');
|
||||
|
||||
var socketStore = new RedisStore({ socket: 'word' });
|
||||
t.equal(socketStore.client.address, 'word', 'sets socket address');
|
||||
socketStore.client.end(false);
|
||||
|
||||
var urlStore = new RedisStore({ url: 'redis://127.0.0.1:8888' });
|
||||
t.equal(urlStore.client.address, '127.0.0.1:8888', 'sets url address');
|
||||
urlStore.client.end(false);
|
||||
|
||||
var hostNoPort = new RedisStore({ host: 'host' });
|
||||
t.equal(hostNoPort.client.address, 'host:6379', 'sets default port');
|
||||
hostNoPort.client.end(false);
|
||||
|
||||
return lifecycleTest(store, t);
|
||||
});
|
||||
|
||||
test('ttl options', P.coroutine(function *(t) {
|
||||
var store = new RedisStore({ port: redisSrv.port });
|
||||
|
||||
var sid = '123';
|
||||
var data, ok;
|
||||
sinon.stub(store.client, 'set').callsArgWith(1, null, 'OK');
|
||||
P.promisifyAll(store);
|
||||
|
||||
// Basic (one day)
|
||||
data = { cookie: {}, name: 'tj' };
|
||||
ok = yield store.setAsync(sid, data);
|
||||
t.equal(ok, 'OK', '#set() ok');
|
||||
assertSetCalledWith(t, store, sid, data, ['EX', 86400]);
|
||||
|
||||
// maxAge in cookie
|
||||
data = { cookie: { maxAge: 2000 }, name: 'tj' };
|
||||
ok = yield store.setAsync(sid, data);
|
||||
t.equal(ok, 'OK', '#set() ok');
|
||||
assertSetCalledWith(t, store, sid, data, ['EX', 2]);
|
||||
|
||||
// Floors maxage
|
||||
data = { cookie: { maxAge: 2500 }, name: 'tj' };
|
||||
ok = yield store.setAsync(sid, data);
|
||||
t.equal(ok, 'OK', '#set() ok');
|
||||
assertSetCalledWith(t, store, sid, data, ['EX', 2]);
|
||||
|
||||
// store.disableTTL
|
||||
store.disableTTL = true;
|
||||
data = { cookie: {}, name: 'tj' };
|
||||
ok = yield store.setAsync(sid, data);
|
||||
t.equal(ok, 'OK', '#set() ok');
|
||||
assertSetCalledWith(t, store, sid, data);
|
||||
store.disableTTL = false;
|
||||
|
||||
// store.ttl: number
|
||||
store.ttl = 50;
|
||||
data = { cookie: {}, name: 'tj' };
|
||||
ok = yield store.setAsync(sid, data);
|
||||
t.equal(ok, 'OK', '#set() ok');
|
||||
assertSetCalledWith(t, store, sid, data, ['EX', 50]);
|
||||
store.ttl = null;
|
||||
|
||||
// store.ttl: function
|
||||
store.ttl = sinon.stub().returns(200);
|
||||
data = { cookie: {}, name: 'tj' };
|
||||
ok = yield store.setAsync(sid, data);
|
||||
t.equal(ok, 'OK', '#set() ok');
|
||||
assertSetCalledWith(t, store, sid, data, ['EX', 200]);
|
||||
t.ok(store.ttl.called, 'TTL fn was called');
|
||||
t.deepEqual(store.ttl.firstCall.args, [store, data, sid]);
|
||||
store.ttl = null;
|
||||
|
||||
// store.ttl: string (invalid)
|
||||
store.ttl = {};
|
||||
data = { cookie: {}, name: 'tj' };
|
||||
try {
|
||||
ok = yield store.setAsync(sid, data);
|
||||
t.ok(false, '#set() should throw with bad TTL');
|
||||
} catch (e) {
|
||||
t.ok(/must be a number or function/i.test(e.message), 'bad TTL type throws error');
|
||||
}
|
||||
store.ttl = null;
|
||||
|
||||
store.client.end(false);
|
||||
}));
|
||||
|
||||
function assertSetCalledWith(t, store, sid, data, addl) {
|
||||
var args = [store.prefix + sid, store.serializer.stringify(data)];
|
||||
if (Array.isArray(addl)) args = args.concat(addl);
|
||||
t.deepEqual(store.client.set.lastCall.args[0], args, '#.set() called with expected params');
|
||||
}
|
||||
|
||||
test('interups', function (t) {
|
||||
var store = P.promisifyAll(new RedisStore({ port: redisSrv.port, connect_timeout: 500 }));
|
||||
return store.setAsync('123', { cookie: { maxAge: 2000 }, name: 'tj' })
|
||||
.catch(function (er) {
|
||||
t.ok(/broken/.test(er.message), 'failed connection');
|
||||
store.client.end(false);
|
||||
});
|
||||
});
|
||||
|
||||
test('serializer', function (t) {
|
||||
var serializer = {
|
||||
stringify: function() { return 'XXX'+JSON.stringify.apply(JSON, arguments); },
|
||||
parse: function(x) {
|
||||
t.ok(x.match(/^XXX/));
|
||||
return JSON.parse(x.substring(3));
|
||||
}
|
||||
};
|
||||
t.equal(serializer.stringify('UnitTest'), 'XXX"UnitTest"');
|
||||
t.equal(serializer.parse(serializer.stringify('UnitTest')), 'UnitTest');
|
||||
|
||||
var store = new RedisStore({ port: redisSrv.port, serializer: serializer });
|
||||
return lifecycleTest(store, t);
|
||||
});
|
||||
|
||||
test('teardown', redisSrv.disconnect);
|
17
node_modules/connect-redis/test/redis-server.js
generated
vendored
Normal file
17
node_modules/connect-redis/test/redis-server.js
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
var P = require('bluebird');
|
||||
var spawn = require('child_process').spawn;
|
||||
var redisSrv;
|
||||
var port = exports.port = 18543;
|
||||
|
||||
exports.connect = function () {
|
||||
redisSrv = spawn('redis-server', [
|
||||
'--port', port,
|
||||
'--loglevel', 'notice',
|
||||
], { stdio: 'inherit' });
|
||||
return P.delay(1500);
|
||||
};
|
||||
|
||||
exports.disconnect = function () {
|
||||
redisSrv.kill('SIGKILL');
|
||||
return P.resolve();
|
||||
};
|
Reference in New Issue
Block a user