Skip to content

Commit

Permalink
Fix compatibility issues with ioredis + Cluster
Browse files Browse the repository at this point in the history
When calling req.session.destroy() without providing a callback function,
we actually invokes `redis.del(sid, undefined)`. However, ioredis considers
`undefined` as empty strings, which makes the invocation become
`redis.del(sid, "")`, and it will cause errors under cluster mode since
empty string may not belongs to a same slot with `sid`.

PR: #272
  • Loading branch information
luin authored and wavded committed Jul 19, 2019
1 parent a2babda commit 3609797
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/connect-redis.js
Expand Up @@ -217,6 +217,8 @@ module.exports = function (session) {

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;
Expand Down
14 changes: 13 additions & 1 deletion test/connect-redis-test.js
Expand Up @@ -63,7 +63,19 @@ test('existing client', function (t) {
test('io redis client', function (t) {
var client = ioRedis.createClient(redisSrv.port, 'localhost');
var store = new RedisStore({ client: client });
return lifecycleTest(store, t);
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) {
Expand Down

0 comments on commit 3609797

Please sign in to comment.