Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions aiomcache/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ async def wrapper(self: _Client, *args: _P.args, # type: ignore[misc]


class FlagClient(Generic[_T]):
__slots__ = ("__weakref__", "_pool", "_get_flag_handler", "_set_flag_handler")
def __init__(self, host: str, port: int = 11211, *,
pool_size: int = 2, pool_minsize: Optional[int] = None,
conn_args: Optional[Mapping[str, Any]] = None,
Expand Down
27 changes: 23 additions & 4 deletions aiomcache/pool.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio
from typing import Any, Mapping, NamedTuple, Optional, Set

__all__ = ['MemcachePool']
__all__ = ["MemcachePool"]


class Connection(NamedTuple):
Expand All @@ -10,8 +10,26 @@ class Connection(NamedTuple):


class MemcachePool:
def __init__(self, host: str, port: int, *, minsize: int, maxsize: int,
conn_args: Optional[Mapping[str, Any]] = None):
__slots__ = (
"__weakref__",
"_host",
"_port",
"_minsize",
"_maxsize",
"conn_args",
"_pool",
"_in_use",
)

def __init__(
self,
host: str,
port: int,
*,
minsize: int,
maxsize: int,
conn_args: Optional[Mapping[str, Any]] = None,
):
self._host = host
self._port = port
self._minsize = minsize
Expand Down Expand Up @@ -68,7 +86,8 @@ def release(self, conn: Connection) -> None:
async def _create_new_conn(self) -> Optional[Connection]:
if self.size() < self._maxsize:
reader, writer = await asyncio.open_connection(
self._host, self._port, **self.conn_args)
self._host, self._port, **self.conn_args
)
if self.size() < self._maxsize:
return Connection(reader, writer)
else:
Expand Down
Loading