Skip to content

Commit

Permalink
feat: disallow call Redis() as a function
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
The `new` keyword is required explicitly. So `Redis(/* options */)`
will not work, use `new Redis(/* options */)` instead.
  • Loading branch information
luin committed Jun 23, 2018
1 parent da60b8b commit 68578a8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
9 changes: 2 additions & 7 deletions lib/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ var PromiseContainer = require('./promise_container');
* var Redis = require('ioredis');
*
* var redis = new Redis();
* // or: var redis = Redis();
*
* var redisOnPort6380 = new Redis(6380);
* var anotherRedis = new Redis(6380, '192.168.100.1');
Expand All @@ -103,10 +102,6 @@ var PromiseContainer = require('./promise_container');
* ```
*/
function Redis() {
if (!(this instanceof Redis)) {
return new Redis(arguments[0], arguments[1], arguments[2]);
}

this.parseOptions(arguments[0], arguments[1], arguments[2]);

EventEmitter.call(this);
Expand Down Expand Up @@ -139,8 +134,8 @@ Object.assign(Redis.prototype, Commander.prototype);
*
* @deprecated
*/
Redis.createClient = function () {
return Redis.apply(this, arguments);
Redis.createClient = function (...args) {
return new Redis(...args);
};

/**
Expand Down
4 changes: 2 additions & 2 deletions test/unit/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ describe('Redis', function () {
}
Redis.prototype.connect.restore();

function getOption() {
var redis = Redis.apply(null, arguments);
function getOption(...args) {
var redis = new Redis(...args);
return redis.options;
}
});
Expand Down

0 comments on commit 68578a8

Please sign in to comment.