Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Does the node-redis client.auth callback substitute for the ready event?

Does the node-redis client.auth callback substitute for the ready event?

Problem

From node-redis documentation on github:

NOTE: Your call to client.auth() should not be inside the ready handler. If you are doing this wrong, client will emit an error that looks something like this Error: Ready check failed: ERR operation not permitted

So does that mean that when client.auth executes a Callback passed to it, it is safe to assume that this connection is ready for normal commands as well? If no then is one supposed to juggle two callback functions, determining which one was called second?

Problem courtesy of: Bijou Trouvaille

Solution

When no auth is required, node-redis sends INFO to the server to detect when it's ready and then fires the ready event (see https://github.com/mranney/node_redis).

When auth is required, it looks like redis will only start accepting commands once the auth is complete (see http://redis.io/commands/auth).

So what I would do is respond to the "ready" event when not authenticating and respond to the auth callback when authenticating (probably having used {no_ready_check: true} when creating the client).

Solution courtesy of: Stuart Harris

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Does the node-redis client.auth callback substitute for the ready event?

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×