ConnectionPool

connection_pool.py
 1import typing
 2from zcached import Result, ZCached, Connection, ConnectionPool
 3
 4
 5def main():
 6    connection_pool = ConnectionPool(
 7        # Connections in the pool. If we do not send a large number of requests, we can use only one.
 8        pool_size=1,
 9        # Some function that does not take any arguments, but returns the created connection.
10        connection_factory=lambda: Connection(host="127.0.0.1", port=7556),
11    )
12
13    client: ZCached = ZCached.from_connection_pool(connection_pool)
14    client.run()
15
16    response: Result[typing.List[str]] = client.keys()
17    if response.error:
18        raise RuntimeError(response.error)
19
20    print(response.value)
21
22
23if __name__ == "__main__":
24    main()