Skip to content

fix(redis): redis cache version detection - #11936

Merged
gioboa merged 5 commits into
typeorm:v0.3from
mguida22:redis-version-detection
Mar 1, 2026
Merged

gioboa merged 5 commits into
typeorm:v0.3from
mguida22:redis-version-detection

Conversation

@mguida22

@mguida22 mguida22 commented Jan 22, 2026 •

Copy link
Copy Markdown
Collaborator

Description of change

Fixes logic to determine if the provided redis client uses a promise or callback based API. This fix calls ping to check if the response returns a function (and therefore uses promises).

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • This pull request links relevant issues as Fixes #00000
  • There are new or updated tests validating the change (tests/**.test.ts)
  • Documentation has been updated to reflect this change (docs/docs/**.md)

@pkg-pr-new

pkg-pr-new Bot commented Jan 22, 2026 •

Copy link
Copy Markdown
  • typeorm-sql-js-example

    npm i https://pkg.pr.new/typeorm/typeorm@11936
    

commit: 97e3075

@coveralls

coveralls commented Jan 22, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 80.775% (+0.01%) from 80.765%
when pulling d54d0a5 on mguida22:redis-version-detection
into 9d07ec3 on typeorm:v0.3.

@mguida22
mguida22 marked this pull request as ready for review January 30, 2026 17:02
@mguida22
mguida22 requested a review from gioboa January 30, 2026 17:03
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

User description

Description of change

Fixes logic to determine if the provided redis client uses a promise or callback based API. This fix calls ping to check if the response returns a function (and therefore uses promises).

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • This pull request links relevant issues as Fixes #00000
  • There are new or updated tests validating the change (tests/**.test.ts)
  • Documentation has been updated to reflect this change (docs/docs/**.md)

PR Type

Bug fix


Description

  • Replace version detection with runtime Promise-based API detection

  • Check if Redis client methods return Promises instead of reading package.json

  • Simplify API style detection by calling ping() and checking return type

  • Update tests to verify Promise vs callback-based API detection


Diagram Walkthrough

flowchart LR
  A["Old: Read package.json version"] --> B["Parse major version number"]
  B --> C["Determine API style from version"]
  D["New: Call ping() method"] --> E["Check if result has .then"]
  E --> F["Set isPromiseBasedApi flag"]
  C -.->|replaced by| F
Loading

File Walkthrough

Relevant files
Bug fix
RedisQueryResultCache.ts
Runtime Promise-based API detection instead of version parsing

src/cache/RedisQueryResultCache.ts

  • Replace redisMajorVersion property with isPromiseBasedApi boolean flag
  • Replace detectRedisVersion() with detectPromiseBasedApi() that checks
    ping() return type
  • Remove isRedis5OrHigher() method and use isPromiseBasedApi directly
    throughout
  • Update all cache methods (disconnect, getFromCache, saveInCache,
    clear, deleteKey) to use new flag
  • Remove version-based comments and simplify conditional logic
+20/-43 
Tests
redis-query-result-cache.ts
Update tests for Promise-based API detection                         

test/unit/cache/redis-query-result-cache.ts

  • Rename test suite from "detectRedisVersion" to "detectPromiseBasedApi"
  • Remove readPackageVersionStub and PlatformTools.readPackageVersion
    mocking
  • Replace 4 version-specific tests with 3 API-detection tests
  • Add test for Promise-based API detection (ping returns Promise)
  • Add test for callback-based API detection (ping returns non-Promise)
  • Add test for ioredis client type (should not detect)
+28/-51 

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Jan 30, 2026 •

Copy link
Copy Markdown

PR Code Suggestions ✨

Latest suggestions up to 97e3075

CategorySuggestion                                                                                                                                    Impact
Possible issue
Guard and harden API detection

Add a guard to ensure API detection only runs for the redis client type and wrap
the logic in a try-catch block to prevent potential errors with older clients.

src/cache/RedisQueryResultCache.ts [297-305]

 private detectPromiseBasedApi(): void {
-    // Call ping() and check if it returns a Promise
-    // This works because v5+ returns Promises directly, while v4 with legacyMode uses callbacks
-    const result = this.client.ping()
-    this.isPromiseBasedApi = !!result?.then
-    if (this.isPromiseBasedApi) {
-        result.catch(() => {})
+    if (this.clientType !== "redis" || !this.client) return
+
+    try {
+        // v5+ returns Promises; older callback-style clients may throw if called without a callback
+        const result = this.client.ping()
+        this.isPromiseBasedApi = !!result && typeof result.then === "function"
+        if (this.isPromiseBasedApi) {
+            void result.catch(() => {})
+        }
+    } catch {
+        this.isPromiseBasedApi = false
     }
 }
  • Apply / Chat
Suggestion importance[1-10]: 8

__

Why: The suggestion correctly identifies a bug where the API detection runs for ioredis and adds a necessary guard, while also improving robustness with a try-catch block.

Medium
Ensure detection is skipped

Update the test for the ioredis client type to assert that the ping() method is
not called, which correctly verifies that the API detection logic is skipped.

test/unit/cache/redis-query-result-cache.ts [67-83]

 it("should not detect for ioredis client type", () => {
     const cache = new RedisQueryResultCache(
         mockDataSource as any,
         "ioredis",
     )
 
-    // Mock client - shouldn't matter since clientType is ioredis
-    ;(cache as any).client = {
-        ping: () => Promise.resolve("PONG"),
-    }
+    const pingStub = sandbox.stub().returns(Promise.resolve("PONG"))
+    ;(cache as any).client = { ping: pingStub }
 
-    // Call the private method
     ;(cache as any).detectPromiseBasedApi()
 
-    // Should remain false (default) for non-redis clients
+    expect(pingStub.called).to.be.false
     expect((cache as any).isPromiseBasedApi).to.be.false
 })
  • Apply / Chat
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly points out that the test is flawed and proposes a better way to verify the guard's behavior by checking if the ping method was called.

Medium
  • More

Previous suggestions

✅ Suggestions up to commit 0398841
CategorySuggestion                                                                                                                                    Impact
Possible issue
✅ Restrict detection to node-redis
Suggestion Impact:The call to detectPromiseBasedApi() was moved into the "redis" branch so it no longer runs for "ioredis", addressing the ioredis breakage concern.

code diff:

@@ -87,6 +87,9 @@
             if (typeof this.client.connect === "function") {
                 await this.client.connect()
             }
+
+            // Detect API style by checking if methods return Promises
+            this.detectPromiseBasedApi()
         } else if (this.clientType === "ioredis") {
             if (cacheOptions && cacheOptions.port) {
                 if (cacheOptions.options) {
@@ -124,9 +127,6 @@
                 )
             }
         }
-
-        // Detect API style by checking if methods return Promises
-        this.detectPromiseBasedApi()
     }

Restrict the detectPromiseBasedApi() call to only run when the clientType is
redis to avoid breaking ioredis functionality.

src/cache/RedisQueryResultCache.ts [128-129]

-// Detect API style by checking if methods return Promises
-this.detectPromiseBasedApi()
+// Detect API style (only relevant for node-redis)
+if (this.clientType === "redis") {
+    await this.detectPromiseBasedApi()
+}
Suggestion importance[1-10]: 9

__

Why: The suggestion correctly identifies a critical regression where calling detectPromiseBasedApi() for ioredis would cause runtime errors by routing it to use node-redis specific methods that do not exist on the ioredis client.

High
Make detection safe and awaited

Refactor detectPromiseBasedApi to be async and use a try/catch block to safely
handle clients that require a callback for ping(), preventing potential crashes
and unhandled promise rejections.

src/cache/RedisQueryResultCache.ts [297-305]

-private detectPromiseBasedApi(): void {
-    // Call ping() and check if it returns a Promise
-    // This works because v5+ returns Promises directly, while v4 with legacyMode uses callbacks
-    const result = this.client.ping()
-    this.isPromiseBasedApi = !!result?.then
-    if (this.isPromiseBasedApi) {
-        result.catch(() => {})
+private async detectPromiseBasedApi(): Promise<void> {
+    if (this.clientType !== "redis") {
+        this.isPromiseBasedApi = false
+        return
+    }
+
+    try {
+        const result = this.client.ping()
+        this.isPromiseBasedApi =
+            !!result && typeof (result as any).then === "function"
+
+        if (this.isPromiseBasedApi) {
+            await result
+        }
+    } catch {
+        // If ping() requires a callback / throws, treat as callback-based API
+        this.isPromiseBasedApi = false
     }
 }
Suggestion importance[1-10]: 8

__

Why: The suggestion correctly points out that the current implementation of detectPromiseBasedApi is not robust, can cause unhandled promise rejections, and may crash on older clients. The proposed change makes the detection logic safer and more reliable.

Medium
Gate branches by client type

Add a this.clientType === "redis" check in addition to this.isPromiseBasedApi
before calling node-redis specific methods like flushDb() to prevent other
client types from executing incorrect code paths.

src/cache/RedisQueryResultCache.ts [228-231]

-if (this.isPromiseBasedApi) {
+if (this.clientType === "redis" && this.isPromiseBasedApi) {
     await this.client.flushDb()
     return
 }
Suggestion importance[1-10]: 7

__

Why: This is a good defensive programming suggestion that adds an extra layer of safety, ensuring that node-redis specific code paths are only executed for the redis client, preventing potential issues if isPromiseBasedApi were ever incorrectly set for other client types.

Medium
✅ Suggestions up to commit bcdc206
CategorySuggestion                                                                                                                                    Impact
Possible issue
✅ Prevent API detection from throwing
Suggestion Impact:The commit modified the same API-detection logic, changing the promise detection to use optional chaining (result?.then) and attaching a catch handler to avoid unhandled promise rejections, and moved when detectPromiseBasedApi() is invoked. However, it did not add the suggested try/catch around ping() nor a this.client null check to prevent ping() from throwing.

code diff:

@@ -87,9 +87,6 @@
             if (typeof this.client.connect === "function") {
                 await this.client.connect()
             }
-
-            // Detect API style by checking if methods return Promises
-            this.detectPromiseBasedApi()
         } else if (this.clientType === "ioredis") {
             if (cacheOptions && cacheOptions.port) {
                 if (cacheOptions.options) {
@@ -127,6 +124,9 @@
                 )
             }
         }
+
+        // Detect API style by checking if methods return Promises
+        this.detectPromiseBasedApi()
     }
 
     /**
@@ -295,15 +295,13 @@
      * by checking the return type of a method call at runtime.
      */
     private detectPromiseBasedApi(): void {
-        if (this.clientType !== "redis") {
-            this.isPromiseBasedApi = false
-            return
-        }
-
         // Call ping() and check if it returns a Promise
         // This works because v5+ returns Promises directly, while v4 with legacyMode uses callbacks
         const result = this.client.ping()
-        this.isPromiseBasedApi = result && typeof result.then === "function"
+        this.isPromiseBasedApi = !!result?.then
+        if (this.isPromiseBasedApi) {
+            result.catch(() => {})
+        }
     }

Add a try/catch block and a null check for this.client in detectPromiseBasedApi
to prevent potential runtime errors when probing the API style.

src/cache/RedisQueryResultCache.ts [297-307]

 private detectPromiseBasedApi(): void {
-    if (this.clientType !== "redis") {
+    if (this.clientType !== "redis" || !this.client) {
         this.isPromiseBasedApi = false
         return
     }
 
-    // Call ping() and check if it returns a Promise
-    // This works because v5+ returns Promises directly, while v4 with legacyMode uses callbacks
-    const result = this.client.ping()
-    this.isPromiseBasedApi = result && typeof result.then === "function"
+    try {
+        // v5+ returns Promises directly, while callback-based clients may throw if no callback is provided
+        const result = this.client.ping()
+        this.isPromiseBasedApi = !!result && typeof (result as any).then === "function"
+    } catch {
+        this.isPromiseBasedApi = false
+    }
 }
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly identifies that this.client.ping() could throw an error for callback-based APIs, and the proposed try/catch block makes the new detection logic more robust against potential runtime errors.

Medium
Make disconnect safe when unset

Add a guard clause if (!this.client) return at the beginning of the disconnect
method to prevent errors if the client is not initialized.

src/cache/RedisQueryResultCache.ts [135-149]

 async disconnect(): Promise<void> {
+    if (!this.client) return
+
     if (this.isPromiseBasedApi) {
         await this.client.quit()
         this.client = undefined
         return
     }
 
     return new Promise<void>((ok, fail) => {
         this.client.quit((err: any, result: any) => {
             if (err) return fail(err)
             ok()
             this.client = undefined
         })
     })
 }
Suggestion importance[1-10]: 6

__

Why: The suggestion correctly points out that this.client could be undefined when disconnect() is called, and adding a guard clause is a good defensive programming practice to prevent a runtime error.

Low
✅ Suggestions up to commit d54d0a5
CategorySuggestion                                                                                                                                    Impact
Possible issue
✅ Correctly detect promise-based API for ioredis
Suggestion Impact:The commit changed detectPromiseBasedApi to no longer force non-"redis" clients to be callback-based; it now detects promise-based behavior via ping() for all client types, which fixes ioredis being misclassified. It also ensures any returned promise is caught to avoid unhandled rejections and moves the detection call to run after client initialization.

code diff:

@@ -87,9 +87,6 @@
             if (typeof this.client.connect === "function") {
                 await this.client.connect()
             }
-
-            // Detect API style by checking if methods return Promises
-            this.detectPromiseBasedApi()
         } else if (this.clientType === "ioredis") {
             if (cacheOptions && cacheOptions.port) {
                 if (cacheOptions.options) {
@@ -127,6 +124,9 @@
                 )
             }
         }
+
+        // Detect API style by checking if methods return Promises
+        this.detectPromiseBasedApi()
     }
 
     /**
@@ -295,15 +295,13 @@
      * by checking the return type of a method call at runtime.
      */
     private detectPromiseBasedApi(): void {
-        if (this.clientType !== "redis") {
-            this.isPromiseBasedApi = false
-            return
-        }
-
         // Call ping() and check if it returns a Promise
         // This works because v5+ returns Promises directly, while v4 with legacyMode uses callbacks
         const result = this.client.ping()
-        this.isPromiseBasedApi = result && typeof result.then === "function"
+        this.isPromiseBasedApi = !!result?.then
+        if (this.isPromiseBasedApi) {
+            result.catch(() => {})
+        }
     }

Update the detectPromiseBasedApi method to correctly identify ioredis and
ioredis/cluster clients as promise-based, as they are currently misclassified,
causing incorrect API usage.

src/cache/RedisQueryResultCache.ts [297-307]

 private detectPromiseBasedApi(): void {
+    if (this.clientType === "ioredis" || this.clientType === "ioredis/cluster") {
+        this.isPromiseBasedApi = true
+        return
+    }
+
     if (this.clientType !== "redis") {
         this.isPromiseBasedApi = false
         return
     }
 
     // Call ping() and check if it returns a Promise
     // This works because v5+ returns Promises directly, while v4 with legacyMode uses callbacks
     const result = this.client.ping()
     this.isPromiseBasedApi = result && typeof result.then === "function"
 }
Suggestion importance[1-10]: 8

__

Why: The suggestion correctly identifies that ioredis clients are promise-based and the current logic fails to handle them, leading to incorrect behavior. This is a significant bug fix.

Medium

@mguida22

Copy link
Copy Markdown
Collaborator Author

This can use some real world testing. Please install the version from this branch and report any feedback.

@mguida22
mguida22 requested review from alumni and naorpeled January 30, 2026 17:04
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Jan 30, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (21) 📘 Rule violations (9) 📎 Requirement gaps (0)

Grey Divider


Action required

1. Empty ping().catch(() => {}) 📘 Rule violation ⛯ Reliability
Description
The new Redis API detection code swallows ping() errors via an empty catch, which can mask
connection/auth problems and looks like defensive noise. This violates the requirement to avoid
abnormal defensive code and AI-like slop.
Code

src/cache/RedisQueryResultCache.ts[R300-303]

+        const result = this.client.ping()
+        this.isPromiseBasedApi = !!result?.then
+        if (this.isPromiseBasedApi) {
+            result.catch(() => {})
Evidence
Compliance ID 4 disallows abnormal defensive code; the added empty catch explicitly suppresses
errors from a network call (ping()), hiding failures instead of handling them meaningfully.

Rule 4: Remove AI-generated noise
src/cache/RedisQueryResultCache.ts[300-303]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`detectPromiseBasedApi()` calls `ping()` and then suppresses failures with an empty `catch(() =&amp;amp;amp;gt; {})`, which can hide real connectivity/authentication problems and violates the &amp;amp;amp;quot;Remove AI-generated noise&amp;amp;amp;quot; requirement.
## Issue Context
This code runs during cache initialization and should not silently ignore Redis errors.
## Fix Focus Areas
- src/cache/RedisQueryResultCache.ts[300-303]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Detection runs for ioredis 🐞 Bug ✓ Correctness
Description
connect() calls detectPromiseBasedApi() for all client types, and detectPromiseBasedApi() has no
clientType guard. This can flip ioredis/ioredis-cluster into the Promise-based branches that use
node-redis-specific method names/signatures (e.g., flushDb() and set(key, value, {PX})), and it also
contradicts this PR’s unit test expectation for ioredis.
Code

src/cache/RedisQueryResultCache.ts[R297-305]

+    private detectPromiseBasedApi(): void {
+        // Call ping() and check if it returns a Promise
+        // This works because v5+ returns Promises directly, while v4 with legacyMode uses callbacks
+        const result = this.client.ping()
+        this.isPromiseBasedApi = !!result?.then
+        if (this.isPromiseBasedApi) {
+            result.catch(() => {})
     }
-        if (major <= 4) {
-            // Redis 3/4 uses callback-based API
-            this.redisMajorVersion = 3
-        } else {
-            // Redis 5+ uses Promise-based API
-            this.redisMajorVersion = 5
-        }
-    }
-
-    /**
-     * Checks if Redis version is 5.x or higher
-     */
-    private isRedis5OrHigher(): boolean {
-        if (this.clientType !== "redis") return false
-        return (
-            this.redisMajorVersion !== undefined && this.redisMajorVersion >= 5
-        )
 }
Evidence
The implementation unconditionally runs API-style detection after connect, and the detector sets
isPromiseBasedApi purely from ping()’s return value. Many cache operations branch on
isPromiseBasedApi and use different method names/signatures between the two branches (flushDb vs
flushdb; set with {PX} vs "PX", duration). The PR’s own unit test asserts ioredis should not be
detected (remain false), but the current implementation will set it to true if ioredis ping()
returns a Promise.

src/cache/RedisQueryResultCache.ts[56-130]
src/cache/RedisQueryResultCache.ts[293-305]
src/cache/RedisQueryResultCache.ts[192-222]
src/cache/RedisQueryResultCache.ts[224-239]
test/unit/cache/redis-query-result-cache.ts[67-83]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`detectPromiseBasedApi()` is invoked for all cache client types and has no `clientType` guard. This can incorrectly set `isPromiseBasedApi` for `ioredis` / `ioredis/cluster`, routing them into node-redis-specific Promise code paths (different command names/signatures), and it fails this PR’s own unit test expectation.
## Issue Context
- `connect()` ends by calling `this.detectPromiseBasedApi()` regardless of whether the client is `redis`, `ioredis`, or `ioredis/cluster`.
- `detectPromiseBasedApi()` sets `isPromiseBasedApi` based on `this.client.ping()` return shape with no client-type check.
- Cache operations branch on `isPromiseBasedApi` and use different method names/signatures (e.g., `flushDb()` vs `flushdb()`, `set(..., { PX })` vs `set(..., &amp;amp;amp;quot;PX&amp;amp;amp;quot;, duration, cb)`), so wrong detection can cause runtime failures.
## Fix Focus Areas
- src/cache/RedisQueryResultCache.ts[56-130]
- src/cache/RedisQueryResultCache.ts[293-305]
- src/cache/RedisQueryResultCache.ts[192-239]
- test/unit/cache/redis-query-result-cache.ts[67-83]
## Suggested change
- Add a guard in `detectPromiseBasedApi()`:
- `if (this.clientType !== &amp;amp;amp;quot;redis&amp;amp;amp;quot;) return;`
- optionally also `if (typeof this.client?.ping !== &amp;amp;amp;quot;function&amp;amp;amp;quot;) return;`
- Alternatively (or additionally), call `detectPromiseBasedApi()` only inside the `if (this.clientType === &amp;amp;amp;quot;redis&amp;amp;amp;quot;) { ... }` branch in `connect()`.
- Keep the existing ioredis behavior on the callback-style branch unless you also update ioredis promise-path calls to correct method names/signatures and add tests.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Empty ping().catch(() => {}) 📘 Rule violation ⛯ Reliability
Description
The new Redis API detection code swallows ping() errors via an empty catch, which can mask
connection/auth problems and looks like defensive noise. This violates the requirement to avoid
abnormal defensive code and AI-like slop.
Code

src/cache/RedisQueryResultCache.ts[R300-303]

+        const result = this.client.ping()
+        this.isPromiseBasedApi = !!result?.then
+        if (this.isPromiseBasedApi) {
+            result.catch(() => {})
Evidence
Compliance ID 4 disallows abnormal defensive code; the added empty catch explicitly suppresses
errors from a network call (ping()), hiding failures instead of handling them meaningfully.

Rule 4: Remove AI-generated noise
src/cache/RedisQueryResultCache.ts[300-303]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`detectPromiseBasedApi()` calls `ping()` and then suppresses failures with an empty `catch(() =&amp;amp;gt; {})`, which can hide real connectivity/authentication problems and violates the &amp;amp;quot;Remove AI-generated noise&amp;amp;quot; requirement.
## Issue Context
This code runs during cache initialization and should not silently ignore Redis errors.
## Fix Focus Areas
- src/cache/RedisQueryResultCache.ts[300-303]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


View more (3)
4. Detection runs for ioredis 🐞 Bug ✓ Correctness
Description
connect() calls detectPromiseBasedApi() for all client types, and detectPromiseBasedApi() has no
clientType guard. This can flip ioredis/ioredis-cluster into the Promise-based branches that use
node-redis-specific method names/signatures (e.g., flushDb() and set(key, value, {PX})), and it also
contradicts this PR’s unit test expectation for ioredis.
Code

src/cache/RedisQueryResultCache.ts[R297-305]

+    private detectPromiseBasedApi(): void {
+        // Call ping() and check if it returns a Promise
+        // This works because v5+ returns Promises directly, while v4 with legacyMode uses callbacks
+        const result = this.client.ping()
+        this.isPromiseBasedApi = !!result?.then
+        if (this.isPromiseBasedApi) {
+            result.catch(() => {})
      }
-        if (major <= 4) {
-            // Redis 3/4 uses callback-based API
-            this.redisMajorVersion = 3
-        } else {
-            // Redis 5+ uses Promise-based API
-            this.redisMajorVersion = 5
-        }
-    }
-
-    /**
-     * Checks if Redis version is 5.x or higher
-     */
-    private isRedis5OrHigher(): boolean {
-        if (this.clientType !== "redis") return false
-        return (
-            this.redisMajorVersion !== undefined && this.redisMajorVersion >= 5
-        )
  }
Evidence
The implementation unconditionally runs API-style detection after connect, and the detector sets
isPromiseBasedApi purely from ping()’s return value. Many cache operations branch on
isPromiseBasedApi and use different method names/signatures between the two branches (flushDb vs
flushdb; set with {PX} vs "PX", duration). The PR’s own unit test asserts ioredis should not be
detected (remain false), but the current implementation will set it to true if ioredis ping()
returns a Promise.

src/cache/RedisQueryResultCache.ts[56-130]
src/cache/RedisQueryResultCache.ts[293-305]
src/cache/RedisQueryResultCache.ts[192-222]
src/cache/RedisQueryResultCache.ts[224-239]
test/unit/cache/redis-query-result-cache.ts[67-83]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`detectPromiseBasedApi()` is invoked for all cache client types and has no `clientType` guard. This can incorrectly set `isPromiseBasedApi` for `ioredis` / `ioredis/cluster`, routing them into node-redis-specific Promise code paths (different command names/signatures), and it fails this PR’s own unit test expectation.
## Issue Context
- `connect()` ends by calling `this.detectPromiseBasedApi()` regardless of whether the client is `redis`, `ioredis`, or `ioredis/cluster`.
- `detectPromiseBasedApi()` sets `isPromiseBasedApi` based on `this.client.ping()` return shape with no client-type check.
- Cache operations branch on `isPromiseBasedApi` and use different method names/signatures (e.g., `flushDb()` vs `flushdb()`, `set(..., { PX })` vs `set(..., &amp;amp;quot;PX&amp;amp;quot;, duration, cb)`), so wrong detection can cause runtime failures.
## Fix Focus Areas
- src/cache/RedisQueryResultCache.ts[56-130]
- src/cache/RedisQueryResultCache.ts[293-305]
- src/cache/RedisQueryResultCache.ts[192-239]
- test/unit/cache/redis-query-result-cache.ts[67-83]
## Suggested change
- Add a guard in `detectPromiseBasedApi()`:
- `if (this.clientType !== &amp;amp;quot;redis&amp;amp;quot;) return;`
- optionally also `if (typeof this.client?.ping !== &amp;amp;quot;function&amp;amp;quot;) return;`
- Alternatively (or additionally), call `detectPromiseBasedApi()` only inside the `if (this.clientType === &amp;amp;quot;redis&amp;amp;quot;) { ... }` branch in `connect()`.
- Keep the existing ioredis behavior on the callback-style branch unless you also update ioredis promise-path calls to correct method names/signatures and add tests.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


5. Empty ping().catch(() => {}) 📘 Rule violation ⛯ Reliability
Description
The new Redis API detection code swallows ping() errors via an empty catch, which can mask
connection/auth problems and looks like defensive noise. This violates the requirement to avoid
abnormal defensive code and AI-like slop.
Code

src/cache/RedisQueryResultCache.ts[R300-303]

+        const result = this.client.ping()
+        this.isPromiseBasedApi = !!result?.then
+        if (this.isPromiseBasedApi) {
+            result.catch(() => {})
Evidence
Compliance ID 4 disallows abnormal defensive code; the added empty catch explicitly suppresses
errors from a network call (ping()), hiding failures instead of handling them meaningfully.

Rule 4: Remove AI-generated noise
src/cache/RedisQueryResultCache.ts[300-303]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`detectPromiseBasedApi()` calls `ping()` and then suppresses failures with an empty `catch(() =&amp;gt; {})`, which can hide real connectivity/authentication problems and violates the &amp;quot;Remove AI-generated noise&amp;quot; requirement.
## Issue Context
This code runs during cache initialization and should not silently ignore Redis errors.
## Fix Focus Areas
- src/cache/RedisQueryResultCache.ts[300-303]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


6. Detection runs for ioredis 🐞 Bug ✓ Correctness
Description
connect() calls detectPromiseBasedApi() for all client types, and detectPromiseBasedApi() has no
clientType guard. This can flip ioredis/ioredis-cluster into the Promise-based branches that use
node-redis-specific method names/signatures (e.g., flushDb() and set(key, value, {PX})), and it also
contradicts this PR’s unit test expectation for ioredis.
Code

src/cache/RedisQueryResultCache.ts[R297-305]

+    private detectPromiseBasedApi(): void {
+        // Call ping() and check if it returns a Promise
+        // This works because v5+ returns Promises directly, while v4 with legacyMode uses callbacks
+        const result = this.client.ping()
+        this.isPromiseBasedApi = !!result?.then
+        if (this.isPromiseBasedApi) {
+            result.catch(() => {})
       }
-        if (major <= 4) {
-            // Redis 3/4 uses callback-based API
-            this.redisMajorVersion = 3
-        } else {
-            // Redis 5+ uses Promise-based API
-            this.redisMajorVersion = 5
-        }
-    }
-
-    /**
-     * Checks if Redis version is 5.x or higher
-     */
-    private isRedis5OrHigher(): boolean {
-        if (this.clientType !== "redis") return false
-        return (
-            this.redisMajorVersion !== undefined && this.redisMajorVersion >= 5
-        )
   }
Evidence
The implementation unconditionally runs API-style detection after connect, and the detector sets
isPromiseBasedApi purely from ping()’s return value. Many cache operations branch on
isPromiseBasedApi and use different method names/signatures between the two branches (flushDb vs
flushdb; set with {PX} vs "PX", duration). The PR’s own unit test asserts ioredis should not be
detected (remain false), but the current implementation will set it to true if ioredis ping()
returns a Promise.

src/cache/RedisQueryResultCache.ts[56-130]
src/cache/RedisQueryResultCache.ts[293-305]
src/cache/RedisQueryResultCache.ts[192-222]
src/cache/RedisQueryResultCache.ts[224-239]
test/unit/cache/redis-query-result-cache.ts[67-83]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`detectPromiseBasedApi()` is invoked for all cache client types and has no `clientType` guard. This can incorrectly set `isPromiseBasedApi` for `ioredis` / `ioredis/cluster`, routing them into node-redis-specific Promise code paths (different command names/signatures), and it fails this PR’s own unit test expectation.
## Issue Context
- `connect()` ends by calling `this.detectPromiseBasedApi()` regardless of whether the client is `redis`, `ioredis`, or `ioredis/cluster`.
- `detectPromiseBasedApi()` sets `isPromiseBasedApi` based on `this.client.ping()` return shape with no client-type check.
- Cache operations branch on `isPromiseBasedApi` and use different method names/signatures (e.g., `flushDb()` vs `flushdb()`, `set(..., { PX })` vs `set(..., &amp;quot;PX&amp;quot;, duration, cb)`), so wrong detection can cause runtime failures.
## Fix Focus Areas
- src/cache/RedisQueryResultCache.ts[56-130]
- src/cache/RedisQueryResultCache.ts[293-305]
- src/cache/RedisQueryResultCache.ts[192-239]
- test/unit/cache/redis-query-result-cache.ts[67-83]
## Suggested change
- Add a guard in `detectPromiseBasedApi()`:
- `if (this.clientType !== &amp;quot;redis&amp;quot;) return;`
- optionally also `if (typeof this.client?.ping !== &amp;quot;function&amp;quot;) return;`
- Alternatively (or additionally), call `detectPromiseBasedApi()` only inside the `if (this.clientType === &amp;quot;redis&amp;quot;) { ... }` branch in `connect()`.
- Keep the existing ioredis behavior on the callback-style branch unless you also update ioredis promise-path calls to correct method names/signatures and add tests.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

7. Unhandled Promise from ping() call ☑ 🐞 Bug ⛯ Reliability
Description
• The detectPromiseBasedApi() method calls this.client.ping() without handling the returned Promise
for Redis v5+ clients • If ping() fails or rejects (e.g., network issues, authentication errors), it
creates an unhandled promise rejection • While unlikely after successful connection, this violates
best practices and could cause Node.js warnings or crashes in strict mode
Code

src/cache/RedisQueryResultCache.ts[R305-306]

+        const result = this.client.ping()
+        this.isPromiseBasedApi = result && typeof result.then === "function"
Evidence
The code calls ping() and only checks if the return value has a 'then' method, but never awaits or
catches the Promise. For Redis v5+, this returns a Promise that is left unhandled. The connect()
method sets up error handlers (lines 81-83) but only for the 'error' event, not for unhandled
promises from method calls.

src/cache/RedisQueryResultCache.ts[305-306]
src/cache/RedisQueryResultCache.ts[81-83]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue Description
The detectPromiseBasedApi() method calls this.client.ping() without handling the returned Promise, which can lead to unhandled promise rejections if the ping fails.
## Issue Context
This occurs in the Redis client initialization flow after connection is established. The method is used to detect whether the client uses Promise-based (v5+) or callback-based (v3/v4) API.
## Fix Focus Areas
- src/cache/RedisQueryResultCache.ts[297-307] - Add error handling to the ping() call
Recommended approach: Add a .catch() handler to silently ignore ping errors since this is only for type detection:

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


8. Test mock doesn't match real behavior 🐞 Bug ✓ Correctness
Description
• The test for callback-based API detection uses a mock that returns the string 'PONG', but real
Redis v3/v4 callback-based ping() methods return undefined • The comment says '(returns undefined)'
but the implementation returns a string • While the test passes (both undefined and 'PONG' are
non-Promise values), it doesn't accurately represent actual Redis client behavior
Code

test/unit/cache/redis-query-result-cache.ts[R56-59]

+            // Mock client with callback-based ping() (returns undefined)
+            ;(cache as any).client = {
+                ping: () => "PONG",
+            }
Evidence
The test mock returns a string 'PONG' while the comment indicates it should return undefined. Real
callback-based Redis clients' ping() method accepts a callback parameter and returns undefined. The
test works by accident because the detection logic checks for Promise-like objects, and both
undefined and strings fail that check.

test/unit/cache/redis-query-result-cache.ts[56-59]
src/cache/RedisQueryResultCache.ts[304-306]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue Description
The test mock for callback-based Redis client doesn&amp;amp;amp;#x27;t accurately represent real Redis v3/v4 behavior. The mock returns &amp;amp;amp;#x27;PONG&amp;amp;amp;#x27; string but should return undefined.
## Issue Context
This test validates that the detection logic correctly identifies callback-based APIs. Real callback-based Redis clients&amp;amp;amp;#x27; ping() method returns undefined and accepts a callback parameter.
## Fix Focus Areas
- test/unit/cache/redis-query-result-cache.ts[56-59] - Update mock to return undefined
Change the mock from:

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


9. New as any test casts 📘 Rule violation ✓ Correctness
Description
The updated unit tests add new as any casts to access private members and inject a mock client,
which violates the requirement to avoid type-bypassing casts. This can reduce test type-safety and
hide interface mismatches with real Redis clients.
Code

test/unit/cache/redis-query-result-cache.ts[R40-47]

+            ;(cache as any).client = {
+                ping: () => Promise.resolve("pong"),
+            }
-            const cache = new RedisQueryResultCache(
-                mockDataSource as any,
-                "redis",
-            )
-
-            ;(cache as any).detectRedisVersion()
+            // Call the private method
+            ;(cache as any).detectPromiseBasedApi()
-            expect((cache as any).redisMajorVersion).to.equal(3)
+            expect((cache as any).isPromiseBasedApi).to.be.true
Evidence
PR Compliance ID 4 prohibits adding any casts to bypass types; the modified tests introduce new
(cache as any) usages to set client, call a private method, and assert a private flag.

Rule 4: Remove AI-generated noise
test/unit/cache/redis-query-result-cache.ts[40-47]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The unit tests introduce new `(cache as any)` casts to set `client`, call `detectPromiseBasedApi()`, and read `isPromiseBasedApi`, which violates the compliance requirement to avoid `any`-casts used to bypass types.
## Issue Context
These casts are newly added in the updated tests for API detection and reduce type-safety, potentially masking real incompatibilities.
## Fix Focus Areas
- test/unit/cache/redis-query-result-cache.ts[40-47]
- test/unit/cache/redis-query-result-cache.ts[56-64]
- test/unit/cache/redis-query-result-cache.ts[73-82]నున్న

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


View more (21)
10. Unhandled Promise from ping() call ☑ 🐞 Bug ⛯ Reliability
Description
• The detectPromiseBasedApi() method calls this.client.ping() without handling the returned Promise
for Redis v5+ clients • If ping() fails or rejects (e.g., network issues, authentication errors), it
creates an unhandled promise rejection • While unlikely after successful connection, this violates
best practices and could cause Node.js warnings or crashes in strict mode
Code

src/cache/RedisQueryResultCache.ts[R305-306]

+        const result = this.client.ping()
+        this.isPromiseBasedApi = result && typeof result.then === "function"
Evidence
The code calls ping() and only checks if the return value has a 'then' method, but never awaits or
catches the Promise. For Redis v5+, this returns a Promise that is left unhandled. The connect()
method sets up error handlers (lines 81-83) but only for the 'error' event, not for unhandled
promises from method calls.

src/cache/RedisQueryResultCache.ts[305-306]
src/cache/RedisQueryResultCache.ts[81-83]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue Description
The detectPromiseBasedApi() method calls this.client.ping() without handling the returned Promise, which can lead to unhandled promise rejections if the ping fails.
## Issue Context
This occurs in the Redis client initialization flow after connection is established. The method is used to detect whether the client uses Promise-based (v5+) or callback-based (v3/v4) API.
## Fix Focus Areas
- src/cache/RedisQueryResultCache.ts[297-307] - Add error handling to the ping() call
Recommended approach: Add a .catch() handler to silently ignore ping errors since this is only for type detection:

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


11. Test mock doesn't match real behavior 🐞 Bug ✓ Correctness
Description
• The test for callback-based API detection uses a mock that returns the string 'PONG', but real
Redis v3/v4 callback-based ping() methods return undefined • The comment says '(returns undefined)'
but the implementation returns a string • While the test passes (both undefined and 'PONG' are
non-Promise values), it doesn't accurately represent actual Redis client behavior
Code

test/unit/cache/redis-query-result-cache.ts[R56-59]

+            // Mock client with callback-based ping() (returns undefined)
+            ;(cache as any).client = {
+                ping: () => "PONG",
+            }
Evidence
The test mock returns a string 'PONG' while the comment indicates it should return undefined. Real
callback-based Redis clients' ping() method accepts a callback parameter and returns undefined. The
test works by accident because the detection logic checks for Promise-like objects, and both
undefined and strings fail that check.

test/unit/cache/redis-query-result-cache.ts[56-59]
src/cache/RedisQueryResultCache.ts[304-306]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue Description
The test mock for callback-based Redis client doesn&amp;amp;amp;amp;#x27;t accurately represent real Redis v3/v4 behavior. The mock returns &amp;amp;amp;amp;#x27;PONG&amp;amp;amp;amp;#x27; string but should return undefined.
## Issue Context
This test validates that the detection logic correctly identifies callback-based APIs. Real callback-based Redis clients&amp;amp;amp;amp;#x27; ping() method returns undefined and accepts a callback parameter.
## Fix Focus Areas
- test/unit/cache/redis-query-result-cache.ts[56-59] - Update mock to return undefined
Change the mock from:

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


12. Unhandled Promise from ping() call ☑ 🐞 Bug ⛯ Reliability
Description
• The detectPromiseBasedApi() method calls this.client.ping() without handling the returned Promise
for Redis v5+ clients • If ping() fails or rejects (e.g., network issues, authentication errors), it
creates an unhandled promise rejection • While unlikely after successful connection, this violates
best practices and could cause Node.js warnings or crashes in strict mode
Code

src/cache/RedisQueryResultCache.ts[R305-306]

+        const result = this.client.ping()
+        this.isPromiseBasedApi = result && typeof result.then === "function"
Evidence
The code calls ping() and only checks if the return value has a 'then' method, but never awaits or
catches the Promise. For Redis v5+, this returns a Promise that is left unhandled. The connect()
method sets up error handlers (lines 81-83) but only for the 'error' event, not for unhandled
promises from method calls.

src/cache/RedisQueryResultCache.ts[305-306]
src/cache/RedisQueryResultCache.ts[81-83]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue Description
The detectPromiseBasedApi() method calls this.client.ping() without handling the returned Promise, which can lead to unhandled promise rejections if the ping fails.
## Issue Context
This occurs in the Redis client initialization flow after connection is established. The method is used to detect whether the client uses Promise-based (v5+) or callback-based (v3/v4) API.
## Fix Focus Areas
- src/cache/RedisQueryResultCache.ts[297-307] - Add error handling to the ping() call
Recommended approach: Add a .catch() handler to silently ignore ping errors since this is only for type detection:

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


13. Test mock doesn't match real behavior 🐞 Bug ✓ Correctness
Description
• The test for callback-based API detection uses a mock that returns the string 'PONG', but real
Redis v3/v4 callback-based ping() methods return undefined • The comment says '(returns undefined)'
but the implementation returns a string • While the test passes (both undefined and 'PONG' are
non-Promise values), it doesn't accurately represent actual Redis client behavior
Code

test/unit/cache/redis-query-result-cache.ts[R56-59]

+            // Mock client with callback-based ping() (returns undefined)
+            ;(cache as any).client = {
+                ping: () => "PONG",
+            }
Evidence
The test mock returns a string 'PONG' while the comment indicates it should return undefined. Real
callback-based Redis clients' ping() method accepts a callback parameter and returns undefined. The
test works by accident because the detection logic checks for Promise-like objects, and both
undefined and strings fail that check.

test/unit/cache/redis-query-result-cache.ts[56-59]
src/cache/RedisQueryResultCache.ts[304-306]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue Description
The test mock for callback-based Redis client doesn&amp;amp;amp;amp;#x27;t accurately represent real Redis v3/v4 behavior. The mock returns &amp;amp;amp;amp;#x27;PONG&amp;amp;amp;amp;#x27; string but should return undefined.
## Issue Context
This test validates that the detection logic correctly identifies callback-based APIs. Real callback-based Redis clients&amp;amp;amp;amp;#x27; ping() method returns undefined and accepts a callback parameter.
## Fix Focus Areas
- test/unit/cache/redis-query-result-cache.ts[56-59] - Update mock to return undefined
Change the mock from:

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


14. New as any test casts 📘 Rule violation ✓ Correctness
Description
The updated unit tests add new as any casts to access private members and inject a mock client,
which violates the requirement to avoid type-bypassing casts. This can reduce test type-safety and
hide interface mismatches with real Redis clients.
Code

test/unit/cache/redis-query-result-cache.ts[R40-47]

+            ;(cache as any).client = {
+                ping: () => Promise.resolve("pong"),
+            }
-            const cache = new RedisQueryResultCache(
-                mockDataSource as any,
-                "redis",
-            )
-
-            ;(cache as any).detectRedisVersion()
+            // Call the private method
+            ;(cache as any).detectPromiseBasedApi()
-            expect((cache as any).redisMajorVersion).to.equal(3)
+            expect((cache as any).isPromiseBasedApi).to.be.true
Evidence
PR Compliance ID 4 prohibits adding any casts to bypass types; the modified tests introduce new
(cache as any) usages to set client, call a private method, and assert a private flag.

Rule 4: Remove AI-generated noise
test/unit/cache/redis-query-result-cache.ts[40-47]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The unit tests introduce new `(cache as any)` casts to set `client`, call `detectPromiseBasedApi()`, and read `isPromiseBasedApi`, which violates the compliance requirement to avoid `any`-casts used to bypass types.
## Issue Context
These casts are newly added in the updated tests for API detection and reduce type-safety, potentially masking real incompatibilities.
## Fix Focus Areas
- test/unit/cache/redis-query-result-cache.ts[40-47]
- test/unit/cache/redis-query-result-cache.ts[56-64]
- test/unit/cache/redis-query-result-cache.ts[73-82]నున్న

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


15. Unhandled Promise from ping() call ☑ 🐞 Bug ⛯ Reliability
Description
• The detectPromiseBasedApi() method calls this.client.ping() without handling the returned Promise
for Redis v5+ clients • If ping() fails or rejects (e.g., network issues, authentication errors), it
creates an unhandled promise rejection • While unlikely after successful connection, this violates
best practices and could cause Node.js warnings or crashes in strict mode
Code

src/cache/RedisQueryResultCache.ts[R305-306]

+        const result = this.client.ping()
+        this.isPromiseBasedApi = result && typeof result.then === "function"
Evidence
The code calls ping() and only checks if the return value has a 'then' method, but never awaits or
catches the Promise. For Redis v5+, this returns a Promise that is left unhandled. The connect()
method sets up error handlers (lines 81-83) but only for the 'error' event, not for unhandled
promises from method calls.

src/cache/RedisQueryResultCache.ts[305-306]
src/cache/RedisQueryResultCache.ts[81-83]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue Description
The detectPromiseBasedApi() method calls this.client.ping() without handling the returned Promise, which can lead to unhandled promise rejections if the ping fails.
## Issue Context
This occurs in the Redis client initialization flow after connection is established. The method is used to detect whether the client uses Promise-based (v5+) or callback-based (v3/v4) API.
## Fix Focus Areas
- src/cache/RedisQueryResultCache.ts[297-307] - Add error handling to the ping() call
Recommended approach: Add a .catch() handler to silently ignore ping errors since this is only for type detection:

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


16. Test mock doesn't match real behavior 🐞 Bug ✓ Correctness
Description
• The test for callback-based API detection uses a mock that returns the string 'PONG', but real
Redis v3/v4 callback-based ping() methods return undefined • The comment says '(returns undefined)'
but the implementation returns a string • While the test passes (both undefined and 'PONG' are
non-Promise values), it doesn't accurately represent actual Redis client behavior
Code

test/unit/cache/redis-query-result-cache.ts[R56-59]

+            // Mock client with callback-based ping() (returns undefined)
+            ;(cache as any).client = {
+                ping: () => "PONG",
+            }
Evidence
The test mock returns a string 'PONG' while the comment indicates it should return undefined. Real
callback-based Redis clients' ping() method accepts a callback parameter and returns undefined. The
test works by accident because the detection logic checks for Promise-like objects, and both
undefined and strings fail that check.

test/unit/cache/redis-query-result-cache.ts[56-59]
src/cache/RedisQueryResultCache.ts[304-306]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue Description
The test mock for callback-based Redis client doesn&amp;amp;amp;amp;amp;#x27;t accurately represent real Redis v3/v4 behavior. The mock returns &amp;amp;amp;amp;amp;#x27;PONG&amp;amp;amp;amp;amp;#x27; string but should return undefined.
## Issue Context
This test validates that the detection logic correctly identifies callback-based APIs. Real callback-based Redis clients&amp;amp;amp;amp;amp;#x27; ping() method returns undefined and accepts a callback parameter.
## Fix Focus Areas
- test/unit/cache/redis-query-result-cache.ts[56-59] - Update mock to return undefined
Change the mock from:

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


17. New as any test casts 📘 Rule violation ✓ Correctness
Description
The updated unit tests add new as any casts to access private members and inject a mock client,
which violates the requirement to avoid type-bypassing casts. This can reduce test type-safety and
hide interface mismatches with real Redis clients.
Code

test/unit/cache/redis-query-result-cache.ts[R40-47]

+            ;(cache as any).client = {
+                ping: () => Promise.resolve("pong"),
+            }
-            const cache = new RedisQueryResultCache(
-                mockDataSource as any,
-                "redis",
-            )
-
-            ;(cache as any).detectRedisVersion()
+            // Call the private method
+            ;(cache as any).detectPromiseBasedApi()
-            expect((cache as any).redisMajorVersion).to.equal(3)
+            expect((cache as any).isPromiseBasedApi).to.be.true
Evidence
PR Compliance ID 4 prohibits adding any casts to bypass types; the modified tests introduce new
(cache as any) usages to set client, call a private method, and assert a private flag.

Rule 4: Remove AI-generated noise
test/unit/cache/redis-query-result-cache.ts[40-47]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The unit tests introduce new `(cache as any)` casts to set `client`, call `detectPromiseBasedApi()`, and read `isPromiseBasedApi`, which violates the compliance requirement to avoid `any`-casts used to bypass types.
## Issue Context
These casts are newly added in the updated tests for API detection and reduce type-safety, potentially masking real incompatibilities.
## Fix Focus Areas
- test/unit/cache/redis-query-result-cache.ts[40-47]
- test/unit/cache/redis-query-result-cache.ts[56-64]
- test/unit/cache/redis-query-result-cache.ts[73-82]నున్న

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


18. Unhandled Promise from ping() call ☑ 🐞 Bug ⛯ Reliability
Description
• The detectPromiseBasedApi() method calls this.client.ping() without handling the returned Promise
for Redis v5+ clients • If ping() fails or rejects (e.g., network issues, authentication errors), it
creates an unhandled promise rejection • While unlikely after successful connection, this violates
best practices and could cause Node.js warnings or crashes in strict mode
Code

src/cache/RedisQueryResultCache.ts[R305-306]

+        const result = this.client.ping()
+        this.isPromiseBasedApi = result && typeof result.then === "function"
Evidence
The code calls ping() and only checks if the return value has a 'then' method, but never awaits or
catches the Promise. For Redis v5+, this returns a Promise that is left unhandled. The connect()
method sets up error handlers (lines 81-83) but only for the 'error' event, not for unhandled
promises from method calls.

src/cache/RedisQueryResultCache.ts[305-306]
src/cache/RedisQueryResultCache.ts[81-83]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue Description
The detectPromiseBasedApi() method calls this.client.ping() without handling the returned Promise, which can lead to unhandled promise rejections if the ping fails.
## Issue Context
This occurs in the Redis client initialization flow after connection is established. The method is used to detect whether the client uses Promise-based (v5+) or callback-based (v3/v4) API.
## Fix Focus Areas
- src/cache/RedisQueryResultCache.ts[297-307] - Add error handling to the ping() call
Recommended approach: Add a .catch() handler to silently ignore ping errors since this is only for type detection:

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


19. Test mock doesn't match real behavior 🐞 Bug ✓ Correctness
Description
• The test for callback-based API detection uses a mock that returns the string 'PONG', but real
Redis v3/v4 callback-based ping() methods return undefined • The comment says '(returns undefined)'
but the implementation returns a string • While the test passes (both undefined and 'PONG' are
non-Promise values), it doesn't accurately represent actual Redis client behavior
Code

test/unit/cache/redis-query-result-cache.ts[R56-59]

+            // Mock client with callback-based ping() (returns undefined)
+            ;(cache as any).client = {
+                ping: () => "PONG",
+            }
Evidence
The test mock returns a string 'PONG' while the comment indicates it should return undefined. Real
callback-based Redis clients' ping() method accepts a callback parameter and returns undefined. The
test works by accident because the detection logic checks for Promise-like objects, and both
undefined and strings fail that check.

test/unit/cache/redis-query-result-cache.ts[56-59]
src/cache/RedisQueryResultCache.ts[304-306]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue Description
The test mock for callback-based Redis client doesn&amp;amp;amp;#x27;t accurately represent real Redis v3/v4 behavior. The mock returns &amp;amp;amp;#x27;PONG&amp;amp;amp;#x27; string but should return undefined.
## Issue Context
This test validates that the detection logic correctly identifies callback-based APIs. Real callback-based Redis clients&amp;amp;amp;#x27; ping() method returns undefined and accepts a callback parameter.
## Fix Focus Areas
- test/unit/cache/redis-query-result-cache.ts[56-59] - Update mock to return undefined
Change the mock from:

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


20. Unhandled Promise from ping() call ☑ 🐞 Bug ⛯ Reliability
Description
• The detectPromiseBasedApi() method calls this.client.ping() without handling the returned Promise
for Redis v5+ clients • If ping() fails or rejects (e.g., network issues, authentication errors), it
creates an unhandled promise rejection • While unlikely after successful connection, this violates
best practices and could cause Node.js warnings or crashes in strict mode
Code

src/cache/RedisQueryResultCache.ts[R305-306]

+        const result = this.client.ping()
+        this.isPromiseBasedApi = result && typeof result.then === "function"
Details

@gioboa gioboa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you look at the qodo comment please?

Comment thread src/cache/RedisQueryResultCache.ts Resolved
Comment thread src/cache/RedisQueryResultCache.ts Resolved
@cyberemissary

Copy link
Copy Markdown

This change resolved the issue I reported #11846
Thank you

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (1) 📎 Requirement gaps (0)

Grey Divider


Remediation recommended

1. New as any test casts 📘 Rule violation ✓ Correctness ⭐ New
Description
The updated unit tests add new as any casts to access private members and inject a mock client,
which violates the requirement to avoid type-bypassing casts. This can reduce test type-safety and
hide interface mismatches with real Redis clients.
Code

test/unit/cache/redis-query-result-cache.ts[R40-47]

+            ;(cache as any).client = {
+                ping: () => Promise.resolve("pong"),
+            }

-            const cache = new RedisQueryResultCache(
-                mockDataSource as any,
-                "redis",
-            )
-
-            ;(cache as any).detectRedisVersion()
+            // Call the private method
+            ;(cache as any).detectPromiseBasedApi()

-            expect((cache as any).redisMajorVersion).to.equal(3)
+            expect((cache as any).isPromiseBasedApi).to.be.true
Evidence
PR Compliance ID 4 prohibits adding any casts to bypass types; the modified tests introduce new
(cache as any) usages to set client, call a private method, and assert a private flag.

Rule 4: Remove AI-generated noise
test/unit/cache/redis-query-result-cache.ts[40-47]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The unit tests introduce new `(cache as any)` casts to set `client`, call `detectPromiseBasedApi()`, and read `isPromiseBasedApi`, which violates the compliance requirement to avoid `any`-casts used to bypass types.

## Issue Context
These casts are newly added in the updated tests for API detection and reduce type-safety, potentially masking real incompatibilities.

## Fix Focus Areas
- test/unit/cache/redis-query-result-cache.ts[40-47]
- test/unit/cache/redis-query-result-cache.ts[56-64]
- test/unit/cache/redis-query-result-cache.ts[73-82]నున్న

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Unhandled Promise from ping() call 🐞 Bug ⛯ Reliability
Description
• The detectPromiseBasedApi() method calls this.client.ping() without handling the returned Promise
for Redis v5+ clients • If ping() fails or rejects (e.g., network issues, authentication errors), it
creates an unhandled promise rejection • While unlikely after successful connection, this violates
best practices and could cause Node.js warnings or crashes in strict mode
Code

src/cache/RedisQueryResultCache.ts[R305-306]

+        const result = this.client.ping()
+        this.isPromiseBasedApi = result && typeof result.then === "function"
Evidence
The code calls ping() and only checks if the return value has a 'then' method, but never awaits or
catches the Promise. For Redis v5+, this returns a Promise that is left unhandled. The connect()
method sets up error handlers (lines 81-83) but only for the 'error' event, not for unhandled
promises from method calls.

src/cache/RedisQueryResultCache.ts[305-306]
src/cache/RedisQueryResultCache.ts[81-83]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue Description
The detectPromiseBasedApi() method calls this.client.ping() without handling the returned Promise, which can lead to unhandled promise rejections if the ping fails.
## Issue Context
This occurs in the Redis client initialization flow after connection is established. The method is used to detect whether the client uses Promise-based (v5+) or callback-based (v3/v4) API.
## Fix Focus Areas
- src/cache/RedisQueryResultCache.ts[297-307] - Add error handling to the ping() call
Recommended approach: Add a .catch() handler to silently ignore ping errors since this is only for type detection:

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Test mock doesn't match real behavior 🐞 Bug ✓ Correctness
Description
• The test for callback-based API detection uses a mock that returns the string 'PONG', but real
Redis v3/v4 callback-based ping() methods return undefined • The comment says '(returns undefined)'
but the implementation returns a string • While the test passes (both undefined and 'PONG' are
non-Promise values), it doesn't accurately represent actual Redis client behavior
Code

test/unit/cache/redis-query-result-cache.ts[R56-59]

+            // Mock client with callback-based ping() (returns undefined)
+            ;(cache as any).client = {
+                ping: () => "PONG",
+            }
Evidence
The test mock returns a string 'PONG' while the comment indicates it should return undefined. Real
callback-based Redis clients' ping() method accepts a callback parameter and returns undefined. The
test works by accident because the detection logic checks for Promise-like objects, and both
undefined and strings fail that check.

test/unit/cache/redis-query-result-cache.ts[56-59]
src/cache/RedisQueryResultCache.ts[304-306]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue Description
The test mock for callback-based Redis client doesn&amp;#x27;t accurately represent real Redis v3/v4 behavior. The mock returns &amp;#x27;PONG&amp;#x27; string but should return undefined.
## Issue Context
This test validates that the detection logic correctly identifies callback-based APIs. Real callback-based Redis clients&amp;#x27; ping() method returns undefined and accepts a callback parameter.
## Fix Focus Areas
- test/unit/cache/redis-query-result-cache.ts[56-59] - Update mock to return undefined
Change the mock from:

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

Comment thread src/cache/RedisQueryResultCache.ts Resolved
@G0maa
G0maa requested a review from alumni February 28, 2026 09:08
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (5) 📘 Rule violations (2) 📎 Requirement gaps (0)

Grey Divider


Action required

1. Empty ping().catch(() => {}) 📘 Rule violation ⛯ Reliability ⭐ New
Description
The new Redis API detection code swallows ping() errors via an empty catch, which can mask
connection/auth problems and looks like defensive noise. This violates the requirement to avoid
abnormal defensive code and AI-like slop.
Code

src/cache/RedisQueryResultCache.ts[R300-303]

+        const result = this.client.ping()
+        this.isPromiseBasedApi = !!result?.then
+        if (this.isPromiseBasedApi) {
+            result.catch(() => {})
Evidence
Compliance ID 4 disallows abnormal defensive code; the added empty catch explicitly suppresses
errors from a network call (ping()), hiding failures instead of handling them meaningfully.

Rule 4: Remove AI-generated noise
src/cache/RedisQueryResultCache.ts[300-303]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`detectPromiseBasedApi()` calls `ping()` and then suppresses failures with an empty `catch(() =&gt; {})`, which can hide real connectivity/authentication problems and violates the &quot;Remove AI-generated noise&quot; requirement.

## Issue Context
This code runs during cache initialization and should not silently ignore Redis errors.

## Fix Focus Areas
- src/cache/RedisQueryResultCache.ts[300-303]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Detection runs for ioredis 🐞 Bug ✓ Correctness ⭐ New
Description
connect() calls detectPromiseBasedApi() for all client types, and detectPromiseBasedApi() has no
clientType guard. This can flip ioredis/ioredis-cluster into the Promise-based branches that use
node-redis-specific method names/signatures (e.g., flushDb() and set(key, value, {PX})), and it also
contradicts this PR’s unit test expectation for ioredis.
Code

src/cache/RedisQueryResultCache.ts[R297-305]

+    private detectPromiseBasedApi(): void {
+        // Call ping() and check if it returns a Promise
+        // This works because v5+ returns Promises directly, while v4 with legacyMode uses callbacks
+        const result = this.client.ping()
+        this.isPromiseBasedApi = !!result?.then
+        if (this.isPromiseBasedApi) {
+            result.catch(() => {})
        }
-        if (major <= 4) {
-            // Redis 3/4 uses callback-based API
-            this.redisMajorVersion = 3
-        } else {
-            // Redis 5+ uses Promise-based API
-            this.redisMajorVersion = 5
-        }
-    }
-
-    /**
-     * Checks if Redis version is 5.x or higher
-     */
-    private isRedis5OrHigher(): boolean {
-        if (this.clientType !== "redis") return false
-        return (
-            this.redisMajorVersion !== undefined && this.redisMajorVersion >= 5
-        )
    }
Evidence
The implementation unconditionally runs API-style detection after connect, and the detector sets
isPromiseBasedApi purely from ping()’s return value. Many cache operations branch on
isPromiseBasedApi and use different method names/signatures between the two branches (flushDb vs
flushdb; set with {PX} vs "PX", duration). The PR’s own unit test asserts ioredis should not be
detected (remain false), but the current implementation will set it to true if ioredis ping()
returns a Promise.

src/cache/RedisQueryResultCache.ts[56-130]
src/cache/RedisQueryResultCache.ts[293-305]
src/cache/RedisQueryResultCache.ts[192-222]
src/cache/RedisQueryResultCache.ts[224-239]
test/unit/cache/redis-query-result-cache.ts[67-83]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`detectPromiseBasedApi()` is invoked for all cache client types and has no `clientType` guard. This can incorrectly set `isPromiseBasedApi` for `ioredis` / `ioredis/cluster`, routing them into node-redis-specific Promise code paths (different command names/signatures), and it fails this PR’s own unit test expectation.

## Issue Context
- `connect()` ends by calling `this.detectPromiseBasedApi()` regardless of whether the client is `redis`, `ioredis`, or `ioredis/cluster`.
- `detectPromiseBasedApi()` sets `isPromiseBasedApi` based on `this.client.ping()` return shape with no client-type check.
- Cache operations branch on `isPromiseBasedApi` and use different method names/signatures (e.g., `flushDb()` vs `flushdb()`, `set(..., { PX })` vs `set(..., &quot;PX&quot;, duration, cb)`), so wrong detection can cause runtime failures.

## Fix Focus Areas
- src/cache/RedisQueryResultCache.ts[56-130]
- src/cache/RedisQueryResultCache.ts[293-305]
- src/cache/RedisQueryResultCache.ts[192-239]
- test/unit/cache/redis-query-result-cache.ts[67-83]

## Suggested change
- Add a guard in `detectPromiseBasedApi()`:
 - `if (this.clientType !== &quot;redis&quot;) return;`
 - optionally also `if (typeof this.client?.ping !== &quot;function&quot;) return;`
- Alternatively (or additionally), call `detectPromiseBasedApi()` only inside the `if (this.clientType === &quot;redis&quot;) { ... }` branch in `connect()`.
- Keep the existing ioredis behavior on the callback-style branch unless you also update ioredis promise-path calls to correct method names/signatures and add tests.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

3. Unhandled Promise from ping() call 🐞 Bug ⛯ Reliability
Description
• The detectPromiseBasedApi() method calls this.client.ping() without handling the returned Promise
for Redis v5+ clients • If ping() fails or rejects (e.g., network issues, authentication errors), it
creates an unhandled promise rejection • While unlikely after successful connection, this violates
best practices and could cause Node.js warnings or crashes in strict mode
Code

src/cache/RedisQueryResultCache.ts[R305-306]

+        const result = this.client.ping()
+        this.isPromiseBasedApi = result && typeof result.then === "function"
Evidence
The code calls ping() and only checks if the return value has a 'then' method, but never awaits or
catches the Promise. For Redis v5+, this returns a Promise that is left unhandled. The connect()
method sets up error handlers (lines 81-83) but only for the 'error' event, not for unhandled
promises from method calls.

src/cache/RedisQueryResultCache.ts[305-306]
src/cache/RedisQueryResultCache.ts[81-83]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue Description
The detectPromiseBasedApi() method calls this.client.ping() without handling the returned Promise, which can lead to unhandled promise rejections if the ping fails.
## Issue Context
This occurs in the Redis client initialization flow after connection is established. The method is used to detect whether the client uses Promise-based (v5+) or callback-based (v3/v4) API.
## Fix Focus Areas
- src/cache/RedisQueryResultCache.ts[297-307] - Add error handling to the ping() call
Recommended approach: Add a .catch() handler to silently ignore ping errors since this is only for type detection:

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


4. Test mock doesn't match real behavior 🐞 Bug ✓ Correctness
Description
• The test for callback-based API detection uses a mock that returns the string 'PONG', but real
Redis v3/v4 callback-based ping() methods return undefined • The comment says '(returns undefined)'
but the implementation returns a string • While the test passes (both undefined and 'PONG' are
non-Promise values), it doesn't accurately represent actual Redis client behavior
Code

test/unit/cache/redis-query-result-cache.ts[R56-59]

+            // Mock client with callback-based ping() (returns undefined)
+            ;(cache as any).client = {
+                ping: () => "PONG",
+            }
Evidence
The test mock returns a string 'PONG' while the comment indicates it should return undefined. Real
callback-based Redis clients' ping() method accepts a callback parameter and returns undefined. The
test works by accident because the detection logic checks for Promise-like objects, and both
undefined and strings fail that check.

test/unit/cache/redis-query-result-cache.ts[56-59]
src/cache/RedisQueryResultCache.ts[304-306]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue Description
The test mock for callback-based Redis client doesn&amp;#x27;t accurately represent real Redis v3/v4 behavior. The mock returns &amp;#x27;PONG&amp;#x27; string but should return undefined.
## Issue Context
This test validates that the detection logic correctly identifies callback-based APIs. Real callback-based Redis clients&amp;#x27; ping() method returns undefined and accepts a callback parameter.
## Fix Focus Areas
- test/unit/cache/redis-query-result-cache.ts[56-59] - Update mock to return undefined
Change the mock from:

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


5. New as any test casts 📘 Rule violation ✓ Correctness
Description
The updated unit tests add new as any casts to access private members and inject a mock client,
which violates the requirement to avoid type-bypassing casts. This can reduce test type-safety and
hide interface mismatches with real Redis clients.
Code

test/unit/cache/redis-query-result-cache.ts[R40-47]

+            ;(cache as any).client = {
+                ping: () => Promise.resolve("pong"),
+            }

-            const cache = new RedisQueryResultCache(
-                mockDataSource as any,
-                "redis",
-            )
-
-            ;(cache as any).detectRedisVersion()
+            // Call the private method
+            ;(cache as any).detectPromiseBasedApi()

-            expect((cache as any).redisMajorVersion).to.equal(3)
+            expect((cache as any).isPromiseBasedApi).to.be.true
Evidence
PR Compliance ID 4 prohibits adding any casts to bypass types; the modified tests introduce new
(cache as any) usages to set client, call a private method, and assert a private flag.

Rule 4: Remove AI-generated noise
test/unit/cache/redis-query-result-cache.ts[40-47]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The unit tests introduce new `(cache as any)` casts to set `client`, call `detectPromiseBasedApi()`, and read `isPromiseBasedApi`, which violates the compliance requirement to avoid `any`-casts used to bypass types.
## Issue Context
These casts are newly added in the updated tests for API detection and reduce type-safety, potentially masking real incompatibilities.
## Fix Focus Areas
- test/unit/cache/redis-query-result-cache.ts[40-47]
- test/unit/cache/redis-query-result-cache.ts[56-64]
- test/unit/cache/redis-query-result-cache.ts[73-82]నున్న

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


View more (2)
6. Unhandled Promise from ping() call 🐞 Bug ⛯ Reliability
Description
• The detectPromiseBasedApi() method calls this.client.ping() without handling the returned Promise
for Redis v5+ clients • If ping() fails or rejects (e.g., network issues, authentication errors), it
creates an unhandled promise rejection • While unlikely after successful connection, this violates
best practices and could cause Node.js warnings or crashes in strict mode
Code

src/cache/RedisQueryResultCache.ts[R305-306]

+        const result = this.client.ping()
+        this.isPromiseBasedApi = result && typeof result.then === "function"
Evidence
The code calls ping() and only checks if the return value has a 'then' method, but never awaits or
catches the Promise. For Redis v5+, this returns a Promise that is left unhandled. The connect()
method sets up error handlers (lines 81-83) but only for the 'error' event, not for unhandled
promises from method calls.

src/cache/RedisQueryResultCache.ts[305-306]
src/cache/RedisQueryResultCache.ts[81-83]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue Description
The detectPromiseBasedApi() method calls this.client.ping() without handling the returned Promise, which can lead to unhandled promise rejections if the ping fails.
## Issue Context
This occurs in the Redis client initialization flow after connection is established. The method is used to detect whether the client uses Promise-based (v5+) or callback-based (v3/v4) API.
## Fix Focus Areas
- src/cache/RedisQueryResultCache.ts[297-307] - Add error handling to the ping() call
Recommended approach: Add a .catch() handler to silently ignore ping errors since this is only for type detection:

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


7. Test mock doesn't match real behavior 🐞 Bug ✓ Correctness
Description
• The test for callback-based API detection uses a mock that returns the string 'PONG', but real
Redis v3/v4 callback-based ping() methods return undefined • The comment says '(returns undefined)'
but the implementation returns a string • While the test passes (both undefined and 'PONG' are
non-Promise values), it doesn't accurately represent actual Redis client behavior
Code

test/unit/cache/redis-query-result-cache.ts[R56-59]

+            // Mock client with callback-based ping() (returns undefined)
+            ;(cache as any).client = {
+                ping: () => "PONG",
+            }
Evidence
The test mock returns a string 'PONG' while the comment indicates it should return undefined. Real
callback-based Redis clients' ping() method accepts a callback parameter and returns undefined. The
test works by accident because the detection logic checks for Promise-like objects, and both
undefined and strings fail that check.

test/unit/cache/redis-query-result-cache.ts[56-59]
src/cache/RedisQueryResultCache.ts[304-306]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue Description
The test mock for callback-based Redis client doesn&amp;amp;#x27;t accurately represent real Redis v3/v4 behavior. The mock returns &amp;amp;#x27;PONG&amp;amp;#x27; string but should return undefined.
## Issue Context
This test validates that the detection logic correctly identifies callback-based APIs. Real callback-based Redis clients&amp;amp;#x27; ping() method returns undefined and accepts a callback parameter.
## Fix Focus Areas
- test/unit/cache/redis-query-result-cache.ts[56-59] - Update mock to return undefined
Change the mock from:

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

@G0maa
G0maa requested a review from gioboa February 28, 2026 09:08
@G0maa
G0maa requested review from G0maa and removed request for G0maa February 28, 2026 09:31
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

@G0maa
G0maa changed the base branch from v0.3 to master February 28, 2026 11:25
@G0maa
G0maa changed the base branch from master to v0.3 February 28, 2026 11:26

@gioboa gioboa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM @mguida22

@gioboa
gioboa merged commit f22c7a2 into typeorm:v0.3 Mar 1, 2026
72 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

7 participants