question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'passIfNotConnected' option is not compatible with ioredis client

See original GitHub issue

I love the idea of the passIfNotConnected option that was recently added in https://github.com/wyattjoh/rate-limit-redis/pull/29

However, it is based on the redis (“node-redis”) client implementation of the client.connected Boolean, which is not compatible with the ioredis client.

In ioredis, they seem to use the following complex set of checks for determining if the client is connected (e.g. source example):

if (
  this.status === "connecting" ||
  this.status === "connect" ||
  this.status === "ready"
) {
  reject(new Error("Redis is already connecting/connected"));
  return;
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
luincommented, Mar 30, 2021

Hi, I’m the author of ioredis (and contributor of node_redis) and happened to see this issue. Thank @JamesMGreene for pointing this out!

I think to better reflect the intent, we should check .ready instead of .connected as when .connected is true, the client may be not ready to send/receive commands.

The equivalent of .ready in ioredis is .status === 'ready'. So to support ioredis, the easiest change would be changing the following code in redis-store.js:

if (!options.client.connected && options.passIfNotConnected) {

To:

const clientConnected =
  options.client.status == 'ready' || // ioredis
  options.client.ready; // node_redis
if (!clientConnected && options.passIfNotConnected) {

I haven’t tried it myself but this may be a valid workaround to those using ioredis:

Looks good to me. To be more complete:

const Redis = require("ioredis");
const client = new Redis(/* ... options ... */);
client.connected = false;
client.ready = false;

client.on('connect', function () { client.connected = true; });
client.on('ready', function () { client.ready = true; });
client.on('close', function () {
  client.connected = false;
  client.ready = false;
});

0reactions
stale[bot]commented, Mar 20, 2022

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

rate-limit-redis works with redis and not with ioredis #38 - GitHub
We're migrating from the redis module to ioredis. ... generates an error message: redis client is not connected, rate-limit-redis disabled!
Read more >
Redis with Node.js (ioredis) | Redis Documentation Center
js Redis client. The following sections demonstrate the use of ioredis, a community-recommended Redis client for Node.js with build-in support for promises.
Read more >
ioredis connection keeps resetting when connecting to local ...
I had to use the natMap option in the ioredis client to remap the internal cluster network connections to the network address of...
Read more >
API - ioredis - Read the Docs
While loading, the server not respond to any commands. To work around this, when this option is true , ioredis will check the...
Read more >
Migrating from Node Redis to Ioredis: a slightly bumpy but ...
Here's how and why we migrated from Node Redis client library to Ioredis to suit ... by the client libraries themselves, but were...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found