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

Add support for ioredis #12

Merged
merged 3 commits into from
Oct 12, 2015
Merged

Add support for ioredis #12

merged 3 commits into from
Oct 12, 2015

Conversation

luin
Copy link
Contributor

@luin luin commented Oct 1, 2015

Hi, I'm the author of ioredis, a node.js redis client that supports Sentinel and Cluster.

I'm using this awesome module in my application, however this module doesn't support ioredis, which means I can't use it with my sentinel servers.

It's trivial to support ioredis since it's compatible with node_redis for most APIs. The only difference is the result of multi in ioredis is [[err1, res1], [err2, res2], [err3, res3]] and in node_redis is [res1, res2, res3]. Refer to https://github.com/luin/ioredis/wiki/Migrating-from-node_redis for more details.

The only change have to be made is changing (!res || !res[0]) to (!res || !res[0] || !res[0][1]), which works with both node_redis and ioredis. What's more, I added forEach wrapper around the original tests so that it will test this module against both node_redis and ioredis.

@@ -76,7 +76,7 @@ Limiter.prototype.get = function (fn) {
if (err) return fn(err);
// If the request has failed, it means the values already
// exist in which case we need to get the latest values.
if (!res || !res[0]) return mget();
if (!res || !res[0] || !res[0][1]) return mget();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only problem that I see is that you rely on the fact that node_redis returns a string result.

I think that a better way would be to check if res[0] is an array, if so, check if res[0][1] exists.
what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm...yes, it would make more sense. Just submitted a commit for this.

@noamshemesh
Copy link
Collaborator

I really like this PR and want to merge it, just one more question, don't you want to check the response also for the multi() in decr() func?
I suggest to extract the response handling to another function and call it on every multi() callback. How does that sound to you?

@luin
Copy link
Contributor Author

luin commented Oct 12, 2015

Yes, of course. Didn't notice there's another multi 😢

@noamshemesh noamshemesh merged commit e46872a into tj:master Oct 12, 2015
@luin luin deleted the ioredis branch October 12, 2015 08:13
@noamshemesh
Copy link
Collaborator

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants