本文介绍了为什么 memcache 在我的 Django 中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
from django.core.cache import cache
def testcache():
cache.set('test','I am putting this message in',3333)
print cache.get('test')
它只是打印无"
这是在ps aux"中:
This is in "ps aux":
dovr 2241 0.0 0.8 57824 2144 ? Ssl 04:20 0:00 memcached -d -u root -m 3900 -p 11211
dovr 2247 0.0 3.7 83696 9800 pts/2 S+ 04:20 0:00 python manage.py runserver 0.0.0.0:8000
这是在我的 settings.py 中:
And this is in my settings.py:
CACHE_BACKEND = 'memcached://MYIPADRESS:11211/'
顺便说一下,它以前有效,但现在不行了!我不知道为什么.好奇怪.
By the way, it worked before, but not anymore! I don't know why. So weird.
推荐答案
已解决.
Django 正在与服务器通话.我做了nc IPADRESS 11211".并输入统计数据"
Django was talking to the server.I did "nc IPADRESS 11211" .And typed "stats"
然后,我发现 cmd_get 和 cmd_set 正在发生变化,所以这意味着它在说话.
Then, I looked that cmd_get and cmd_set were changing, so that means it's talking.
然后,我意识到我的视图中的代码有问题.键中不能有空格".它必须是非空白的(并且已编码)
Then, I realized that I had problem with code in my views.You can't have "space" in the key. It has to be non-spaceless (and encoded)
这篇关于为什么 memcache 在我的 Django 中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!