我在 Celery 中有比赛条件.受此启发- ask.github.io/celery/cookbook/tasks.html#ensuring-a-task-is-only-exected-一次一次我决定使用内存缓存为我的任务添加锁.
I have a race condition in Celery. Inspired by this - ask.github.io/celery/cookbook/tasks.html#ensuring-a-task-is-only-executed-one-at-a-time I decided to use memcache to add locks to my tasks.
这些是我所做的更改:
python-memcached # settings for memcache CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache', 'LOCATION': '127.0.0.1:11211', } }此后,我登录我的shell并执行以下操作
After this I login to my shell and do the following
>>> import os >>> import django >>> from django.core.cache import cache >>> os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proj.settings.base') >>> cache <django.core.cache.DefaultCacheProxy object at 0x101e4c860> >>> cache.set('my_key', 'hello, world!', 30) #display nothing. No T/F >>> cache.get('my_key') #Display nothing. >>> from django.core.cache import caches >>> caches['default'] <django.core.cache.backends.memcached.MemcachedCache object at 0x1048a5208> >>> caches['default'].set('my_key', 'hello, world!', 30) #display nothing. No T/F >>> caches['default'].get('my_key') #Display nothing.也做了 pip安装python-memcached
使用 Python 3.6 , Django == 1.10.5
我做错了什么?任何帮助将不胜感激.
What am I doing wrong? Any help will be appreciated.
推荐答案问题是,由于某种原因,memcached被杀死了,我以为它仍在运行.我的错.现在一切正常.
The problem was, memcached was killed for some reason and I was assumed it was still running. My bad. Now it works all perfectly.
对于任何想解决类似问题的人,要确保您仍在运行memcached,请尝试 memcached -vv
For anyone who is stuck on a similar problem you want to make sure you are still running memcached, try memcached -vv
在此保留以供参考.
更多推荐
django上的记忆快取无法运作
发布评论