redis / ioredis

🚀 A robust, performance-focused, and full-featured Redis client for Node.js.
MIT License
14.06k stars 1.19k forks source link

Utilize `retryStrategy` for connection error #1855

Open nodegin opened 4 months ago

nodegin commented 4 months ago

I am hosting my Redis on cloud service which has DDoS prevent mechanism,

Currently I'm using BullMQ as the queue service but it emit tons of request causing my provider throttle my Redis connection.

So I'm getting the following error:

ReplyError: Too many requests. Please try again later.
    at parseError (/Users/user/Desktop/project/node_modules/redis-parser/lib/parser.js:179:12)
    at parseType (/Users/user/Desktop/project/node_modules/redis-parser/lib/parser.js:302:14) {
  command: {
    name: 'auth',
    args: [ 'redis-host', 'password' ]
  }
}

I have added the following to my ioredis connection params:

  reconnectOnError: () => 2 as const,
  retryStrategy(times) {
    const delay = Math.min(times * 50, 2000);
    return delay;
  },

which should fixes the issue, but currently ioredis doesn't utilize retryStrategy for connection event.

So this PR is to provide support for that