Skip to content

fix(redis): Don't SETEX with a non-positive TTL - #456

Open
DarkaMaul wants to merge 2 commits into
psf:masterfrom
trail-of-forks:fix-redis-negative-ttl
Open

fix(redis): Don't SETEX with a non-positive TTL#456
DarkaMaul wants to merge 2 commits into
psf:masterfrom
trail-of-forks:fix-redis-negative-ttl

Conversation

@DarkaMaul

Copy link
Copy Markdown
Contributor

RedisCache.set forwarded its expiry straight to SETEX, which Redis rejects for seconds <=0 with an "invalid expire time" ResponseError.

(Verified against a local redis container)

@woodruffw

Copy link
Copy Markdown
Member

@DarkaMaul

Copy link
Copy Markdown
Contributor Author

Ooo, I was not familiar with this part of the spec... Indeed, the much cleaner fix is to reject negative values much earlier.
Note that the internal docs says :

The google homepage specifically uses a negative expires header and private cache control header to avoid caches. We've managed to work around that aspect and cache the response using our heuristic.

I can refine the PR to just handle the 0 case that also fails with setex. And then, normalize/reject negative values in the controller, WDYT?

@woodruffw

Copy link
Copy Markdown
Member

Yeah, that sounds good to me. Specifically we should normalize k valid TTLs to zero (and emit a warning log in that case, maybe?), which the controller logic should then treat as "don't cache this."

(That'll change the Google behavior but IMO that's good -- we should follow the specs precisely here.)

@DarkaMaul
DarkaMaul force-pushed the fix-redis-negative-ttl branch from 78e62a8 to 55d730c Compare August 4, 2026 13:47
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.

2 participants