thadeusb/flask-cache

connecting to an SSL StrictRedis instance for caching

RedCraig opened this issue · 4 comments

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!

Just stumbled across this as well

Also had this issue with TLS enabled Redis on AWS

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

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,
}