def main(): # Create client instance and connect to memcached server = ('localhost', 11211) client = Client(server) client.connect() # Set value result = client.set('testkey', 'testvalue') print(result) # Get value result = client.get('testkey') print(result)
def _get_client(self): with self._lock: if self._free_clients: # Get first free client from queue client = self._free_clients.pop() self._used_clients.append(client) return client # Check if max_clients limit has been reached if len(self._used_clients) >= self._max_clients: raise DriverConnectionLimitExceededException( "Open clients limit reached. Cannot create more clients") # Create new client and use it log.debug("Creating new client") client = Client(self.server) if not client.connect(): raise DriverConnectionException("Failed to connect to server") self._used_clients.append(client) return client