1

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

Community
  • 1
  • 1
Nabeel Ahmed
  • 18,328
  • 4
  • 58
  • 63

0 Answers0