Skip to content

Commit

Permalink
Update node redis to 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben Bridgewater committed Sep 25, 2015
1 parent dcbc43d commit 334e9ef
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 29 deletions.
5 changes: 1 addition & 4 deletions Readme.md
Expand Up @@ -21,6 +21,7 @@ Then follow the usage instructions below.
- `host` Redis server hostname
- `port` Redis server portno
- `socket` Redis server unix_socket
- `url` Redis server url

The following additional params may be included:

Expand Down Expand Up @@ -54,10 +55,6 @@ Clients other than `node_redis` will work if they support the same interface. J

## FAQ

#### Can I use a URL scheme to make a connection?

Since `node_redis` which this library wraps does not include the ability to create a client from a URL. Neither does this library. However, there's a [separate module](https://github.com/ddollar/redis-url) that can be used in conjunction to get this behavior.

#### 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, one way this scenario can be handled is including a "session check" after setting up a session (checking for the existence of `req.session`):
Expand Down
19 changes: 3 additions & 16 deletions lib/connect-redis.js
Expand Up @@ -54,6 +54,7 @@ module.exports = function (session) {
var self = this;

options = options || {};
options.max_attempts = 2;
Store.call(this, options);
this.prefix = options.prefix == null
? 'sess:'
Expand All @@ -63,22 +64,8 @@ module.exports = function (session) {

/* istanbul ignore next */
if (options.url) {
console.error('Warning: "url" param is deprecated and will be removed in a later release: use redis-url module instead');
var url = require('url').parse(options.url);
if (url.protocol === 'redis:') {
if (url.auth) {
var userparts = url.auth.split(':');
options.user = userparts[0];
if (userparts.length === 2) {
options.pass = userparts[1];
}
}
options.host = url.hostname;
options.port = url.port;
if (url.pathname) {
options.db = url.pathname.replace('/', '', 1);
}
}
options.port = options.url;
options.host = options;
}

// convert to redis connect params
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -14,7 +14,7 @@
},
"dependencies": {
"debug": "^1.0.4",
"redis": "^0.12.1"
"redis": "^2.0.1"
},
"devDependencies": {
"blue-tape": "^0.1.8",
Expand Down
15 changes: 7 additions & 8 deletions test/connect-redis-test.js
Expand Up @@ -31,7 +31,7 @@ function lifecycleTest (store, t) {
.then(function (ok) {
t.equal(ok, 1, '#destroy() ok');
store.client.end();
return redisSrv.disconnect()
return redisSrv.disconnect();
});
}

Expand All @@ -54,13 +54,13 @@ test('basic', function (t) {

test('existing client', function (t) {
var client = redis.createClient(8543, 'localhost');
var store = new RedisStore({ client: client })
var store = new RedisStore({ client: client });
return lifecycleTest(store, t);
});

test('io redis client', function (t) {
var client = ioRedis.createClient(8543, 'localhost');
var store = new RedisStore({ client: client })
var store = new RedisStore({ client: client });
return lifecycleTest(store, t);
});

Expand All @@ -84,21 +84,20 @@ test('options', function (t) {

var socketStore = new RedisStore({ socket: 'word' });
t.equal(socketStore.client.address, 'word', 'sets socket address');
socketStore.client.end()
socketStore.client.end();

var hostNoPort = new RedisStore({ host: 'host' });
t.equal(hostNoPort.client.address, 'host:6379', 'sets default port');
hostNoPort.client.end()
hostNoPort.client.end();

return lifecycleTest(store, t);
});

test('interups', function (t) {
var store = P.promisifyAll(new RedisStore({ port: 8543 }));

return store.setAsync('123', { cookie: { maxAge: 2000 }, name: 'tj' })
.catch(function (er) {
t.ok(/failed/.test(er.message), 'failed connection');
t.ok(/broken/.test(er.message), 'failed connection');
store.client.end();
});
});
Expand All @@ -115,5 +114,5 @@ test('serializer', function (t) {
t.equal(serializer.parse(serializer.stringify("UnitTest")), 'UnitTest');

var store = new RedisStore({ port: 8543, serializer: serializer });
return lifecycleTest(store, t);
return lifecycleTest(store, t);
});

0 comments on commit 334e9ef

Please sign in to comment.