How to check when python-memcached server could not be connected

I was using python-memcached, and the process was going on even though the server I was connecting to was dead, so I was a little troubled.

Cause

memcache.py


    def _set(self, cmd, key, val, time, min_compress_len = 0):
        self.check_key(key)
        server, key = self._get_server(key)
        if not server:
            return 0

When set, 0 is returned even if there is no server.

memcache.py


    def _get(self, cmd, key):
        self.check_key(key)
        server, key = self._get_server(key)
        if not server:
            return None

None will come back even if you get it or there is no server.

With this, I don't know if the value is not actually set and it is None, or if there is no server and it is None.

Solution

I don't think this is correct, but it seemed to be identifiable, so for the time being.

client = memcache.Client(['192.168.1.1:11211'])
		
if len(client.get_stats()) == 0:
	raise Exception('Kestrel server not connected.')

The stats () function fetches each server status, but it doesn't seem to fetch it unless it's connected.

I thought it would be okay to set a value that shortened the lifespan and check if 0 was returned ... Isn't that better in terms of the number of server connections? w

If there is any good way, please teach everyone.

Recommended Posts

How to check when python-memcached server could not be connected
A command to check when something goes wrong when the server is not doing anything
How to not load images when using PhantomJS with Selenium
Check when the Docker container does not connect to the Internet
How to log with python (when No handlers could be found for logger "__main__" appears)
How doi may be useful when asking how to write code?
When I tried to use pip with python, I was told that XML_SetHashSalt could not be found.
How to not escape Japanese when dealing with json in python
A note on how to check the connection to the license server port
Settings to be made when starting up the linux server centos7
How to add sudo when debugging
How to check Linux OS version
Ignore soname when linking (could not)
What to do if you get "The session could not be opened" when installing CentOS on VirtualBox
How to check which is / dev / video ?? when multiple webcams are inserted
[Web server] A story when I investigated because I could not access nginx
How to build my own Linux server
How to check the version of Django
How to get IP when Tornado + nginx
How to set the server time to Japanese time
Could not update pip due to ssl
How to check opencv version in python
Tkinter could not be imported in Python
Be careful when adding an array to an array
[Note] QXcbConnection: Could not connect to display
Log when I was worried that I could not connect to Wi-Fi on Linux
What to do when "TypeError: must be string, not int…" appears when using strptime