Skip to content

Commit

Permalink
fix: remove unnecessary bluebird usage
Browse files Browse the repository at this point in the history
  • Loading branch information
luin committed Jul 2, 2018
1 parent 0b07db2 commit 2502b1b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 26 deletions.
28 changes: 3 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -919,16 +919,7 @@ redis.set('foo', function (err) {
});
```

When a reply error is not handled (no callback is specified, and no `catch` method is chained),
the error will be logged to stderr. For instance:

```javascript
var Redis = require('ioredis');
var redis = new Redis();
redis.set('foo');
```

The following error will be printed:
This is the error stack of the `ReplyError`:

```
Unhandled rejection ReplyError: ERR wrong number of arguments for 'set' command
Expand All @@ -941,7 +932,7 @@ Unhandled rejection ReplyError: ERR wrong number of arguments for 'set' command
at TCP.onread (net.js:509:20)
```

But the error stack doesn't make any sense because the whole stack happens in the ioredis
By default, the error stack doesn't make any sense because the whole stack happens in the ioredis
module itself, not in your code. So it's not easy to find out where the error happens in your code.
ioredis provides an option `showFriendlyErrorStack` to solve the problem. When you enable
`showFriendlyErrorStack`, ioredis will optimize the error stack for you:
Expand All @@ -955,7 +946,7 @@ redis.set('foo');
And the output will be:

```
Unhandled rejection ReplyError: ERR wrong number of arguments for 'set' command
ReplyError: ERR wrong number of arguments for 'set' command
at Object.<anonymous> (/app/index.js:3:7)
at Module._compile (module.js:446:26)
at Object.Module._extensions..js (module.js:464:10)
Expand All @@ -970,19 +961,6 @@ This time the stack tells you that the error happens on the third line in your c
However, it would decrease the performance significantly to optimize the error stack. So by
default, this option is disabled and can only be used for debugging purposes. You **shouldn't** use this feature in a production environment.

If you want to catch all unhandled errors without decreased performance, there's another way:

```javascript
var Redis = require('ioredis');
Redis.Promise.onPossiblyUnhandledRejection(function (error) {
// you can log the error here.
// error.command.name is the command name, here is 'set'
// error.command.args is the command arguments, here is ['foo']
});
var redis = new Redis();
redis.set('foo');
```

# Plugging in your own Promises Library
If you're an advanced user, you may want to plug in your own promise library like [bluebird](https://www.npmjs.com/package/bluebird). Just set Redis.Promise to your favorite ES6-style promise constructor and ioredis will use it.

Expand Down
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
exports = module.exports = require('./lib/redis');

exports.ReplyError = require('./lib/reply_error');
exports.Promise = require('bluebird');
exports.Cluster = require('./lib/cluster');
exports.Command = require('./lib/command');

Expand Down

0 comments on commit 2502b1b

Please sign in to comment.