fastify / fastify-redis

Plugin to share a common Redis connection across Fastify.
MIT License
198 stars 31 forks source link

Redis connection error #182

Closed anistark closed 1 year ago

anistark commented 1 year ago

Prerequisites

Fastify version

4.0.0

Plugin version

6.1.1

Node.js version

20

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

13

Description

Still getting AVV_ERR_READY_TIMEOUT on redis connection. Even though redis server is running locally.

AvvioError [Error]: Plugin did not start in time: '@fastify/redis'. You may have forgotten to call 'done' function or to resolve a Promise

Here's my sample code:

'use strict'

const fp = require('fastify-plugin')
const fastifyRedis = require('@fastify/redis');
const Redis = require('ioredis');

const redisClient = new Redis(
  {
    host: process.env.REDIS_HOST,
    port: process.env.REDIS_PORT,
    closeClient: true
  }
);

/**
 * This plugins handles redis config
 *
 * @see https://github.com/fastify/fastify-redis
 */
module.exports = fp(async function (fastify, opts) {
  fastify.register(fastifyRedis, {
    client: redisClient,
    lazyConnect: false
  });
})

Steps to Reproduce

Add the above code to plugin and run fastify server.

Expected Behavior

Should just connect to redis.

Uzlopak commented 1 year ago

This is not reproducable. Timeouts happen if the server is not reachable.

anistark commented 1 year ago

This is not reproducable. Timeouts happen if the server is not reachable.

But I'm able to connect to local redis server from node express codebase.

Uzlopak commented 1 year ago

Did it work or did you close out of frustration?

anistark commented 1 year ago

no it worked. I realised it was unreachable to this server port cause of a proxy config. My bad. Apologies for inconvenience.

Sembauke commented 6 months ago

For anyone looking at this issue and unable to find an answer to their question, this is how I solved it:

So I thought registering the @fasitift/redis plugin would automatically start a "Redis Server", but this is not the case. This only connects your Fastify instance and the externally setup Redis server to each other.

You can easily run a Redis server in the background with Docker.