django上的记忆快取无法运作

编程入门 行业动态 更新时间:2024-10-26 16:29:09
本文介绍了django上的记忆快取无法运作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在 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上的记忆快取无法运作

本文发布于:2023-10-24 08:58:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1523506.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:快取   记忆   django

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!