Skip to content

Redis Connection Status is Always "connecting" until explicitly check connections status or run a command #56

@rmilyushkevich

Description

@rmilyushkevich

Prerequisites

I am trying to verify the presence of an active Redis connection by using Redis.activeConnectionsCount, however, it always returns a value of 0 despite having correct credentials. Upon checking the list of connections in redis-cli, I noticed that there are no active connections except for the one established by redis-cli. The status of the connection also appears as "connecting" when checked using Redis.connection().status.

As a temporary solution, I have implemented a workaround by checking the connection in the boot method of the AppProvider. This establishes the connection once the application is up and running.

Image 1. Status is "connecting".
image

Image 2. Checking for status. Then wait 5 seconds and then checking for status again. Status is "ready".
image

Package version

7.3.1

Node.js and npm version

16.17.0 & 8.15.0

Sample Code (to reproduce the issue)

AppProvider.ts

import { ApplicationContract } from '@ioc:Adonis/Core/Application'

export default class AppProvider {
  constructor(protected app: ApplicationContract) {}

  public register() {
    // Register your own bindings
  }

  public async boot() {
    const Redis = (await import('@ioc:Adonis/Addons/Redis')).default;

    // console.log(Redis.activeConnectionsCount)
    // console.log(Redis.connection().status)

    await new Promise((resolve) => {
      setTimeout(() => resolve(true), 5000)
    })

    console.log(Redis.activeConnectionsCount) // always 0 if lines 13 and 14 are commented out
    console.log(Redis.connection().status) // always "connecting" if lines 13 and 14 are commented out
  }

  public async ready() {
    // App is ready
  }

  public async shutdown() {
    // Cleanup, since app is going down
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: AbandonedDropped and not into consideration

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions