-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add ssl support #691
add ssl support #691
Conversation
The example here suggests we only need to pass I'm wondering if we should maybe just accept arbitrary arguments and pass them through to |
The single SSL parameter is not enough in the general sense. There are a set of parameters specific to SSL, for example to ignore checking the certificate chain, which is required on heroku. In addition there is a strong case to be made to allow specifying the connection pool class, for example, to allow turning on blocking mode. See redis/redis-py#2517 |
More reason to just pass all arguments through, rather than trying to maintain a list of arguments. |
My first thought is to just move all the existing arguments into a dict, which can be used as default values. Then just do That would disallow positional arguments, but not sure that's a major loss. |
Right and I have connection_pool_kwargs. One of the parameters is specifically overridden per comment and a couple of the others are remapped based on names that this library uses more generally but sure there might be one or two that can be factored out as a general spread through |
I don't think there's any need for naming consistency, ultimately they are arguments for Just realised we probably can't use |
Right, that is why I did the |
If we just allow arbitrary arguments for the entire |
Maybe this PR is reasonable as a backwards-compatible approach for 0.x though. If you're happy to go with that, then please retarget this PR to the 0.12 branch and create a new one for master that uses |
I want to make sure I understand what you are suggesting for the change to master. At present, a redis Cache would be instantiated as: cache = Cache(
Cache.REDIS,
endpoint="127.0.0.1",
port=6379,
password="xyz"
) with this PR (as is), it could be instantiated as (for SSL + Blocking support): cache = Cache(
Cache.REDIS,
endpoint="127.0.0.1",
port=6379,
password="xyz",
ssl=True,
connection_pool_class=redis.BlockingConnectionPool,
connection_pool_kwargs={"ssl_cert_reqs": None}
) and it seems like you are suggesting: cache = Cache(
Cache.REDIS,
redis_args={"connection_pool": BlockingConnectionPool(dict(
host="127.0.0.1",
port=6379,
password="xyz",
decode_responses=False, # make sure to not forget this!
connection_class=redis.SSLConnection
ssl_cert_reqs=None
))}
) which IMHO is not great DX and it makes the params very different for different Cache types. |
The params are different for different cache types.. There are By doing something like this, the advantages are that the user has full flexibility to pass any valid arguments desired to customise the backend, the code is kept very simple resulting in not needing to make changes to keep up-to-date with the upstream library and we don't get more bug reports when another user wants to change SSL ciphers or whatever other details come up in future. |
Ideally there would be a way to still parse the DB url to get a dict rather than an instantiation of the Cache itself. cls, cache_params = Cache.params_from_url(cache_url)
# For: rediss://:pass@host:port/db (injected by Heroku for example)
# ->
Cache.REDIS,
#->
{"connection_pool": {
"host": "127.0.0.1",
"port": 6379,
"password": "xyz",
"decode_responses": False, # okay, but where does this come from?
"connection_class": redis.SSLConnection, # would be cool to get this from the url
#ssl_cert_reqs=None # fine, this would have to be set by the user since is Heroku specific
}} Having a nice utility function like that would be nice and perhaps act a bridge between to the new API . |
That could be nice, I'd look at it as a separate feature though. e.g. the prefix ( |
I do think there is value is splitting up the parsing of the URL from the instantiation. i.e. There are still warts / leaks in the abstraction, for example the |
As an aside, now that I'm hitting this issue -- should |
aioredis migrated to upstream redis. aioredis is no longer supported. |
Rad, thank you! |
How about passing a connection pool instance as an argument? I don't mean that as a replacement for passing creation arguments, but for a different use case, where the pool exists already. This is a different issue, but related to the same topic, i.e. the cache creation, anyway. We are using Redis connections also for other purposes, namely storing session tokens in fastapi-users. Initially we had multiple redis clients happening from various libs, but I was then happy to centralize it to one module, and passing client or the pool from there. I integrated aiocache redis to our app now, but didn't see a way to pass the existing pool, so am for now just letting it do the default behaviour. Am now considering subclassing to customize the initialialization, maybe to pass an existing redis client instance. Am no Redis expert, so don't really know if it's an issue that multiple clients are created. Earlier just wanted to reduce the amount of moving parts and ensure consistent configuration etc. by having a single place for pool and client creation. |
That's exactly what I suggested in my change request: It might make sense to just remove all these arguments and have the user pass in a The only potential issue is that it appears we need |
Again, if someone wants to create a new PR that accepts just accepts Redis client, I'll look at merging that into the master branch. |
I did this for us now by subclassing: import aiocache
from aiocache.base import BaseCache
class AiocacheRedisCacheForClient(aiocache.RedisCache):
def __init__(self, client, **kwargs):
"""skips RedisCache.__init__"""
BaseCache.__init__(self, **kwargs)
self.client = client I also encountered exactly the problem with So +1 for the assert you suggested. |
|
We've updated 1.0 to just accept a Redis client now. |
Is there any way to re-open the PR? |
115532f
to
05e97af
Compare
ok, branch changed and rebased. lmk your thoughts. |
Looks good to me, want to mark the PR as ready? |
Looks like we have a few failing tests too, if you have some time to look at those? |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 0.12 #691 +/- ##
==========================================
- Coverage 99.57% 99.55% -0.03%
==========================================
Files 35 35
Lines 3770 3782 +12
==========================================
+ Hits 3754 3765 +11
- Misses 16 17 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report in Codecov by Sentry.
|
Ok tests fixed |
What do these changes do?
Are there changes in behavior for the user?
Related issue number
Checklist
CHANGES
folder<issue_id>.<type>
(e.g.588.bugfix
)issue_id
change it to the pr id after creating the PR.feature
: Signifying a new feature..bugfix
: Signifying a bug fix..doc
: Signifying a documentation improvement..removal
: Signifying a deprecation or removal of public API..misc
: A ticket has been closed, but it is not of interest to users.Fix issue with non-ascii contents in doctest text files.