Skip to content

Fix RedisCacheHandler SET TTL calculation#52

Open
tobiasvdorp wants to merge 2 commits into
mrjasonroy:mainfrom
tobiasvdorp:fix-redis-cache-handler-ttl
Open

Fix RedisCacheHandler SET TTL calculation#52
tobiasvdorp wants to merge 2 commits into
mrjasonroy:mainfrom
tobiasvdorp:fix-redis-cache-handler-ttl

Conversation

@tobiasvdorp

@tobiasvdorp tobiasvdorp commented Jul 2, 2026

Copy link
Copy Markdown

Summary

Fixes a Redis cache write bug in RedisCacheHandler.set().
calculateLifespan() stores expireAt as epoch seconds, but the Redis TTL calculation compared it directly with Date.now() in milliseconds. That made the computed TTL <= 0, so writes with a TTL were skipped as already expired instead of being stored in Redis.
This changes the Redis TTL calculation to compare seconds with seconds, so SETEX receives a positive TTL again.

Co-authored-by: Cursor <cursoragent@cursor.com>
@tobiasvdorp tobiasvdorp requested a review from mrjasonroy as a code owner July 2, 2026 13:24

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a helper function redisTtlSecondsFromLifespan to correctly compute the remaining Redis EX TTL in seconds from lifespan parameters, fixing a bug where the previous formula (which mixed milliseconds and seconds) resulted in negative or zero TTL values and skipped writes. It also adds corresponding unit tests for this helper and the Redis cache handler. The reviewer recommends restoring real timers after using fake timers in the new test suite to prevent test flakiness.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +423 to +424
describe("TTL on set", () => {
test("should store entry with setex when defaultTTL is configured", async () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Using vi.useFakeTimers() without restoring them can leak fake timers to subsequent tests in this file or other test files, leading to unexpected behavior or flakiness. Please ensure that real timers are restored after the tests in this block run.

  describe("TTL on set", () => {
    afterEach(() => {
      vi.useRealTimers();
    });

    test("should store entry with setex when defaultTTL is configured", async () => {

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant