memcached listeing on UDP with Django

左心房为你撑大大i 提交于 2019-12-06 11:18:11

As far as I have been able to explore the library libmemcached that pylibmc uses does not support get operations with UDP.

I have traced the cache call to 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);
    }
    ...

that coincides with your error as pylibmc's get method is mapped to libmemcached's memcached_get method in the file with the code above (/libmemcached/get.cc).

I have install and configure the same environment in my own machine and I have got identical results.

Nevertheless, the set operation seems to work perfectly as I have observed running memcached in debugging mode.

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.

    CACHES = {
        'default': {
            'BACKEND': 'django.core.cache.backends.memcached.PyLibMCCache',
            'LOCATION': 'udp:127.0.0.1:11211;127.0.0.1:11211',
            'TIMEOUT': None,
        }
    }

All the previous facts are confirmed by the documentation of libmemcached.

The option of using django.core.cache.backends.memcached.MemcachedCache as a backend is also discarded as it only uses TCP sockets (SOCK_STREAM) for connecting to memcached.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!