docs(backends): show how to make Redis fail fast instead of retrying for seconds - #348
Merged
Merged
Conversation
…for seconds With Redis down, redis-py 8's default retry policy makes every cached request wait about 7 s before @cache fails open. Document the cost next to the fail-open text and in the Redis section, with an example that passes retry=, socket_connect_timeout and socket_timeout through the backend, and test that those kwargs reach the redis-py client.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #325
What
With Redis unreachable,
@cachefails open, but only after redis-py has given up. redis-py 8's defaultRetry(10 retries, exponential backoff with jitter, capped at 1 s) makes that slow. Measured with redis-py 8.1.0 (the lockfile version) and the backend's defaults:get/set, defaultsThis PR only changes documentation. The backend's defaults stay as they are; a smaller default retry budget is a separate decision.
docs/HTTP_CACHING.md, "When the backend fails": explains the cost next to the fail-open text, with an example that passesretry=Retry(NoBackoff(), 0),socket_connect_timeoutandsocket_timeoutthroughAsyncRedisCacheBackend's keyword arguments.docs/BACKENDS.md, Redis: new "Failing fast when Redis is down" subsection with the same example and the trade-offs: no retry on a transient error,socket_timeoutalso bounds slow replies, and the settings apply toCacheManager/StateManager/CacheLock/sessions too. It also notes thatRedisConfighas noretryfield.i18n/zh-TW/docs/, with the{#failing-fast-when-redis-is-down}anchor.test_redis_fail_fast_settings_reach_the_clientbuilds the backend exactly as documented, checks that the retry policy and both timeouts reach the redis-py connection kwargs, and checks that agetagainst a closed port fails in under 1 s. It needs no running server and passes on thelowestenv (redis 5.3.0) too.Changelog
No fragment. The repo has no Documentation changelog section, and no library code changed.