Skip to content

Bug in detectRedisVersion #11749

Closed
Closed

Description

@AdolfodelSel

Issue description

The detectRedisVersion function incorrectly detects the Redis version when using versions lower than 4. The "set" function does not exist in version 3.1.2, so the check mistakenly identifies the redisMajorVersion as 5 instead of 3.

Expected Behavior

Ensure that the detectRedisVersion function correctly detects when the Redis version is 3.

Actual Behavior

The detectRedisVersion function incorrectly detects version 3.1.2 as version 5.
`

private detectRedisVersion(): void {
    if (this.clientType !== "redis") return
    try {
        // Detect version by examining the client's method signatures
        // This avoids creating test keys in the database
        const setMethod = this.client.set
        if (setMethod && setMethod.length <= 3) {
            // Redis 5+ set method accepts fewer parameters (key, value, options)
            this.redisMajorVersion = 5
        } else {
            // Redis 3/4 set method requires more parameters (key, value, flag, duration, callback)
            this.redisMajorVersion = 3
        }
    } catch {
        // Default to Redis 3/4 for maximum compatibility
        this.redisMajorVersion = 3
    }
}

`

Steps to reproduce

Use Redis version 3.1.2 and try executing a query with caching.
Configuration:
cache: { type: 'redis', options: { host: 'localhost', port: 6379, db: 0 }, duration: 1800000, ignoreErrors: false }
Example:
query.cache('test', 1000);

My Environment

| Dependency | Version |
| Redis version | 3.1.2 |
| TypeORM version | 0.3.27 |

Additional Context

No response

Relevant Database Driver(s)

  • aurora-mysql
  • aurora-postgres
  • better-sqlite3
  • cockroachdb
  • cordova
  • expo
  • mongodb
  • mysql
  • nativescript
  • oracle
  • postgres
  • react-native
  • sap
  • spanner
  • sqlite
  • sqlite-abstract
  • sqljs
  • sqlserver

Are you willing to resolve this issue by submitting a Pull Request?

Yes, I have the time, and I know how to start.

Activity

  1. changed the title [-]Bug in isRedis5OrHigher[/-] [+]Bug in detectRedisVersion[/+] on Nov 3, 2025
  2. mguida22 commented on Nov 9, 2025

    @mguida22
    Collaborator

    Thanks for the report, can you open a PR with a fix? Ideally we can programmatically get the Redis version via a command instead of checking parameters.

    It looks like this was introduced via #11585

  3. ibrahimmenem commented on Nov 13, 2025

    @ibrahimmenem
    Contributor

    @mguida22 I opened a PR for this but not sure how to proceed to get it reviewed! thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions