Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow url option that's forwarded to ioredis #67

Merged
merged 1 commit into from
Jan 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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