[Python-modules-commits] [aioredis] 08/11: Import aioredis_0.2.8.orig.tar.gz

Piotr Ożarowski piotr at moszumanska.debian.org
Sat Jul 30 15:27:56 UTC 2016


This is an automated email from the git hooks/post-receive script.

piotr pushed a commit to branch master
in repository aioredis.

commit d3b97f11b3c84fc534593d55f596416a31ffc029
Author: Piotr Ożarowski <piotr at debian.org>
Date:   Sat Jul 30 17:20:48 2016 +0200

    Import aioredis_0.2.8.orig.tar.gz
---
 CHANGES.txt                     | 33 +++++++++++++++++++++++++-
 PKG-INFO                        | 35 +++++++++++++++++++++++++--
 aioredis.egg-info/PKG-INFO      | 35 +++++++++++++++++++++++++--
 aioredis/__init__.py            |  4 +++-
 aioredis/commands/generic.py    |  4 ++--
 aioredis/commands/hash.py       | 52 +++++++++++++++++++++++++++++++++++++++--
 aioredis/commands/sorted_set.py |  2 +-
 aioredis/connection.py          | 16 +++++++++++--
 aioredis/errors.py              |  8 +++++--
 aioredis/pool.py                | 45 +++++++++++++++++++++++++++++++++++
 10 files changed, 219 insertions(+), 15 deletions(-)

diff --git a/CHANGES.txt b/CHANGES.txt
index 77f4b05..2603b12 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,6 +1,37 @@
 Changes
 -------
 
+0.2.8 (2016-07-22)
+^^^^^^^^^^^^^^^^^^
+
+**NEW**:
+
+* Add ``hmset_dict`` command
+  (see `#130 <https://github.com/aio-libs/aioredis/issues/130>`_);
+
+* Add ``RedisConnection.address`` property;
+
+* RedisPool ``minsize``/``maxsize`` must not be ``None``;
+
+* Implement ``close()``/``wait_closed()``/``closed`` interface for pool
+  (see `#128 <https://github.com/aio-libs/aioredis/issues/128>`_);
+
+**FIX**:
+
+* Add test for ``hstrlen``;
+
+* Test fixes
+
+**MISC**:
+
+* Enable Redis 3.2.0 on Travis;
+
+* Add spell checking when building docs
+  (see `#132 <https://github.com/aio-libs/aioredis/issues/132>`_);
+
+* Documentation updated;
+
+
 0.2.7 (2016-05-27)
 ^^^^^^^^^^^^^^^^^^
 
@@ -9,7 +40,7 @@ Changes
 * Fixed cancellation of wait_closed
   (see `#118 <https://github.com/aio-libs/aioredis/issues/118>`_);
 
-* Fixed ``time()`` covertion to float
+* Fixed ``time()`` convertion to float
   (see `#126 <https://github.com/aio-libs/aioredis/issues/126>`_);
 
 * Fixed ``hmset()`` method to return bool instead of ``b'OK'``
diff --git a/PKG-INFO b/PKG-INFO
index 469f8b2..da57b8a 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: aioredis
-Version: 0.2.7
+Version: 0.2.8
 Summary: asyncio (PEP 3156) Redis support
 Home-page: https://github.com/aio-libs/aioredis
 Author: Alexey Popravka
@@ -139,6 +139,37 @@ Description: aioredis
         Changes
         -------
         
+        0.2.8 (2016-07-22)
+        ^^^^^^^^^^^^^^^^^^
+        
+        **NEW**:
+        
+        * Add ``hmset_dict`` command
+          (see `#130 <https://github.com/aio-libs/aioredis/issues/130>`_);
+        
+        * Add ``RedisConnection.address`` property;
+        
+        * RedisPool ``minsize``/``maxsize`` must not be ``None``;
+        
+        * Implement ``close()``/``wait_closed()``/``closed`` interface for pool
+          (see `#128 <https://github.com/aio-libs/aioredis/issues/128>`_);
+        
+        **FIX**:
+        
+        * Add test for ``hstrlen``;
+        
+        * Test fixes
+        
+        **MISC**:
+        
+        * Enable Redis 3.2.0 on Travis;
+        
+        * Add spell checking when building docs
+          (see `#132 <https://github.com/aio-libs/aioredis/issues/132>`_);
+        
+        * Documentation updated;
+        
+        
         0.2.7 (2016-05-27)
         ^^^^^^^^^^^^^^^^^^
         
@@ -147,7 +178,7 @@ Description: aioredis
         * Fixed cancellation of wait_closed
           (see `#118 <https://github.com/aio-libs/aioredis/issues/118>`_);
         
-        * Fixed ``time()`` covertion to float
+        * Fixed ``time()`` convertion to float
           (see `#126 <https://github.com/aio-libs/aioredis/issues/126>`_);
         
         * Fixed ``hmset()`` method to return bool instead of ``b'OK'``
diff --git a/aioredis.egg-info/PKG-INFO b/aioredis.egg-info/PKG-INFO
index 469f8b2..da57b8a 100644
--- a/aioredis.egg-info/PKG-INFO
+++ b/aioredis.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: aioredis
-Version: 0.2.7
+Version: 0.2.8
 Summary: asyncio (PEP 3156) Redis support
 Home-page: https://github.com/aio-libs/aioredis
 Author: Alexey Popravka
@@ -139,6 +139,37 @@ Description: aioredis
         Changes
         -------
         
+        0.2.8 (2016-07-22)
+        ^^^^^^^^^^^^^^^^^^
+        
+        **NEW**:
+        
+        * Add ``hmset_dict`` command
+          (see `#130 <https://github.com/aio-libs/aioredis/issues/130>`_);
+        
+        * Add ``RedisConnection.address`` property;
+        
+        * RedisPool ``minsize``/``maxsize`` must not be ``None``;
+        
+        * Implement ``close()``/``wait_closed()``/``closed`` interface for pool
+          (see `#128 <https://github.com/aio-libs/aioredis/issues/128>`_);
+        
+        **FIX**:
+        
+        * Add test for ``hstrlen``;
+        
+        * Test fixes
+        
+        **MISC**:
+        
+        * Enable Redis 3.2.0 on Travis;
+        
+        * Add spell checking when building docs
+          (see `#132 <https://github.com/aio-libs/aioredis/issues/132>`_);
+        
+        * Documentation updated;
+        
+        
         0.2.7 (2016-05-27)
         ^^^^^^^^^^^^^^^^^^
         
@@ -147,7 +178,7 @@ Description: aioredis
         * Fixed cancellation of wait_closed
           (see `#118 <https://github.com/aio-libs/aioredis/issues/118>`_);
         
-        * Fixed ``time()`` covertion to float
+        * Fixed ``time()`` convertion to float
           (see `#126 <https://github.com/aio-libs/aioredis/issues/126>`_);
         
         * Fixed ``hmset()`` method to return bool instead of ``b'OK'``
diff --git a/aioredis/__init__.py b/aioredis/__init__.py
index 05d2e9c..5de2dae 100644
--- a/aioredis/__init__.py
+++ b/aioredis/__init__.py
@@ -11,10 +11,11 @@ from .errors import (
     ReplyError,
     ChannelClosedError,
     WatchVariableError,
+    PoolClosedError,
     )
 
 
-__version__ = '0.2.7'
+__version__ = '0.2.8'
 
 # make pyflakes happy
 (create_connection, RedisConnection,
@@ -23,4 +24,5 @@ __version__ = '0.2.7'
  RedisError, ProtocolError, ReplyError,
  PipelineError, MultiExecError, ConnectionClosedError,
  ChannelClosedError, WatchVariableError,
+ PoolClosedError,
  )
diff --git a/aioredis/commands/generic.py b/aioredis/commands/generic.py
index 466f628..55a9d9f 100644
--- a/aioredis/commands/generic.py
+++ b/aioredis/commands/generic.py
@@ -27,7 +27,7 @@ class GenericCommandsMixin:
     def expire(self, key, timeout):
         """Set a timeout on key.
 
-        if timeout is float it will be multiplyed by 1000
+        if timeout is float it will be multiplied by 1000
         coerced to int and passed to `pexpire` method.
 
         Otherwise raises TypeError if timeout argument is not int.
@@ -43,7 +43,7 @@ class GenericCommandsMixin:
     def expireat(self, key, timestamp):
         """Set expire timestamp on key.
 
-        if timeout is float it will be multiplyed by 1000
+        if timeout is float it will be multiplied by 1000
         coerced to int and passed to `pexpire` method.
 
         Otherwise raises TypeError if timestamp argument is not int.
diff --git a/aioredis/commands/hash.py b/aioredis/commands/hash.py
index 47f08a8..30e25aa 100644
--- a/aioredis/commands/hash.py
+++ b/aioredis/commands/hash.py
@@ -1,4 +1,12 @@
-from aioredis.util import wait_ok, wait_convert, wait_make_dict, _NOTSET, PY_35
+from itertools import chain
+
+from aioredis.util import (
+    wait_ok,
+    wait_convert,
+    wait_make_dict,
+    _NOTSET,
+    PY_35,
+    )
 
 if PY_35:
     from aioredis.util import _ScanIterPairs
@@ -50,13 +58,53 @@ class HashCommandsMixin:
         return self._conn.execute(b'HMGET', key, field, *fields,
                                   encoding=encoding)
 
-    # TODO: replace args with dict_or_pairs
     def hmset(self, key, field, value, *pairs):
         """Set multiple hash fields to multiple values."""
         if len(pairs) % 2 != 0:
             raise TypeError("length of pairs must be even number")
         return wait_ok(self._conn.execute(b'HMSET', key, field, value, *pairs))
 
+    def hmset_dict(self, key, *args, **kwargs):
+        """Set multiple hash fields to multiple values.
+
+        dict can be passed as first positional argument:
+
+        >>> yield from redis.hmset_dict(
+        ...     'key', {'field1': 'value1', 'field2': 'value2'})
+
+        or keyword arguments can be used:
+
+        >>> yield from redis.hmset_dict(
+        ...     'key', field1='value1', field2='value2')
+
+        or dict argument can be mixed with kwargs:
+
+        >>> yield from redis.hmset_dict(
+        ...     'key', {'field1': 'value1'}, field2='value2')
+
+        .. note:: ``dict`` and ``kwargs`` not get mixed into single dictionary,
+           if both specified and both have same key(s) -- ``kwargs`` will win:
+
+           >>> yield from redis.hmset_dict('key', {'foo': 'bar'}, foo='baz')
+           >>> yield from redis.hget('key', 'foo', encoding='utf-8')
+           'baz'
+
+        """
+        if not args and not kwargs:
+            raise TypeError("args or kwargs must be specified")
+        pairs = ()
+        if len(args) > 1:
+            raise TypeError("single positional argument allowed")
+        elif len(args) == 1:
+            if not isinstance(args[0], dict):
+                raise TypeError("args[0] must be dict")
+            elif not args[0] and not kwargs:
+                raise ValueError("args[0] is empty dict")
+            pairs = chain.from_iterable(args[0].items())
+        kwargs_pairs = chain.from_iterable(kwargs.items())
+        return wait_ok(self._conn.execute(
+            b'HMSET', key, *chain(pairs, kwargs_pairs)))
+
     def hset(self, key, field, value):
         """Set the string value of a hash field."""
         return self._conn.execute(b'HSET', key, field, value)
diff --git a/aioredis/commands/sorted_set.py b/aioredis/commands/sorted_set.py
index 2b70692..5b364e1 100644
--- a/aioredis/commands/sorted_set.py
+++ b/aioredis/commands/sorted_set.py
@@ -168,7 +168,7 @@ class SortedSetCommandsMixin:
     def zrangebyscore(self, key, min=float('-inf'), max=float('inf'),
                       withscores=False, offset=None, count=None,
                       *, exclude=None):
-        """Return a range of memebers in a sorted set, by score.
+        """Return a range of members in a sorted set, by score.
 
         :raises TypeError: if min or max is not float or int
         :raises TypeError: if both offset and count are not specified
diff --git a/aioredis/connection.py b/aioredis/connection.py
index cd30b63..09aa3e1 100644
--- a/aioredis/connection.py
+++ b/aioredis/connection.py
@@ -70,11 +70,17 @@ def create_connection(address, *, db=None, password=None, ssl=None,
         sock = writer.transport.get_extra_info('socket')
         if sock is not None:
             sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
+            address = sock.getpeername()
+        address = tuple(address[:2])
     else:
         logger.debug("Creating unix connection to %r", address)
         reader, writer = yield from asyncio.open_unix_connection(
             address, ssl=ssl, loop=loop)
-    conn = RedisConnection(reader, writer, encoding=encoding, loop=loop)
+        sock = writer.transport.get_extra_info('socket')
+        if sock is not None:
+            address = sock.getpeername()
+    conn = RedisConnection(reader, writer, encoding=encoding,
+                           address=address, loop=loop)
 
     try:
         if password is not None:
@@ -91,11 +97,12 @@ def create_connection(address, *, db=None, password=None, ssl=None,
 class RedisConnection:
     """Redis connection."""
 
-    def __init__(self, reader, writer, *, encoding=None, loop=None):
+    def __init__(self, reader, writer, *, address, encoding=None, loop=None):
         if loop is None:
             loop = asyncio.get_event_loop()
         self._reader = reader
         self._writer = writer
+        self._address = address
         self._loop = loop
         self._waiters = deque()
         self._parser = hiredis.Reader(protocolError=ProtocolError,
@@ -325,6 +332,11 @@ class RedisConnection:
         """Current set codec or None."""
         return self._encoding
 
+    @property
+    def address(self):
+        """Redis server address, either host-port tuple or str."""
+        return self._address
+
     def select(self, db):
         """Change the selected database for the current connection."""
         if not isinstance(db, int):
diff --git a/aioredis/errors.py b/aioredis/errors.py
index 41dfea1..f435200 100644
--- a/aioredis/errors.py
+++ b/aioredis/errors.py
@@ -7,6 +7,7 @@ __all__ = [
     'WatchVariableError',
     'ChannelClosedError',
     'ConnectionClosedError',
+    'PoolClosedError',
     ]
 
 
@@ -43,5 +44,8 @@ class ChannelClosedError(RedisError):
 
 
 class ConnectionClosedError(RedisError):
-    """Raised if connection to server was closed.
-    """
+    """Raised if connection to server was closed."""
+
+
+class PoolClosedError(RedisError):
+    """Raised if pool is closed."""
diff --git a/aioredis/pool.py b/aioredis/pool.py
index 7217f7b..7da89ee 100644
--- a/aioredis/pool.py
+++ b/aioredis/pool.py
@@ -5,6 +5,7 @@ import sys
 from .commands import create_redis, Redis
 from .log import logger
 from .util import async_task
+from .errors import PoolClosedError
 
 
 PY_35 = sys.version_info >= (3, 5)
@@ -38,6 +39,13 @@ class RedisPool:
 
     def __init__(self, address, db=0, password=None, encoding=None,
                  *, minsize, maxsize, commands_factory, ssl=None, loop=None):
+        assert isinstance(minsize, int) and minsize >= 0, (
+            "minsize must be int >= 0", minsize, type(minsize))
+        assert maxsize is not None, "Arbitrary pool size is disallowed."
+        assert isinstance(maxsize, int) and maxsize > 0, (
+            "maxsize must be int > 0", maxsize, type(maxsize))
+        assert minsize <= maxsize, (
+            "Invalid pool min/max sizes", minsize, maxsize)
         if loop is None:
             loop = asyncio.get_event_loop()
         self._address = address
@@ -52,6 +60,8 @@ class RedisPool:
         self._used = set()
         self._acquiring = 0
         self._cond = asyncio.Condition(loop=loop)
+        self._close_state = asyncio.Event(loop=loop)
+        self._close_waiter = async_task(self._do_close(), loop=loop)
 
     @property
     def minsize(self):
@@ -87,6 +97,37 @@ class RedisPool:
                 waiters.append(conn.wait_closed())
             yield from asyncio.gather(*waiters, loop=self._loop)
 
+    @asyncio.coroutine
+    def _do_close(self):
+        yield from self._close_state.wait()
+        with (yield from self._cond):
+            assert not self._acquiring, self._acquiring
+            waiters = []
+            while self._pool:
+                conn = self._pool.popleft()
+                conn.close()
+                waiters.append(conn.wait_closed())
+            for conn in self._used:
+                conn.close()
+                waiters.append(conn.wait_closed())
+            yield from asyncio.gather(*waiters, loop=self._loop)
+
+    def close(self):
+        """Close all free and in-progress connections and mark pool as closed.
+        """
+        if not self._close_state.is_set():
+            self._close_state.set()
+
+    @property
+    def closed(self):
+        """True if pool is closed."""
+        return self._close_state.is_set()
+
+    @asyncio.coroutine
+    def wait_closed(self):
+        """Wait until pool gets closed."""
+        yield from asyncio.shield(self._close_waiter, loop=self._loop)
+
     @property
     def db(self):
         """Currently selected db index."""
@@ -115,7 +156,11 @@ class RedisPool:
 
         Creates new connection if needed.
         """
+        if self.closed:
+            raise PoolClosedError("Pool is closed")
         with (yield from self._cond):
+            if self.closed:
+                raise PoolClosedError("Pool is closed")
             while True:
                 yield from self._fill_free(override_min=True)
                 if self.freesize:

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/aioredis.git



More information about the Python-modules-commits mailing list