Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django memcached负值_Django_Memcached_Python 2.6 - Fatal编程技术网

Django memcached负值

Django memcached负值,django,memcached,python-2.6,Django,Memcached,Python 2.6,这里发生了什么 当我用负值初始化缓存键时,我不能使用incr和decr。Get按预期工作 >>> from django.core.cache import cache >>> cache.set('qwerty',-2) >>> cache.incr('qwerty') *** ValueError: Key ':1:qwerty' not found 如果我用一个正数,我会得到预期的行为 >>> cache.set('

这里发生了什么

当我用负值初始化缓存键时,我不能使用incr和decr。Get按预期工作

>>> from django.core.cache import cache
>>> cache.set('qwerty',-2)
>>> cache.incr('qwerty')
*** ValueError: Key ':1:qwerty' not found
如果我用一个正数,我会得到预期的行为

>>> cache.set('qwerty',2)
>>> cache.incr('qwerty')
>>> cache.get('qwerty')
3

这是由于memcache中的限制。只能递增/递减非单整数。

请注意,将缓存后端设置为本地内存(django.core.cache.backends.locmem.LocMemCache)也可以解决此问题。