Skip to content
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

Redis Caching #390

Closed
tylerFowler opened this issue Apr 21, 2016 · 7 comments
Closed

Redis Caching #390

tylerFowler opened this issue Apr 21, 2016 · 7 comments

Comments

@tylerFowler
Copy link

I find that I'm unable to use the RedisCache caching type, the simple type works fine but when I try to hook it up to Redis and get a slice I get this (with no data):

After running the query for the first time:

ERROR:root:'Flask' object has no attribute 'get'
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/caravel/views.py", line 500, in explore
    payload = obj.get_json()
  File "/usr/local/lib/python2.7/site-packages/caravel/viz.py", line 240, in get_json
    payload = cache.get(cache_key)
  File "/usr/local/lib/python2.7/site-packages/flask_cache/__init__.py", line 196, in get
    return self.cache.get(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/werkzeug/contrib/cache.py", line 598, in get
    return self.load_object(self._client.get(self.key_prefix + key))
AttributeError: 'Flask' object has no attribute 'get'

And then running it every time after that:

ERROR:root:'Flask' object has no attribute 'setex'
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/caravel/views.py", line 500, in explore
    payload = obj.get_json()
  File "/usr/local/lib/python2.7/site-packages/caravel/viz.py", line 259, in get_json
    cache.set(cache_key, payload, timeout=self.cache_timeout)
  File "/usr/local/lib/python2.7/site-packages/flask_cache/__init__.py", line 200, in set
    self.cache.set(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/werkzeug/contrib/cache.py", line 612, in set
    result = self._client.setex(name=self.key_prefix + key,
AttributeError: 'Flask' object has no attribute 'setex'

My Caravel conf looks like this:

...

CACHE_CONFIG = {
    'CACHE_TYPE': 'RedisCache',
    'CACHE_REDIS_HOST': '10.0.0.8',
    'CACHE_REDIS_PORT': '6379',
    'CACHE_KEY_PREFIX': '/caravel'
}
@mistercrunch
Copy link
Member

Looks like a flask-cache or werkzeug bug.

CTRL-F for setex
http://werkzeug.readthedocs.org/en/latest/changes/#

What version of these do you have locally? pip freeze | sort

@tylerFowler
Copy link
Author

Werkzeug: 0.11.8
Flask-Cache: 0.13.1

I figured it was a bug in Flask Cache but thought I'd check here to see if anyone has actually got it working with Redis

@alanmcruickshank
Copy link
Contributor

I've got redis working as a cache and don't remember doing anything too acrobatic. I do remember installing the redis dependency using pip in order for things to work. What version of redis do you have installed using pip?

In the mean time I'll root out my config settings.

@tylerFowler
Copy link
Author

Well this is embarrassing but I forgot to even install redis in my Docker image. I just tried that out, installing redis 2.10.5, but unfortunately I still get the same set of errors.

@alanmcruickshank
Copy link
Contributor

My caravel_config.py settings for the Cache are:

CACHE_DEFAULT_TIMEOUT = 30   # 30s default timeout
CACHE_CONFIG = {
    'CACHE_TYPE': 'redis',
    'CACHE_DEFAULT_TIMEOUT': 30,
    'CACHE_KEY_PREFIX': 'caravel_',
    'CACHE_REDIS_HOST': 'redis',
    'CACHE_REDIS_PORT': 6379,
    'CACHE_REDIS_DB': 1,
    'CACHE_REDIS_URL': 'redis://redis:6379/1'
   }

I'm running caravel 0.8.7 with both caravel and redis running on linked docker containers.

@tylerFowler
Copy link
Author

Ah, so it turns out that the cache type of 'redis' does need to be used. I had tried that initially and got an error of something like 'backend does not exist', which in retrospect is probably due to not having redis installed locally. So then I tried a value of 'RedisCache', which was accepted until I ran into those errors.

But the combination of 'redis' and having the redis package installed seems to work so I'll go ahead and close this issue. Thanks!

@andrewpbergeron
Copy link

'Flask' object has no attribute 'setex'

I had a similar issue also with python Flask. in my config: 'CACHE_TYPE': redis #remove the quotes duhh! it wants "import package redis"

zhaoyongjie pushed a commit to zhaoyongjie/incubator-superset that referenced this issue Nov 17, 2021
zhaoyongjie pushed a commit to zhaoyongjie/incubator-superset that referenced this issue Nov 24, 2021
zhaoyongjie pushed a commit to zhaoyongjie/incubator-superset that referenced this issue Nov 25, 2021
zhaoyongjie pushed a commit to zhaoyongjie/incubator-superset that referenced this issue Nov 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants