django上的记忆快取无法运作 [英] memcache on django is not working

查看:78
本文介绍了django上的记忆快取无法运作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Celery 中有比赛条件.受此启发-

I have a race condition in Celery. Inspired by this - http://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上的记忆快取无法运作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆