You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+17-1Lines changed: 17 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -57,11 +57,27 @@ landscape.
57
57
58
58
### Promises
59
59
60
+
#### Native Promises
61
+
If you are using node v8 or higher, you can promisify node_redis with [util.promisify](https://nodejs.org/api/util.html#util_util_promisify_original) as in:
62
+
```js
63
+
const {promisify} =require('util');
64
+
constgetAsync=promisify(client.get).bind(client);
65
+
```
66
+
now *getAsync* is a promisified version of *client.get*:
67
+
```js
68
+
// We expect a value 'foo': 'bar' to be present
69
+
// So instead of writing client.get('foo', cb); you have to write:
70
+
returngetAsync('foo').then(function(res) {
71
+
console.log(res); // => 'bar'
72
+
});
73
+
```
74
+
75
+
#### Bluebird Promises
60
76
You can also use node_redis with promises by promisifying node_redis with
61
77
[bluebird](https://github.com/petkaantonov/bluebird) as in:
0 commit comments