get() set() memcached listening on UDP using Python

霸气de小男生 提交于 2019-12-11 11:20:26

问题


Question: How to get set, memcached listening on UDP only, using Python (any of the production level Python bindings)


What I have done/tried so far:

Making the memcached listen on UDP only - I specified the OPTIONS in memcached config:

OPTIONS="-p 0 -U 11211" # -U for UDP port and -p for TCP port

Verification:

# netstat -nlp|grep memcached
udp        0      0 0.0.0.0:11211           0.0.0.0:*                           12095/memcached     
udp6       0      0 :::11211                :::*                                12095/memcached 

The problem is, I didn't get to verify i.e. performing get and set or simply put I didn't get it to work.

I have looked into the Python memcache bindings- the 2 widely used ones (reliable, to be used in production) python-memcached and pylibmc. For python-memcached I didn't find any explicit mention for specifying UPD only or any check if the memcached is listening on TCP or UDP. For pylibmc, I though found a mention:

To specify UDP, the server address should be prefixed with "udp:", as in "udp:127.0.0.1"

To verify pylibmc:

>>> import pylibmc
>>> mc_tcp = pylibmc.Client(["127.0.0.1"], binary=True, behaviors={"tcp_nodelay": True, "ketama": True})
>>> mc_udp = pylibmc.Client(["udp:127.0.0.1"], binary=True, behaviors=None)
>>>
>>> mc_tcp.set('udp_key', 12)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
_pylibmc.ConnectionError: error 3 from memcached_set: CONNECTION FAILURE
>>>
>>> mc_udp.set('udp_key', 12)
True
>>>
>>> mc_udp.get('udp_key')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
_pylibmc.NotSupportedError: error 28 from memcached_get(udp_key): ACTION NOT SUPPORTED

To verify python-memcached:

>>> import memcache
>>> mc = memcache.Client([('127.0.0.1', 11211)])
>>> mc.set('key', 12)
0
>>> mc.get('key')
>>> 

A similar question - memcached listeing on UDP with Django

来源:https://stackoverflow.com/questions/36055900/get-set-memcached-listening-on-udp-using-python

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