#33681 closed Bug (fixed)
Cache OPTIONS are not passed to the Redis client.
Reported by: | Ben Picolo | Owned by: | Mariusz Felisiak |
---|---|---|---|
Component: | Core (Cache system) | Version: | 4.0 |
Severity: | Release blocker | Keywords: | |
Cc: | Nick Pope | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Hello! First Django interaction, so please let me know how better I can give info here.
I discovered unintentionally that there's no default socket_timeout set for Redis cache connections. This is an issue on it's own (unsafe default that's a particularly hard issue to track down), but in trying to set those timeouts, I hit some tough edges of documentation/usage.
The cache documentation says that the OPTIONS object is passed to the third-party connection class for connections backed by third-party libraries for connections backed by third-party libraries. This is reaffirmed for the redis cache specifically here.
Right now, though, these OPTIONS are passed to the first-party RedisCacheClient object, so you can't pass in options expected by the redis connection pool link. In that sense, RedisCacheClient is being treated as a "first-party" cache according to these docs, but it defers directly to the redis library.
One could do a variety of subclassing to make this work, but there's quite a few layers of indirection here, so it's hard to identify exactly what one should subclass in order to get arguments to the connection class appropriately.
(For now, my workaround is take advantage of the from_url behavior where the connection class pulls arguments out of the connection query string, but this isn't straightforward and feels brittle to django implementation details).
There are a couple of options here – revising documentation or changing behavior (or both).
In my ideal case, it would be great for it to be easy to pass down explicit socket and other timeouts. To me, that suggests updating behavior is ideal, because the documentation would potentially lead folk down a path of tough to navigate behavior. Passing those options in tact, or updating the RedisCacheClient to have a wider range of available options would both work out.
Change History (12)
comment:1 by , 3 years ago
Description: | modified (diff) |
---|
comment:2 by , 3 years ago
Description: | modified (diff) |
---|
comment:3 by , 3 years ago
Description: | modified (diff) |
---|
comment:4 by , 3 years ago
Description: | modified (diff) |
---|
comment:5 by , 3 years ago
Description: | modified (diff) |
---|
comment:6 by , 3 years ago
Cc: | added |
---|---|
Severity: | Normal → Release blocker |
Summary: | Redis client OPTIONS don't work as documented, which makes setting Redis timeouts difficult → Cache OPTIONS are not passed to the Redis client. |
Triage Stage: | Unreviewed → Accepted |
Type: | Cleanup/optimization → Bug |
follow-up: 8 comment:7 by , 3 years ago
I could probably give that a go, will see if I can take it on this weekend
comment:8 by , 3 years ago
Replying to Ben Picolo:
I could probably give that a go, will see if I can take it on this weekend
Sounds good!
comment:9 by , 3 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Thanks for the report. Agreed, we should pass all options to the Redis client. Would you like to prepare a patch? It's probably enough to pass the OPTIONS to the underlying client, e.g.
django/core/cache/backends/redis.py
)Marking as a release blocker as this is as a bug in the new feature.