在Django中,使用Memcached在cache.get('key')中返回None [英] cache.get('key') returns None in Django using Memcached

查看:40
本文介绍了在Django中,使用Memcached在cache.get('key')中返回None的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Django应用中使用Memcache,但似乎配置中缺少某些内容.任何帮助,将不胜感激,谢谢!

I am trying to use Memcache in my Django app, but it seems that something in my configuration is missing. Any help would be appreciated, Thank you!

$ python manage.py shell
Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.core.cache import cache
>>> cache.set('my_key', 'hello, world!', 30)
>>> print cache.get('my_key')
None
>>> 

Settings.py

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
        'LOCATION': '127.0.0.1:11211', 
    }
}

已安装的API:

$ pypm install python-memcached
$ brew install memcached
$ brew install libmemcached

推荐答案

我认为我的配置存在一些问题,因此我只是使用MacPorts重新安装了Memcache

I think I had some issues in my configuration, so I just installed Memcache again using MacPorts

$ sudo port install memcached 

然后我运行了Memcache,它可以正常工作

and then I ran Memcache, and it works

$ memcached -vv

这些说明已在Mac OS X 10.7.5(Lion)上进行了测试

These instructions have been tested on Mac OS X 10.7.5 (Lion)

有关更多信息,访问此网站

这篇关于在Django中,使用Memcached在cache.get('key')中返回None的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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