本文介绍了为什么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中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!