diff --git a/aiomcache/client.py b/aiomcache/client.py index bf1f011..d67f98e 100644 --- a/aiomcache/client.py +++ b/aiomcache/client.py @@ -28,13 +28,10 @@ def wrapper(self, *args, **kwargs): class Client(object): - - def __init__(self, host, port=11211, *, - pool_size=2, pool_minsize=None, loop=None): + def __init__(self, host='127.0.0.1', port=11211, *, pool_size=2, pool_minsize=None, loop=None, unix='/tmp/memcached.sock'): if not pool_minsize: pool_minsize = pool_size - self._pool = MemcachePool( - host, port, minsize=pool_minsize, maxsize=pool_size, loop=loop) + self._pool = MemcachePool(host, port, minsize=pool_minsize, maxsize=pool_size, loop=loop, unix=unix) # key supports ascii sans space and control chars # \x21 is !, right after space, and \x7e is -, right before DEL diff --git a/aiomcache/pool.py b/aiomcache/pool.py index f672ead..fb03e60 100644 --- a/aiomcache/pool.py +++ b/aiomcache/pool.py @@ -1,4 +1,5 @@ import asyncio +import os.path from collections import namedtuple __all__ = ['MemcachePool'] @@ -9,7 +10,7 @@ class MemcachePool: - def __init__(self, host, port, *, minsize, maxsize, loop=None): + def __init__(self, host, port, *, minsize, maxsize, loop=None, unix=None): loop = loop if loop is not None else asyncio.get_event_loop() self._host = host self._port = port @@ -18,6 +19,7 @@ def __init__(self, host, port, *, minsize, maxsize, loop=None): self._loop = loop self._pool = asyncio.Queue(loop=loop) self._in_use = set() + self._unix = unix @asyncio.coroutine def clear(self): @@ -69,8 +71,11 @@ def release(self, conn): @asyncio.coroutine def _create_new_conn(self): if self.size() < self._maxsize: - reader, writer = yield from asyncio.open_connection( - self._host, self._port, loop=self._loop) + if isinstance(self._unix, str) and os.path.exists(self._unix): + reader, writer = yield from asyncio.open_unix_connection(path=self._unix, loop=self._loop) + else: + reader, writer = yield from asyncio.open_connection(self._host, self._port, loop=self._loop) + if self.size() < self._maxsize: return _connection(reader, writer) else: