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.
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.
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