Skip to content

fix: negative TTL docstring, timedelta precision, and zero TTL warning#29

Open
emiliano-go wants to merge 1 commit into
redis:mainfrom
emiliano-go:fix/ttl-behavior
Open

fix: negative TTL docstring, timedelta precision, and zero TTL warning#29
emiliano-go wants to merge 1 commit into
redis:mainfrom
emiliano-go:fix/ttl-behavior

Conversation

@emiliano-go

Copy link
Copy Markdown

Changes

Bug: Negative TTL docstring promises ValueError that never fires

CacheBackend.set() stated "Raises ValueError: If ttl is negative" but the
code silently treated negative values as "no expiry" (identical to ttl=0).

Fix: Updated the docstring: "None or a value of 0 or below means the key
will not be automatically expired."

Bug: Timedelta TTL sub-second precision loss

CacheBackend.set() converted timedelta TTLs via
int(ttl.total_seconds()), discarding sub-second values.
timedelta(milliseconds=500) rounded down to 0 (no expiry).

Fix: When a timedelta is provided, compute milliseconds via
int(ttl / timedelta(milliseconds=1)) and pass px= to redis.set().

Bug: Warning for default TTL=0 (unbounded growth)

Storing entries without an expiry (TTL=0, the default) silently persists them
forever with no indication to the caller.

Fix: Added logger.warning(...) in both _store_cache_entry() and
CacheBackend.set() when no TTL is set.

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