thadeusb / flask-cache

Cache extension for Flask
http://packages.python.org/Flask-Cache/
Other
700 stars 185 forks source link

connecting to an SSL StrictRedis instance for caching #137

Open RedCraig opened 8 years ago

RedCraig commented 8 years ago

This isn't an issue per-se, just something that took me a while to figure out - and I wanted to check the way I'm doing this is OK.

I want to connect to an instance of the microsofts redis cache in azure. They require an ssl connection, example uses StrictRedis connection:

import redis 
r = redis.StrictRedis(host='.redis.cache.windows.net', port=6380, db=0, password='', ssl=True) 
r.set('foo', 'bar') True 
r.get('foo') b'bar'

I couldn't see how to make this work with the flask-cache redis config keys.

I started digging through the source, flask-cache uses werkzeug RedisCache, whose docs say: The first argument can be either a string denoting address of the Redis server or an object resembling an instance of a redis.Redis class.

So it's actually possible to create a StrictRedis instance and pass it to flask-caches CACHE_ARGS in the CACHE_REDIS_HOST option. It works, it just seems a little ...undocumented? All that said, I don't quite see how to use the Custom Cache Backends described in flask-cache docs here, so perhaps there's a way to do similar there.

Thanks for any help!

barakalon commented 7 years ago

Just stumbled across this as well

bradwitte commented 6 years ago

Also had this issue with TLS enabled Redis on AWS

nicholaskuechler commented 6 years ago

@RedCraig How did you make this work? Can you please share your working example code?

bradwitte commented 6 years ago

Here is what worked for me:

import redis 
r = redis.StrictRedis(host='blahblah', port=6380, db=0, password='mypass', ssl=True) 

CACHE_CONFIG = {
'CACHE_TYPE': 'redis',
'CACHE_REDIS_HOST': r,
}