使用Django在UDP上进行memcached侦听 [英] memcached listeing on UDP with Django
问题描述
问题:我无法通过 UDP
监听 memcached
来正常工作( get
使用Django>设置
删除
).
正如我在提及作为理由):
CACHES = {'默认': {'BACKEND':'django.core.cache.backends.memcached.MemcachedCache','LOCATION':'udp:127.0.0.1:11211',超时":无,}}
给予:
ValueError:无法解析连接字符串:"udp:localhost:11211"
2.设置 CACHES
以使用 pylibmc
Python绑定:
CACHES = {'默认': {'BACKEND':'django.core.cache.backends.memcached.PyLibMCCache','LOCATION':'udp:127.0.0.1:11211',超时":无,}}
服务器运行良好-可以进一步验证:
>>>进口django>>>从django.core.cache导入缓存>>>cache.set('udp_key',12)>>>cache.get('udp_key')追溯(最近一次通话):在< module>中,文件<控制台">第1行.在获得的文件"/usr/lib/python2.7/site-packages/django/core/cache/backends/memcached.py"中,第84行val = self._cache.get(key)NotSupportedError:来自memcached_get(:1:udp_key)的错误28:不支持操作
PS 不要在 TCP
与 UDP
辩论
一个类似的问题- get()set()memcached侦听使用Python的UDP
据我所了解的库 libmemcached pylibmc 使用的/a>不支持UDP的 get
操作./p>
我已经跟踪到 libmemcached 的文档确认了所有先前的事实. 使用 更新: python-memcached-udp 现在是一个pip包.它的管理器可以根据需要添加更多功能.如果您有兴趣,我们绝对可以为使用UDP的Memcached创建新的Django缓存后端. Question: I am not able to get I have the memcached listening only on 1.Setting gave: 2.Setting The server ran fine - to further verify:
P.S. Don't make it a memcached on A similar question - get() set() memcached listening on UDP using Python As far as I have been able to explore the library libmemcached that pylibmc uses does not support I have traced the cache call to that coincides with your error as pylibmc's I have install and configure the same environment in my own machine and I have got identical results. Nevertheless, the I have also tried to provide different locations ((PROTOCOL + IP + PORT)s separated by ; in the LOCATION field) for the cache mixing TCP/UDP, but the library DOES NOT SUPPORT mixing protocols either and returns an error. All the previous facts are confirmed by the documentation of libmemcached. The option of using UPDATE: python-memcached-udp is now a pip package. Its mantainer is open to add more features if needed. If you are interested we definitely could work on creating a new Django cache backend for Memcached with UDP. 这篇关于使用Django在UDP上进行memcached侦听的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! get
的缓存调用,直到 libmemcached
,并且发现 django.core.cache.backends.memcached.MemcachedCache
作为后端的选项也被丢弃,因为它仅使用TCP套接字( SOCK_STREAM
)进行连接内存缓存.memcached
listening on UDP
, to work (get
set
delete
) with Django.
UDP
11211
, as I have mentioned in the previous question. What I have tried so far:CACHES
to use python-memcached
Python binding. get and set didn't work with simple settings i.e. 'LOCATION': '127.0.0.1:11211'
, so tried specifying udp
explicitly (using this mention as the rationale):CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': 'udp:127.0.0.1:11211',
'TIMEOUT': None,
}
}
ValueError: Unable to parse connection string: "udp:localhost:11211"
CACHES
to use pylibmc
Python binding:CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.PyLibMCCache',
'LOCATION': 'udp:127.0.0.1:11211',
'TIMEOUT': None,
}
}
>>> import django
>>> from django.core.cache import cache
>>> cache.set('udp_key', 12)
>>> cache.get('udp_key')
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/django/core/cache/backends/memcached.py", line 84, in get
val = self._cache.get(key)
NotSupportedError: error 28 from memcached_get(:1:udp_key): ACTION NOT SUPPORTED
TCP
vs UDP
debate
get
operations with UDP.get
up to libmemcached
and I have found the following code: ...
if (memcached_is_udp(ptr))
{
return memcached_set_error(*ptr, MEMCACHED_NOT_SUPPORTED, MEMCACHED_AT);
}
...
get
method is mapped to libmemcached's memcached_get
method in the file with the code above (/libmemcached/get.cc
).set
operation seems to work perfectly as I have observed running memcached in debugging mode. CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.PyLibMCCache',
'LOCATION': 'udp:127.0.0.1:11211;127.0.0.1:11211',
'TIMEOUT': None,
}
}
django.core.cache.backends.memcached.MemcachedCache
as a backend is also discarded as it only uses TCP sockets (SOCK_STREAM
) for connecting to memcached.