[Python-modules-commits] [aioredis] 01/07: Import aioredis_0.2.9.orig.tar.gz
Piotr Ożarowski
piotr at moszumanska.debian.org
Wed Dec 21 11:31:34 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 691f91885156c05310613eb8780e1ae12777e5e9
Author: Piotr Ożarowski <piotr at debian.org>
Date: Sat Nov 5 19:32:21 2016 +0100
Import aioredis_0.2.9.orig.tar.gz
---
CHANGES.txt | 26 +
MANIFEST.in | 5 +-
PKG-INFO | 32 +-
README.rst | 4 +-
aioredis.egg-info/PKG-INFO | 32 +-
aioredis.egg-info/SOURCES.txt | 51 +-
aioredis/__init__.py | 2 +-
aioredis/commands/generic.py | 11 +-
aioredis/commands/pubsub.py | 5 +-
aioredis/commands/server.py | 21 +-
aioredis/pool.py | 28 +-
docs/_build/man/aioredis.1 | 4047 ++++++++++++++++++++++++++++++++
docs/api_reference.rst | 541 +++++
docs/devel.rst | 232 ++
docs/examples.rst | 57 +
docs/glossary.rst | 37 +
docs/index.rst | 83 +
docs/mixins.rst | 227 ++
docs/releases.rst | 15 +
docs/start.rst | 163 ++
examples/commands.py | 22 +
examples/connection.py | 30 +
examples/pipeline.py | 50 +
examples/pool.py | 24 +
examples/pool_pubsub.py | 71 +
examples/pubsub.py | 37 +
examples/pubsub2.py | 59 +
examples/python_3.5_iscan.py | 52 +
examples/python_3.5_pool.py | 33 +
examples/scan.py | 28 +
examples/transaction.py | 26 +
examples/transaction2.py | 25 +
tests/_testutil.old.py | 251 ++
tests/coerced_keys_dict_test.py | 55 +
tests/conftest.py | 413 ++++
tests/connection_commands_test.py | 64 +
tests/connection_test.py | 367 +++
tests/encode_command_test.py | 55 +
tests/generic_commands_test.py | 602 +++++
tests/hash_commands_test.py | 432 ++++
tests/hyperloglog_commands_test.py | 102 +
tests/list_commands_test.py | 559 +++++
tests/multi_exec_test.py | 44 +
tests/pool_test.py | 411 ++++
tests/pubsub_commands_test.py | 265 +++
tests/py35_generic_commands_test.py | 46 +
tests/py35_hash_commands_test.py | 53 +
tests/py35_pool_test.py | 23 +
tests/py35_pubsub_commands_test.py | 23 +
tests/py35_set_commands_test.py | 49 +
tests/py35_sorted_set_commands_test.py | 42 +
tests/reconnect_test.py | 40 +
tests/scripting_commands_test.py | 126 +
tests/server_commands_test.py | 184 ++
tests/set_commands_test.py | 435 ++++
tests/sorted_set_commands_test.py | 627 +++++
tests/ssl_test.py | 32 +
tests/string_commands_test.py | 680 ++++++
tests/task_cancellation_test.py | 21 +
tests/transaction_commands_test.py | 241 ++
60 files changed, 12288 insertions(+), 30 deletions(-)
diff --git a/CHANGES.txt b/CHANGES.txt
index 2603b12..da3585b 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,6 +1,32 @@
Changes
-------
+0.2.9 (2016-10-24)
+^^^^^^^^^^^^^^^^^^
+
+**NEW**:
+
+* Allow multiple keys in ``EXISTS`` command
+ (see `#156 <https://github.com/aio-libs/aioredis/issues/156>`_
+ and `#157 <https://github.com/aio-libs/aioredis/issues/157>`_);
+
+**FIX**:
+
+* Close RedisPool when connection to Redis failed
+ (see `#136 <https://github.com/aio-libs/aioredis/issues/136>`_);
+
+* Add simple ``INFO`` command argument validation
+ (see `#140 <https://github.com/aio-libs/aioredis/issues/140>`_);
+
+* Remove invalid uses of ``next()``
+
+**MISC**:
+
+* Update devel.rst docs; update Pub/Sub Channel docs (cross-refs);
+
+* Update MANIFEST.in to include docs, examples and tests in source bundle;
+
+
0.2.8 (2016-07-22)
^^^^^^^^^^^^^^^^^^
diff --git a/MANIFEST.in b/MANIFEST.in
index 9da63a6..9ac614a 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -3,4 +3,7 @@ include CHANGES.txt
include README.rst
graft aioredis
global-exclude *.pyc *.swp
-
+recursive-include examples *.py
+recursive-include tests *.py
+recursive-include docs *.rst
+include docs/_build/man/*.*
diff --git a/PKG-INFO b/PKG-INFO
index da57b8a..8a7b751 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: aioredis
-Version: 0.2.8
+Version: 0.2.9
Summary: asyncio (PEP 3156) Redis support
Home-page: https://github.com/aio-libs/aioredis
Author: Alexey Popravka
@@ -15,8 +15,8 @@ Description: aioredis
:target: https://travis-ci.org/aio-libs/aioredis
- .. image:: https://coveralls.io/repos/aio-libs/aioredis/badge.svg?branch=master&service=github
- :target: https://coveralls.io/github/aio-libs/aioredis?branch=master
+ .. image:: https://codecov.io/gh/aio-libs/aioredis/branch/master/graph/badge.svg
+ :target: https://codecov.io/gh/aio-libs/aioredis
Features
--------
@@ -139,6 +139,32 @@ Description: aioredis
Changes
-------
+ 0.2.9 (2016-10-24)
+ ^^^^^^^^^^^^^^^^^^
+
+ **NEW**:
+
+ * Allow multiple keys in ``EXISTS`` command
+ (see `#156 <https://github.com/aio-libs/aioredis/issues/156>`_
+ and `#157 <https://github.com/aio-libs/aioredis/issues/157>`_);
+
+ **FIX**:
+
+ * Close RedisPool when connection to Redis failed
+ (see `#136 <https://github.com/aio-libs/aioredis/issues/136>`_);
+
+ * Add simple ``INFO`` command argument validation
+ (see `#140 <https://github.com/aio-libs/aioredis/issues/140>`_);
+
+ * Remove invalid uses of ``next()``
+
+ **MISC**:
+
+ * Update devel.rst docs; update Pub/Sub Channel docs (cross-refs);
+
+ * Update MANIFEST.in to include docs, examples and tests in source bundle;
+
+
0.2.8 (2016-07-22)
^^^^^^^^^^^^^^^^^^
diff --git a/README.rst b/README.rst
index 0003bc9..1e58d9d 100644
--- a/README.rst
+++ b/README.rst
@@ -7,8 +7,8 @@ asyncio (PEP 3156) Redis client library.
:target: https://travis-ci.org/aio-libs/aioredis
-.. image:: https://coveralls.io/repos/aio-libs/aioredis/badge.svg?branch=master&service=github
- :target: https://coveralls.io/github/aio-libs/aioredis?branch=master
+.. image:: https://codecov.io/gh/aio-libs/aioredis/branch/master/graph/badge.svg
+ :target: https://codecov.io/gh/aio-libs/aioredis
Features
--------
diff --git a/aioredis.egg-info/PKG-INFO b/aioredis.egg-info/PKG-INFO
index da57b8a..8a7b751 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.8
+Version: 0.2.9
Summary: asyncio (PEP 3156) Redis support
Home-page: https://github.com/aio-libs/aioredis
Author: Alexey Popravka
@@ -15,8 +15,8 @@ Description: aioredis
:target: https://travis-ci.org/aio-libs/aioredis
- .. image:: https://coveralls.io/repos/aio-libs/aioredis/badge.svg?branch=master&service=github
- :target: https://coveralls.io/github/aio-libs/aioredis?branch=master
+ .. image:: https://codecov.io/gh/aio-libs/aioredis/branch/master/graph/badge.svg
+ :target: https://codecov.io/gh/aio-libs/aioredis
Features
--------
@@ -139,6 +139,32 @@ Description: aioredis
Changes
-------
+ 0.2.9 (2016-10-24)
+ ^^^^^^^^^^^^^^^^^^
+
+ **NEW**:
+
+ * Allow multiple keys in ``EXISTS`` command
+ (see `#156 <https://github.com/aio-libs/aioredis/issues/156>`_
+ and `#157 <https://github.com/aio-libs/aioredis/issues/157>`_);
+
+ **FIX**:
+
+ * Close RedisPool when connection to Redis failed
+ (see `#136 <https://github.com/aio-libs/aioredis/issues/136>`_);
+
+ * Add simple ``INFO`` command argument validation
+ (see `#140 <https://github.com/aio-libs/aioredis/issues/140>`_);
+
+ * Remove invalid uses of ``next()``
+
+ **MISC**:
+
+ * Update devel.rst docs; update Pub/Sub Channel docs (cross-refs);
+
+ * Update MANIFEST.in to include docs, examples and tests in source bundle;
+
+
0.2.8 (2016-07-22)
^^^^^^^^^^^^^^^^^^
diff --git a/aioredis.egg-info/SOURCES.txt b/aioredis.egg-info/SOURCES.txt
index 6fbeeda..3638233 100644
--- a/aioredis.egg-info/SOURCES.txt
+++ b/aioredis.egg-info/SOURCES.txt
@@ -27,4 +27,53 @@ aioredis/commands/server.py
aioredis/commands/set.py
aioredis/commands/sorted_set.py
aioredis/commands/string.py
-aioredis/commands/transaction.py
\ No newline at end of file
+aioredis/commands/transaction.py
+docs/api_reference.rst
+docs/devel.rst
+docs/examples.rst
+docs/glossary.rst
+docs/index.rst
+docs/mixins.rst
+docs/releases.rst
+docs/start.rst
+docs/_build/man/aioredis.1
+examples/commands.py
+examples/connection.py
+examples/pipeline.py
+examples/pool.py
+examples/pool_pubsub.py
+examples/pubsub.py
+examples/pubsub2.py
+examples/python_3.5_iscan.py
+examples/python_3.5_pool.py
+examples/scan.py
+examples/transaction.py
+examples/transaction2.py
+tests/_testutil.old.py
+tests/coerced_keys_dict_test.py
+tests/conftest.py
+tests/connection_commands_test.py
+tests/connection_test.py
+tests/encode_command_test.py
+tests/generic_commands_test.py
+tests/hash_commands_test.py
+tests/hyperloglog_commands_test.py
+tests/list_commands_test.py
+tests/multi_exec_test.py
+tests/pool_test.py
+tests/pubsub_commands_test.py
+tests/py35_generic_commands_test.py
+tests/py35_hash_commands_test.py
+tests/py35_pool_test.py
+tests/py35_pubsub_commands_test.py
+tests/py35_set_commands_test.py
+tests/py35_sorted_set_commands_test.py
+tests/reconnect_test.py
+tests/scripting_commands_test.py
+tests/server_commands_test.py
+tests/set_commands_test.py
+tests/sorted_set_commands_test.py
+tests/ssl_test.py
+tests/string_commands_test.py
+tests/task_cancellation_test.py
+tests/transaction_commands_test.py
\ No newline at end of file
diff --git a/aioredis/__init__.py b/aioredis/__init__.py
index 5de2dae..1581059 100644
--- a/aioredis/__init__.py
+++ b/aioredis/__init__.py
@@ -15,7 +15,7 @@ from .errors import (
)
-__version__ = '0.2.8'
+__version__ = '0.2.9'
# make pyflakes happy
(create_connection, RedisConnection,
diff --git a/aioredis/commands/generic.py b/aioredis/commands/generic.py
index 55a9d9f..9c2b24b 100644
--- a/aioredis/commands/generic.py
+++ b/aioredis/commands/generic.py
@@ -19,10 +19,13 @@ class GenericCommandsMixin:
"""Dump a key."""
return self._conn.execute(b'DUMP', key)
- def exists(self, key):
- """Check if key exists."""
- fut = self._conn.execute(b'EXISTS', key)
- return wait_convert(fut, bool)
+ def exists(self, key, *keys):
+ """Check if key(s) exists.
+
+ .. versionchanged:: v0.2.9
+ Accept multiple keys; **return** type **changed** from bool to int.
+ """
+ return self._conn.execute(b'EXISTS', key, *keys)
def expire(self, key, timeout):
"""Set a timeout on key.
diff --git a/aioredis/commands/pubsub.py b/aioredis/commands/pubsub.py
index de3bbef..eab214b 100644
--- a/aioredis/commands/pubsub.py
+++ b/aioredis/commands/pubsub.py
@@ -23,7 +23,7 @@ class PubSubCommandsMixin:
subscribe to specified channels.
Returns :func:`asyncio.gather()` coroutine which when done will return
- a list of subscribed channels.
+ a list of :class:`~aioredis.Channel` objects.
"""
conn = self._conn
return wait_return_channels(
@@ -39,7 +39,8 @@ class PubSubCommandsMixin:
subscribe to specified patterns.
Returns :func:`asyncio.gather()` coroutine which when done will return
- a list of subscribed patterns.
+ a list of subscribed :class:`~aioredis.Channel` objects with
+ ``is_pattern`` property set to ``True``.
"""
conn = self._conn
return wait_return_channels(
diff --git a/aioredis/commands/server.py b/aioredis/commands/server.py
index 60af361..ff48544 100644
--- a/aioredis/commands/server.py
+++ b/aioredis/commands/server.py
@@ -112,9 +112,17 @@ class ServerCommandsMixin:
fut = self._conn.execute('FLUSHDB')
return wait_ok(fut)
- def info(self, section):
- """Get information and statistics about the server."""
- # TODO: check section
+ def info(self, section='default'):
+ """Get information and statistics about the server.
+
+ If called without argument will return default set of sections.
+ For available sections, see http://redis.io/commands/INFO
+
+ :raises ValueError: if section is invalid
+
+ """
+ if not section:
+ raise ValueError("invalid section")
fut = self._conn.execute(b'INFO', section, encoding='utf-8')
return wait_convert(fut, parse_info)
@@ -211,8 +219,7 @@ def to_time(obj):
def to_tuples(value):
- lines = iter(value.splitlines(False))
- line = next(lines)
+ line, *lines = value.splitlines(False)
line = list(map(_split, line.split(' ')))
ClientInfo = namedtuple('ClientInfo', ' '.join(k for k, v in line))
# TODO: parse flags and other known fields
@@ -225,8 +232,8 @@ def to_tuples(value):
def parse_info(info):
res = {}
for block in info.split('\r\n\r\n'):
- block = iter(block.strip().splitlines())
- section = next(block)[2:].lower()
+ section, *block = block.strip().splitlines()
+ section = section[2:].lower()
res[section] = tmp = {}
for line in block:
key, value = line.split(':')
diff --git a/aioredis/pool.py b/aioredis/pool.py
index 7da89ee..63be438 100644
--- a/aioredis/pool.py
+++ b/aioredis/pool.py
@@ -1,10 +1,11 @@
import asyncio
import collections
import sys
+import warnings
from .commands import create_redis, Redis
from .log import logger
-from .util import async_task
+from .util import async_task, _NOTSET
from .errors import PoolClosedError
@@ -13,23 +14,37 @@ PY_35 = sys.version_info >= (3, 5)
@asyncio.coroutine
def create_pool(address, *, db=0, password=None, ssl=None, encoding=None,
- minsize=1, maxsize=10, commands_factory=Redis, loop=None):
+ minsize=1, maxsize=10, commands_factory=_NOTSET, loop=None):
"""Creates Redis Pool.
- By default it creates pool of commands_factory instances, but it is
+ By default it creates pool of Redis instances, but it is
also possible to create pool of plain connections by passing
``lambda conn: conn`` as commands_factory.
+ *commands_factory* parameter is deprecated since v0.2.9
+
All arguments are the same as for create_connection.
Returns RedisPool instance.
"""
+ if commands_factory is not _NOTSET:
+ warnings.warn(
+ "commands_factory argument is deprecated and will be removed!",
+ warnings.DeprecationWarning)
+ else:
+ commands_factory = Redis
pool = RedisPool(address, db, password, encoding,
minsize=minsize, maxsize=maxsize,
commands_factory=commands_factory,
ssl=ssl, loop=loop)
- yield from pool._fill_free(override_min=False)
+ try:
+ yield from pool._fill_free(override_min=False)
+ except Exception as ex:
+ pool.close()
+ yield from pool.wait_closed()
+ raise
+
return pool
@@ -111,6 +126,7 @@ class RedisPool:
conn.close()
waiters.append(conn.wait_closed())
yield from asyncio.gather(*waiters, loop=self._loop)
+ logger.debug("Closed %d connections", len(waiters))
def close(self):
"""Close all free and in-progress connections and mark pool as closed.
@@ -220,7 +236,7 @@ class RedisPool:
self._pool.append(conn)
finally:
self._acquiring -= 1
- # connection may be closed at yeild point
+ # connection may be closed at yield point
self._drop_closed()
if self.freesize:
return
@@ -232,7 +248,7 @@ class RedisPool:
self._pool.append(conn)
finally:
self._acquiring -= 1
- # connection may be closed at yeild point
+ # connection may be closed at yield point
self._drop_closed()
def _create_new_connection(self):
diff --git a/docs/_build/man/aioredis.1 b/docs/_build/man/aioredis.1
new file mode 100644
index 0000000..7e5afb3
--- /dev/null
+++ b/docs/_build/man/aioredis.1
@@ -0,0 +1,4047 @@
+.\" Man page generated from reStructuredText.
+.
+.TH "AIOREDIS" "1" "Oct 24, 2016" "0.2" "aioredis"
+.SH NAME
+aioredis \- aioredis Documentation
+.
+.nr rst2man-indent-level 0
+.
+.de1 rstReportMargin
+\\$1 \\n[an-margin]
+level \\n[rst2man-indent-level]
+level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
+-
+\\n[rst2man-indent0]
+\\n[rst2man-indent1]
+\\n[rst2man-indent2]
+..
+.de1 INDENT
+.\" .rstReportMargin pre:
+. RS \\$1
+. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
+. nr rst2man-indent-level +1
+.\" .rstReportMargin post:
+..
+.de UNINDENT
+. RE
+.\" indent \\n[an-margin]
+.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
+.nr rst2man-indent-level -1
+.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
+.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
+..
+.sp
+asyncio (\fI\%PEP 3156\fP) Redis client library.
+.sp
+The library is intended to provide simple and clear interface to Redis
+based on asyncio\&.
+.SH FEATURES
+.TS
+center;
+|l|l|.
+_
+T{
+hiredis parser
+T} T{
+Yes
+T}
+_
+T{
+Pure\-python parser
+T} T{
+TBD
+T}
+_
+T{
+Low\-level & High\-level APIs
+T} T{
+Yes
+T}
+_
+T{
+Connections Pool
+T} T{
+Yes
+T}
+_
+T{
+Pipelining support
+T} T{
+Yes
+T}
+_
+T{
+Pub/Sub support
+T} T{
+Yes
+T}
+_
+T{
+Redis Cluster support
+T} T{
+WIP
+T}
+_
+T{
+Trollius (python 2.7)
+T} T{
+No
+T}
+_
+T{
+Tested python versions
+T} T{
+\fI\%3.3, 3.4, 3.5\fP
+T}
+_
+T{
+Tested for Redis server
+T} T{
+\fI\%2.6, 2.8, 3.0\fP
+T}
+_
+T{
+Support for dev Redis server
+T} T{
+through low\-level API
+T}
+_
+.TE
+.SH INSTALLATION
+.sp
+The easiest way to install aioredis is by using the package on PyPi:
+.INDENT 0.0
+.INDENT 3.5
+.sp
+.nf
+.ft C
+pip install aioredis
+.ft P
+.fi
+.UNINDENT
+.UNINDENT
+.SH REQUIREMENTS
+.INDENT 0.0
+.IP \(bu 2
+Python 3.3 and asyncio or Python 3.4+
+.IP \(bu 2
+hiredis
+.UNINDENT
+.SH CONTRIBUTE
+.INDENT 0.0
+.IP \(bu 2
+Issue Tracker: \fI\%https://github.com/aio\-libs/aioredis/issues\fP
+.IP \(bu 2
+Source Code: \fI\%https://github.com/aio\-libs/aioredis\fP
+.UNINDENT
+.sp
+Feel free to file an issue or make pull request if you find any bugs or have
+some suggestions for library improvement.
+.SH LICENSE
+.sp
+The aioredis is offered under \fI\%MIT license\fP\&.
+
+.sp
+.ce
+----
+
+.ce 0
+.sp
+.SH GETTING STARTED
+.SS Commands Pipelining
+.sp
+Commands pipelining is built\-in.
+.sp
+Every command is sent to transport at\-once
+(ofcourse if no TypeErrors/ValueErrors were raised)
+.sp
+When you making a call with \fByield from\fP you will be waiting result,
+but if you want to make several calls simply collect futures of those calls
+and then gather results.
+.sp
+Simple example show both cases (\fBget source code\fP):
+.INDENT 0.0
+.INDENT 3.5
+.sp
+.nf
+.ft C
+# No pipelining;
+ at asyncio.coroutine
+def wait_each_command():
+ val = yield from redis.get(\(aqfoo\(aq) # wait until \(gaval\(ga is available
+ cnt = yield from redis.incr(\(aqbar\(aq) # wait until \(gacnt\(ga is available
+ return val, cnt
+
+# Sending multiple commands and then gathering results
+ at asyncio.coroutine
+def pipelined():
+ fut1 = redis.get(\(aqfoo\(aq) # issue command and return future
+ fut2 = redis.incr(\(aqbar\(aq) # issue command and return future
+ # block until results are available
+ val, cnt = yield from asyncio.gather(fut1, fut2)
+ return val, cnt
+
+.ft P
+.fi
+.UNINDENT
+.UNINDENT
+.sp
+\fBNOTE:\fP
+.INDENT 0.0
+.INDENT 3.5
+As as convenience \fBaioredis\fP provides
+\fBpipeline()\fP
+method allowing to execute bulk of commands at once
+(\fBget source code\fP):
+.INDENT 0.0
+.INDENT 3.5
+.INDENT 0.0
+.INDENT 3.5
+.sp
+.nf
+.ft C
+# Convenient way
+ at asyncio.coroutine
+def convenience_way():
+ pipe = redis.pipeline()
+ fut1 = pipe.get(\(aqfoo\(aq)
+ fut2 = pipe.incr(\(aqbar\(aq)
+ result = yield from pipe.execute()
+ val, cnt = yield from asyncio.gather(fut1, fut2)
+ assert result == [val, cnt]
+ return val, cnt
+
+.ft P
+.fi
+.UNINDENT
+.UNINDENT
+.UNINDENT
+.UNINDENT
+.UNINDENT
+.UNINDENT
+.SS Multi/Exec transactions
+.sp
+\fBaioredis\fP provides several ways for executing transactions:
+.INDENT 0.0
+.IP \(bu 2
+when using raw connection you can issue \(aqMulti\(aq/\(aqExec\(aq commands
+manually;
+.IP \(bu 2
+when using \fBaioredis.Redis\fP instance you can either use
+\fBmulti()\fP/
+\fBexec()\fP methods
+.IP \(bu 2
+or use \fBmulti_exec()\fP transaction pipeline.
+.UNINDENT
+.sp
+The later one is described in more details.
+.sp
+\fBmulti_exec()\fP method creates and returns new
+\fBMultiExec\fP object which is used for buffering commands and
+then executing them inside MULTI/EXEC block.
+.sp
+Here is simple example
+(\fBget source code\fP):
+.INDENT 0.0
+.INDENT 3.5
+.sp
+.nf
+.ft C
+ at asyncio.coroutine
+def transaction():
+ tr = redis.multi_exec()
+ future1 = tr.set(\(aqfoo\(aq, \(aq123\(aq)
+ future2 = tr.set(\(aqbar\(aq, \(aq321\(aq)
+ result = yield from tr.execute()
+ assert result == (yield from asyncio.gather(future1, future2))
+ return result
+
+.ft P
+.fi
+.UNINDENT
+.UNINDENT
+.sp
+As you can notice \fByield from\fP is \fBonly\fP used at line 6 with \fBtr.execute\fP
+and \fBnot with\fP \fBtr.set(...)\fP calls.
+.sp
+\fBWARNING:\fP
+.INDENT 0.0
+.INDENT 3.5
+It is very important not to \fByield from\fP buffered command
+(ie \fBtr.set(\(aqfoo\(aq, \(aq123\(aq)\fP) as it will block forever.
+.sp
+The following code will block forever:
+.INDENT 0.0
+.INDENT 3.5
+.sp
+.nf
+.ft C
+tr = redis.multi_exec()
+yield from tr.incr(\(aqfoo\(aq) # that\(aqs all. we\(aqve stuck!
+.ft P
+.fi
+.UNINDENT
+.UNINDENT
+.UNINDENT
+.UNINDENT
+.SS Pub/Sub mode
+.sp
+\fBaioredis\fP provides support for Redis Publish/Subscribe messaging.
+.sp
+To switch connection to subscribe mode you must execute \fBsubscribe\fP command
+by yield\(aqing from \fBsubscribe()\fP it returns a list of
+\fBChannel\fP objects representing subscribed channels.
+.sp
+As soon as connection is switched to subscribed mode the channel will receive
+and store messages
+(the \fBChannel\fP object is basically a wrapper around \fI\%asyncio.Queue\fP).
+To read messages from channel you need to use \fBget()\fP
+or \fBget_json()\fP coroutines.
+.sp
+\fBNOTE:\fP
+.INDENT 0.0
+.INDENT 3.5
+In Pub/Sub mode redis connection can only receive messages or issue
+(P)SUBSCRIBE / (P)UNSUBSCRIBE commands.
+.UNINDENT
+.UNINDENT
+.sp
+Pub/Sub example (\fBget source code\fP):
+.INDENT 0.0
+.INDENT 3.5
+.sp
+.nf
+.ft C
+sub = yield from aioredis.create_redis(
+ (\(aqlocalhost\(aq, 6379))
+
+ch1, ch2 = yield from sub.subscribe(\(aqchannel:1\(aq, \(aqchannel:2\(aq)
+assert isinstance(ch1, aioredis.Channel)
+assert isinstance(ch2, aioredis.Channel)
+
+ at asyncio.coroutine
+def async_reader(channel):
+ while (yield from channel.wait_message()):
+ msg = yield from channel.get(encoding=\(aqutf\-8\(aq)
+ # ... process message ...
+ print("message in {}: {}".format(channel.name, msg))
+
+tsk1 = asyncio.async(async_reader(ch1))
+
+# Or alternatively:
+
+ at asyncio.coroutine
+def async_reader2(channel):
+ while True:
+ msg = yield from channel.get(encoding=\(aqutf\-8\(aq)
+ if msg is None:
+ break
+ # ... process message ...
+ print("message in {}: {}".format(channel.name, msg))
+
+tsk2 = asyncio.async(async_reader2(ch2))
+
+.ft P
+.fi
+.UNINDENT
+.UNINDENT
+.sp
+\fBWARNING:\fP
+.INDENT 0.0
+.INDENT 3.5
+Using Pub/Sub mode with \fBPool\fP is possible but
+only within \fBwith\fP block or by explicitly \fBacquiring/releasing\fP
+connection. See example below.
+.UNINDENT
+.UNINDENT
+.sp
+Pub/Sub example (\fBget source code\fP):
+.INDENT 0.0
+.INDENT 3.5
+.sp
+.nf
+.ft C
+ at asyncio.coroutine
+def reader(channel):
+ while (yield from channel.wait_message()):
+ msg = yield from channel.get(encoding=\(aqutf\-8\(aq)
+ # ... process message ...
+ print("message in {}: {}".format(channel.name, msg))
+
+ if msg == STOPWORD:
+ return
+
+with (yield from pool) as redis:
+ channel, = yield from redis.subscribe(\(aqchannel:1\(aq)
+ yield from reader(channel) # wait for reader to complete
+ yield from redis.unsubscribe(\(aqchannel:1\(aq)
+
+# Explicit redis usage
+redis = yield from pool.acquire()
+try:
+ channel, = yield from redis.subscribe(\(aqchannel:1\(aq)
+ yield from reader(channel) # wait for reader to complete
+ yield from redis.unsubscribe(\(aqchannel:1\(aq)
+finally:
+ pool.release(redis)
+
+.ft P
+.fi
+.UNINDENT
+.UNINDENT
+.SS Python 3.5 async/await support
+.sp
+\fBaioredis\fP is compatible with \fI\%PEP 492\fP\&.
+.sp
+\fBPool\fP can be used with \fI\%async with\fP
+(\fBget source code\fP):
+.INDENT 0.0
+.INDENT 3.5
+.sp
+.nf
+.ft C
+
+pool = await aioredis.create_pool(
+ (\(aqlocalhost\(aq, 6379))
+async with pool.get() as conn:
+ value = await conn.get(\(aqmy\-key\(aq)
+ print(\(aqraw value:\(aq, value)
+
+.ft P
+.fi
+.UNINDENT
+.UNINDENT
+.sp
+It also can be used with \fBawait\fP:
+.INDENT 0.0
+.INDENT 3.5
+.sp
+.nf
+.ft C
+
+pool = await aioredis.create_pool(
+ (\(aqlocalhost\(aq, 6379))
+with (await pool) as conn:
+ value = await conn.get(\(aqmy\-key\(aq)
+ print(\(aqraw value:\(aq, value)
+
+.ft P
+.fi
+.UNINDENT
+.UNINDENT
+.sp
+New \fBscan\fP\-family commands added with support of \fI\%async for\fP
+(\fBget source code\fP):
+.INDENT 0.0
+.INDENT 3.5
+.sp
+.nf
+.ft C
+redis = await aioredis.create_redis(
+ (\(aqlocalhost\(aq, 6379))
+
+async for key in redis.iscan(match=\(aqsomething*\(aq):
+ print(\(aqMatched:\(aq, key)
+
+async for name, val in redis.ihscan(key, match=\(aqsomething*\(aq):
+ print(\(aqMatched:\(aq, name, \(aq\->\(aq, val)
+
+async for val in redis.isscan(key, match=\(aqsomething*\(aq):
+ print(\(aqMatched:\(aq, val)
+
+async for val, score in redis.izscan(key, match=\(aqsomething*\(aq):
+ print(\(aqMatched:\(aq, val, \(aq:\(aq, score)
+
+.ft P
+.fi
+.UNINDENT
+.UNINDENT
+.SS SSL/TLS support
+.sp
+Though Redis server \fI\%does not support data encryption\fP
+it is still possible to setup Redis server behind SSL proxy. For such cases
+\fBaioredis\fP library support secure connections through \fI\%asyncio\fP
+SSL support. See \fI\%BaseEventLoop.create_connection\fP for details.
+.SH AIOREDIS --- API REFERENCE
+.SS Connection
+.sp
+Redis Connection is the core function of the library.
+Connection instances can be used as is or through
+\fI\%pool\fP or \fI\%high\-level API\fP\&.
+.sp
+Connection usage is as simple as:
+.INDENT 0.0
+.INDENT 3.5
+.sp
+.nf
+.ft C
+import asyncio
+import aioredis
+
+ at asyncio.coroutine
+def connection_example():
+ conn = yield from aioredis\&.create_connection(
+ (\(aqlocalhost\(aq, 6379))
+ # connecting to socket
+ # conn = yiled from aioredis.create_connection(
+ # \(aq/path/to/redis/socket\(aq)
+ val = yield from conn\&.execute(\(aqGET\(aq, \(aqmy\-key\(aq)
+
+asyncio\&.get_event_loop()\&.run_until_complete(connection_example())
+.ft P
+.fi
+.UNINDENT
+.UNINDENT
+.INDENT 0.0
+.TP
+.B coroutine aioredis.create_connection(address, *, db=0, password=None, ssl=None, encoding=None, loop=None)
+Creates Redis connection.
+.INDENT 7.0
+.TP
... 11889 lines suppressed ...
--
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