def _fetch_memcached_stats(self):
"""Connect to Memcached and retrieve stats."""
data = bytes()
with socket.create_connection((self.config['host'],
self.config['port']),
timeout=self.config['timeout']) as s:
s.sendall(b'stats\r\n')
while True:
buffer = bytearray(4096)
bytes_received = s.recv_into(buffer)
if bytes_received == 0:
# Remote host closed connection
break
data += buffer
if b'\r\nEND\r\n' in data:
# End of the stats command
break
return data
评论列表
文章目录