Jaymon / caches

Python caching backed by Redis
MIT License
6 stars 3 forks source link

Alias caches.interface.Redis:// to redis:// so that the url will be compatible with Heroku #1

Closed thedrow closed 10 years ago

Jaymon commented 10 years ago

Hrm, I don't think I fully understand the problem. I've never used Heroku but it looks like you can set environment variables using config vars, so you could set the value for CACHES_DSN to something like caches.interface.Redis://localhost:6379/0 and it should work as expected when you import caches as long as you have redis support.

If you're using Redis to go and want to use its env variable, REDISTOGO_URL then you should be able to normalize the url into something caches can use with a small amount of glue code:

import os
import re

import caches

# make redis url caches dsn compliant and configure caches
redis_url = os.getenv('REDISTOGO_URL', 'redis://localhost:6379')
caches_dsn = re.sub('^redis', 'caches.interface.Redis', redis_url)
caches.configure(caches_dsn)

I hope that helps and let me know what if my understanding of the problem is incorrect.

thedrow commented 10 years ago

I know I can use a little bit of glue code but it seems uneccessary. The code should simply detect if redis:// is the scheme and no backend is specified simply pick caches.interfaces.Redis.

Jaymon commented 10 years ago

I'm sorry it has taken me so long to get back to you, we've been insanely busy the last few months.

I created a small Heroku app today and was able to get caches working with very minimal effort, basically, once Redis is activated on the app, you can grab the dsn:

$ heroku config:get REDISTOGO_URL
redis://redistogo:d381fd671fe61c0f6d36bdb4c25d3050@grideye.redistogo.com:10174/

And then just modify that to point to caches.interface.Redis and set it into the configuration value that caches likes:

$ heroku config:set CACHES_DSN=caches.interface.Redis://redistogo:d381fd671fe61c0f6d36bdb4c25d3050@grideye.redistogo.com:10174/

Now, just importing caches into your python code should handle all the configuring you need, with no other glue code necessary

import caches # this will automatically use CACHES_DSN and configure module

I'm going to go ahead and close this since it doesn't appear anything really needs to be changed to support Heroku and the current dsn is more explicit and consistent with our other libraries.