Skip to content

Commit b2a59ad

Browse files
authored
Merge pull request #2 from Ziao/master
Added support for ioredis
2 parents f36f0eb + 480e748 commit b2a59ad

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ app.use(limiter);
3535

3636
* **expiry**: seconds - how long each rate limiting window exists for. Defaults to `60`.
3737
* **prefix**: string - prefix to add to entries in Redis. Defaults to `rl:`.
38-
* **client**: [Redis Client](https://github.com/NodeRedis/node_redis) - A node_redis Redis Client to use. Defaults to `require('redis').createClient();`.
38+
* **client**: [Redis Client](https://github.com/NodeRedis/node_redis) or [ioredis Client](https://github.com/luin/ioredis)- A Redis Client to use. Defaults to `require('redis').createClient();`.
3939

4040
## License
4141

lib/redis-store.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@ var RedisStore = function(options) {
2222
return cb(err);
2323
}
2424

25+
// in ioredis, every reply consists of an array [err, value].
26+
// We don't need the error here, and if we aren't dealing with an array,
27+
// nothing is changed.
28+
replies = replies.map(function(val) {
29+
if (Array.isArray(val) && val.length >= 2) {
30+
return val[1];
31+
}
32+
33+
return val;
34+
});
35+
2536
// if this is new or has no expiry
2637
if (replies[0] === 1 || replies[1] === -1) {
2738
// then expire it after the timeout

0 commit comments

Comments
 (0)