Skip to content

Commit

Permalink
Merge 841c46f into 118943e
Browse files Browse the repository at this point in the history
  • Loading branch information
jgodson committed Dec 8, 2019
2 parents 118943e + 841c46f commit 86c0907
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,15 @@ function RedisStore(options) {
options.password =
options.password || options.auth_pass || options.pass || null; // For backwards compatibility
options.path = options.path || options.socket || null; // For backwards compatibility

if (!options.client) {
//
// TODO: we should probably omit custom options we have
// in this lib from `options` passed to instances below
//
const redisUrl = options.url && options.url.toString();
delete options.url;

if (options.isRedisCluster) {
debug('Initializing Redis Cluster');
delete options.isRedisCluster;
Expand All @@ -56,7 +60,7 @@ function RedisStore(options) {
delete options.isRedisCluster;
delete options.nodes;
delete options.clusterOptions;
client = new Redis(options);
client = redisUrl ? new Redis(redisUrl, options) : new Redis(options);
}
} else if (options.duplicate) {
// Duplicate client and update with options provided
Expand Down
12 changes: 12 additions & 0 deletions test/koa-redis.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ describe('test/koa-redis.test.js', () => {
store.connected.should.eql(false);
});

it('should connect and ready with url and quit ok', function*() {
const store = require('..')({
url: 'redis://localhost:6379/'
});
yield event(store, 'connect');
store.connected.should.eql(true);
yield event(store, 'ready');
yield store.quit();
yield event(store, 'end');
store.connected.should.eql(false);
});

it('should set and delete with db ok', function*() {
const store = require('..')({ db: 2 });
const client = new Redis();
Expand Down

0 comments on commit 86c0907

Please sign in to comment.