Error changing memcached

I am trying to catch an error in memcached when this does not work with python:

import memcache import socket mc = memcache.Client(['127.0.0.1:11211'], debug=1) try: print mc.get('gfdsgf') except socket.error: print 'error' 

But I still have this error in my console:

 MemCached: MemCache: inet:127.0.0.1:11211: connect: Connection refused. Marking dead. None 
+4
source share
1 answer

this is actually not a bug that you can catch, it is just a log and it is displayed because your debug parameter is 1, so turn off the debug parameter. And, as you can see, you still have None from your print, which means that your key does not exist.

Try something like this:

 import memcache mc = memcache.Client(['127.0.0.1:11211'], debug=0) try: print mc.get('gfdsgf') except (mc.MemcachedKeyTypeError, mc.MemcachedKeyNoneError, TypeError, mc.MemcachedKeyCharacterError, mc.MemcachedKeyError, mc.MemcachedKeyLengthError, mc.MemcachedStringEncodingError): print 'error' 
+2
source

Source: https://habr.com/ru/post/1495575/


All Articles