1:mod:`aioredis` --- API Reference
2=================================
3
4.. highlight:: python3
5.. module:: aioredis
6
7
8.. _aioredis-connection:
9
10Connection
11----------
12
13Redis Connection is the core function of the library.
14Connection instances can be used as is or through
15:ref:`pool<aioredis-pool>` or :ref:`high-level API<aioredis-redis>`.
16
17Connection usage is as simple as:
18
19.. code:: python
20
21   import asyncio
22   import aioredis
23
24   async def connect_uri():
25       conn = await aioredis.create_connection(
26           'redis://localhost/0')
27       val = await conn.execute('GET', 'my-key')
28
29   async def connect_tcp():
30       conn = await aioredis.create_connection(
31           ('localhost', 6379))
32       val = await conn.execute('GET', 'my-key')
33
34   async def connect_unixsocket():
35       conn = await aioredis.create_connection(
36           '/path/to/redis/socket')
37       # or uri 'unix:///path/to/redis/socket?db=1'
38       val = await conn.execute('GET', 'my-key')
39
40   asyncio.get_event_loop().run_until_complete(connect_tcp())
41   asyncio.get_event_loop().run_until_complete(connect_unixsocket())
42
43
44.. cofunction:: create_connection(address, \*, db=0, password=None, ssl=None,\
45                                  encoding=None, parser=None,\
46                                  timeout=None, connection_cls=None)
47
48   Creates Redis connection.
49
50   .. versionchanged:: v0.3.1
51      ``timeout`` argument added.
52
53   .. versionchanged:: v1.0
54      ``parser`` argument added.
55
56   .. deprecated:: v1.3.1
57      ``loop`` argument deprecated for Python 3.8 compatibility.
58
59   :param address: An address where to connect.
60      Can be one of the following:
61
62      * a Redis URI --- ``"redis://host:6379/0?encoding=utf-8"``;
63        ``"redis://:password@host:6379/0?encoding=utf-8"``;
64
65      * a (host, port) tuple --- ``('localhost', 6379)``;
66
67      * or a unix domain socket path string --- ``"/path/to/redis.sock"``.
68   :type address: tuple or str
69
70   :param int db: Redis database index to switch to when connected.
71
72   :param password: Password to use if redis server instance requires
73                    authorization.
74   :type password: str or None
75
76   :param ssl: SSL context that is passed through to
77               :func:`asyncio.BaseEventLoop.create_connection`.
78   :type ssl: :class:`ssl.SSLContext` or True or None
79
80   :param encoding: Codec to use for response decoding.
81   :type encoding: str or None
82
83   :param parser: Protocol parser class. Can be used to set custom protocol
84      reader; expected same interface as :class:`hiredis.Reader`.
85   :type parser: callable or None
86
87   :param timeout: Max time to open a connection, otherwise
88                   raise :exc:`asyncio.TimeoutError` exception.
89                   ``None`` by default
90   :type timeout: float greater than 0 or None
91
92   :param connection_cls: Custom connection class. ``None`` by default.
93   :type connection_cls: :class:`abc.AbcConnection` or None
94
95   :return: :class:`RedisConnection` instance.
96
97
98.. class:: RedisConnection
99
100   Bases: :class:`abc.AbcConnection`
101
102   Redis connection interface.
103
104   .. attribute:: address
105
106      Redis server address; either IP-port tuple or unix socket str (*read-only*).
107      IP is either IPv4 or IPv6 depending on resolved host part in initial address.
108
109      .. versionadded:: v0.2.8
110
111   .. attribute:: db
112
113      Current database index (*read-only*).
114
115   .. attribute:: encoding
116
117      Current codec for response decoding (*read-only*).
118
119   .. attribute:: closed
120
121      Set to ``True`` if connection is closed (*read-only*).
122
123   .. attribute:: in_transaction
124
125      Set to ``True`` when MULTI command was issued (*read-only*).
126
127   .. attribute:: pubsub_channels
128
129      *Read-only* dict with subscribed channels.
130      Keys are bytes, values are :class:`~aioredis.Channel` instances.
131
132   .. attribute:: pubsub_patterns
133
134      *Read-only* dict with subscribed patterns.
135      Keys are bytes, values are :class:`~aioredis.Channel` instances.
136
137   .. attribute:: in_pubsub
138
139      Indicates that connection is in PUB/SUB mode.
140      Provides the number of subscribed channels. *Read-only*.
141
142
143   .. method:: execute(command, \*args, encoding=_NOTSET)
144
145      Execute Redis command.
146
147      The method is **not a coroutine** itself but instead it
148      writes to underlying transport and returns a :class:`asyncio.Future`
149      waiting for result.
150
151      :param command: Command to execute
152      :type command: str, bytes, bytearray
153
154      :param encoding: Keyword-only argument for overriding response decoding.
155                       By default will use connection-wide encoding.
156                       May be set to None to skip response decoding.
157      :type encoding: str or None
158
159      :raise TypeError: When any of arguments is None or
160                        can not be encoded as bytes.
161      :raise aioredis.ReplyError: For redis error replies.
162      :raise aioredis.ProtocolError: When response can not be decoded
163                                     and/or connection is broken.
164
165      :return: Returns bytes or int reply (or str if encoding was set)
166
167
168   .. method:: execute_pubsub(command, \*channels_or_patterns)
169
170      Method to execute Pub/Sub commands.
171      The method is not a coroutine itself but returns a :func:`asyncio.gather()`
172      coroutine.
173      Method also accept :class:`aioredis.Channel` instances as command
174      arguments::
175
176         >>> ch1 = Channel('A', is_pattern=False)
177         >>> await conn.execute_pubsub('subscribe', ch1)
178         [[b'subscribe', b'A', 1]]
179
180      .. versionchanged:: v0.3
181         The method accept :class:`~aioredis.Channel` instances.
182
183      :param command: One of the following Pub/Sub commands:
184                      ``subscribe``, ``unsubscribe``,
185                      ``psubscribe``, ``punsubscribe``.
186      :type command: str, bytes, bytearray
187
188      :param \*channels_or_patterns: Channels or patterns to subscribe connection
189                                     to or unsubscribe from.
190                                     At least one channel/pattern is required.
191
192      :return: Returns a list of subscribe/unsubscribe messages,
193         ex::
194
195            >>> await conn.execute_pubsub('subscribe', 'A', 'B')
196            [[b'subscribe', b'A', 1], [b'subscribe', b'B', 2]]
197
198
199   .. method:: close()
200
201      Closes connection.
202
203      Mark connection as closed and schedule cleanup procedure.
204
205      All pending commands will be canceled with
206      :exc:`ConnectionForcedCloseError`.
207
208
209   .. method:: wait_closed()
210
211      Coroutine waiting for connection to get closed.
212
213
214   .. method:: select(db)
215
216      Changes current db index to new one.
217
218      :param int db: New redis database index.
219
220      :raise TypeError: When ``db`` parameter is not int.
221      :raise ValueError: When ``db`` parameter is less than 0.
222
223      :return True: Always returns True or raises exception.
224
225
226   .. method:: auth(password)
227
228      Send AUTH command.
229
230      :param str password: Plain-text password
231
232      :return bool: True if redis replied with 'OK'.
233
234
235----
236
237.. _aioredis-pool:
238
239Connections Pool
240----------------
241
242The library provides connections pool. The basic usage is as follows:
243
244.. code:: python
245
246   import aioredis
247
248   async def sample_pool():
249       pool = await aioredis.create_pool('redis://localhost')
250       val = await pool.execute('get', 'my-key')
251
252
253.. _aioredis-create_pool:
254
255.. function:: create_pool(address, \*, db=0, password=None, ssl=None, \
256                          encoding=None, minsize=1, maxsize=10, \
257                          parser=None, \
258                          create_connection_timeout=None, \
259                          pool_cls=None, connection_cls=None)
260
261   A :ref:`coroutine<coroutine>` that instantiates a pool of
262   :class:`~.RedisConnection`.
263
264   .. versionchanged:: v0.2.7
265      ``minsize`` default value changed from 10 to 1.
266
267   .. versionchanged:: v0.2.8
268      Disallow arbitrary ConnectionsPool maxsize.
269
270   .. deprecated:: v0.2.9
271      *commands_factory* argument is deprecated and will be removed in *v1.0*.
272
273   .. versionchanged:: v0.3.2
274      ``create_connection_timeout`` argument added.
275
276   .. versionchanged: v1.0
277      ``commands_factory`` argument has been dropped.
278
279   .. versionadded:: v1.0
280      ``parser``, ``pool_cls`` and ``connection_cls`` arguments added.
281
282   .. deprecated:: v1.3.1
283      ``loop`` argument deprecated for Python 3.8 compatibility.
284
285   :param address: An address where to connect.
286      Can be one of the following:
287
288      * a Redis URI --- ``"redis://host:6379/0?encoding=utf-8"``;
289
290      * a (host, port) tuple --- ``('localhost', 6379)``;
291
292      * or a unix domain socket path string --- ``"/path/to/redis.sock"``.
293   :type address: tuple or str
294
295   :param int db: Redis database index to switch to when connected.
296
297   :param password: Password to use if redis server instance requires
298                    authorization.
299   :type password: str or None
300
301   :param ssl: SSL context that is passed through to
302               :func:`asyncio.BaseEventLoop.create_connection`.
303   :type ssl: :class:`ssl.SSLContext` or True or None
304
305   :param encoding: Codec to use for response decoding.
306   :type encoding: str or None
307
308   :param int minsize: Minimum number of free connection to create in pool.
309                       ``1`` by default.
310
311   :param int maxsize: Maximum number of connection to keep in pool.
312                       ``10`` by default.
313                       Must be greater than ``0``. ``None`` is disallowed.
314
315   :param parser: Protocol parser class. Can be used to set custom protocol
316      reader; expected same interface as :class:`hiredis.Reader`.
317   :type parser: callable or None
318
319   :param create_connection_timeout: Max time to open a connection,
320      otherwise raise an :exc:`asyncio.TimeoutError`. ``None`` by default.
321   :type create_connection_timeout: float greater than 0 or None
322
323   :param pool_cls: Can be used to instantiate custom pool class.
324      This argument **must be** a subclass of :class:`~aioredis.abc.AbcPool`.
325   :type pool_cls: aioredis.abc.AbcPool
326
327   :param connection_cls: Can be used to make pool instantiate custom
328      connection classes. This argument **must be** a subclass of
329      :class:`~aioredis.abc.AbcConnection`.
330   :type connection_cls: aioredis.abc.AbcConnection
331
332   :return: :class:`ConnectionsPool` instance.
333
334
335.. class:: ConnectionsPool
336
337   Bases: :class:`abc.AbcPool`
338
339   Redis connections pool.
340
341   .. attribute:: minsize
342
343      A minimum size of the pool (*read-only*).
344
345   .. attribute:: maxsize
346
347      A maximum size of the pool (*read-only*).
348
349   .. attribute:: size
350
351      Current pool size --- number of free and used connections (*read-only*).
352
353   .. attribute:: freesize
354
355      Current number of free connections (*read-only*).
356
357   .. attribute:: db
358
359      Currently selected db index (*read-only*).
360
361   .. attribute:: encoding
362
363      Current codec for response decoding (*read-only*).
364
365   .. attribute:: closed
366
367      ``True`` if pool is closed.
368
369      .. versionadded:: v0.2.8
370
371   .. method:: execute(command, \*args, \**kwargs)
372
373      Execute Redis command in a free connection and return
374      :class:`asyncio.Future` waiting for result.
375
376      This method tries to pick a free connection from pool and send
377      command through it at once (keeping pipelining feature provided
378      by :meth:`aioredis.RedisConnection.execute`).
379      If no connection is found --- returns coroutine waiting for free
380      connection to execute command.
381
382      .. versionadded:: v1.0
383
384   .. method:: execute_pubsub(command, \*channels)
385
386      Execute Redis (p)subscribe/(p)unsubscribe command.
387
388      ``ConnectionsPool`` picks separate free connection for pub/sub
389      and uses it until pool is closed or connection is disconnected
390      (unsubscribing from all channels/pattern will leave connection
391      locked for pub/sub use).
392
393      There is no auto-reconnect for Pub/Sub connection as this will
394      hide from user messages loss.
395
396      Has similar to :meth:`execute` behavior, ie: tries to pick free
397      connection from pool and switch it to pub/sub mode; or fallback
398      to coroutine waiting for free connection and repeating operation.
399
400      .. versionadded:: v1.0
401
402   .. method:: get_connection(command, args=())
403
404      Gets free connection from pool returning tuple of (connection, address).
405
406      If no free connection is found -- None is returned in place of connection.
407
408      :rtype: tuple(:class:`RedisConnection` or None, str)
409
410      .. versionadded:: v1.0
411
412   .. comethod:: clear()
413
414      Closes and removes all free connections in the pool.
415
416   .. comethod:: select(db)
417
418      Changes db index for all free connections in the pool.
419
420      :param int db: New database index.
421
422   .. comethod:: acquire(command=None, args=())
423
424      Acquires a connection from *free pool*. Creates new connection if needed.
425
426      :param command: reserved for future.
427      :param args: reserved for future.
428      :raises aioredis.PoolClosedError: if pool is already closed
429
430   .. method:: release(conn)
431
432      Returns used connection back into pool.
433
434      When returned connection has db index that differs from one in pool
435      the connection will be dropped.
436      When queue of free connections is full the connection will be dropped.
437
438      .. note:: This method is **not a coroutine**.
439
440      :param aioredis.RedisConnection conn: A RedisConnection instance.
441
442   .. method:: close()
443
444      Close all free and in-progress connections and mark pool as closed.
445
446      .. versionadded:: v0.2.8
447
448   .. comethod:: wait_closed()
449
450      Wait until pool gets closed (when all connections are closed).
451
452      .. versionadded:: v0.2.8
453
454----
455
456.. _aioredis-exceptions:
457
458Exceptions
459----------
460
461.. exception:: RedisError
462
463   :Bases: :exc:`Exception`
464
465   Base exception class for aioredis exceptions.
466
467.. exception:: ProtocolError
468
469   :Bases: :exc:`RedisError`
470
471   Raised when protocol error occurs.
472   When this type of exception is raised connection must be considered
473   broken and must be closed.
474
475.. exception:: ReplyError
476
477   :Bases: :exc:`RedisError`
478
479   Raised for Redis :term:`error replies`.
480
481.. exception:: MaxClientsError
482
483   :Bases: :exc:`ReplyError`
484
485   Raised when maximum number of clients has been reached
486   (Redis server configured value).
487
488.. exception:: AuthError
489
490   :Bases: :exc:`ReplyError`
491
492   Raised when authentication errors occur.
493
494.. exception:: ConnectionClosedError
495
496   :Bases: :exc:`RedisError`
497
498   Raised if connection to server was lost/closed.
499
500.. exception:: ConnectionForcedCloseError
501
502   :Bases: :exc:`ConnectionClosedError`
503
504   Raised if connection was closed with :func:`RedisConnection.close` method.
505
506.. exception:: PipelineError
507
508   :Bases: :exc:`RedisError`
509
510   Raised from :meth:`~.commands.TransactionsCommandsMixin.pipeline`
511   if any pipelined command raised error.
512
513.. exception:: MultiExecError
514
515   :Bases: :exc:`PipelineError`
516
517   Same as :exc:`~.PipelineError` but raised when executing multi_exec
518   block.
519
520.. exception:: WatchVariableError
521
522   :Bases: :exc:`MultiExecError`
523
524   Raised if watched variable changed (EXEC returns None).
525   Subclass of :exc:`~.MultiExecError`.
526
527.. exception:: ChannelClosedError
528
529   :Bases: :exc:`RedisError`
530
531   Raised from :meth:`aioredis.Channel.get` when Pub/Sub channel is
532   unsubscribed and messages queue is empty.
533
534.. exception:: PoolClosedError
535
536   :Bases: :exc:`RedisError`
537
538   Raised from :meth:`aioredis.ConnectionsPool.acquire`
539   when pool is already closed.
540
541.. exception:: ReadOnlyError
542
543   :Bases: :exc:`RedisError`
544
545   Raised from slave when read-only mode is enabled.
546
547.. exception:: MasterNotFoundError
548
549   :Bases: :exc:`RedisError`
550
551   Raised by Sentinel client if it can not find requested master.
552
553.. exception:: SlaveNotFoundError
554
555   :Bases: :exc:`RedisError`
556
557   Raised by Sentinel client if it can not find requested slave.
558
559.. exception:: MasterReplyError
560
561   :Bases: :exc:`RedisError`
562
563   Raised if establishing connection to master failed with ``RedisError``,
564   for instance because of required or wrong authentication.
565
566.. exception:: SlaveReplyError
567
568   :Bases: :exc:`RedisError`
569
570   Raised if establishing connection to slave failed with ``RedisError``,
571   for instance because of required or wrong authentication.
572
573Exceptions Hierarchy
574~~~~~~~~~~~~~~~~~~~~
575
576.. code-block:: guess
577
578   Exception
579      RedisError
580         ProtocolError
581         ReplyError
582            MaxClientsError
583            AuthError
584         PipelineError
585            MultiExecError
586               WatchVariableError
587         ChannelClosedError
588         ConnectionClosedError
589            ConnectionForcedCloseError
590         PoolClosedError
591         ReadOnlyError
592         MasterNotFoundError
593         SlaveNotFoundError
594         MasterReplyError
595         SlaveReplyError
596
597
598----
599
600.. _aioredis-channel:
601
602Pub/Sub Channel object
603----------------------
604
605`Channel` object is a wrapper around queue for storing received pub/sub messages.
606
607
608.. class:: Channel(name, is_pattern)
609
610   Bases: :class:`abc.AbcChannel`
611
612   Object representing Pub/Sub messages queue.
613   It's basically a wrapper around :class:`asyncio.Queue`.
614
615   .. attribute:: name
616
617      Holds encoded channel/pattern name.
618
619   .. attribute:: is_pattern
620
621      Set to True for pattern channels.
622
623   .. attribute:: is_active
624
625      Set to True if there are messages in queue and connection is still
626      subscribed to this channel.
627
628   .. comethod:: get(\*, encoding=None, decoder=None)
629
630      Coroutine that waits for and returns a message.
631
632      Return value is message received or ``None`` signifying that channel has
633      been unsubscribed and no more messages will be received.
634
635      :param str encoding: If not None used to decode resulting bytes message.
636
637      :param callable decoder: If specified used to decode message,
638                               ex. :func:`json.loads()`
639
640      :raise aioredis.ChannelClosedError: If channel is unsubscribed and
641                                          has no more messages.
642
643   .. method:: get_json(\*, encoding="utf-8")
644
645      Shortcut to ``get(encoding="utf-8", decoder=json.loads)``
646
647   .. comethod:: wait_message()
648
649      Waits for message to become available in channel
650      or channel is closed (unsubscribed).
651
652      Main idea is to use it in loops:
653
654      >>> ch = redis.channels['channel:1']
655      >>> while await ch.wait_message():
656      ...     msg = await ch.get()
657
658      :rtype: bool
659
660   .. comethod:: iter(, \*, encoding=None, decoder=None)
661      :async-for:
662      :coroutine:
663
664      Same as :meth:`~.get` method but it is a native coroutine.
665
666      Usage example::
667
668         >>> async for msg in ch.iter():
669         ...     print(msg)
670
671      .. versionadded:: 0.2.5
672         Available for Python 3.5 only
673
674
675----
676
677.. _aioredis-redis:
678
679Commands Interface
680------------------
681
682The library provides high-level API implementing simple interface
683to Redis commands.
684
685The usage is as simple as:
686
687.. code:: python
688
689   import aioredis
690
691   # Create Redis client bound to single non-reconnecting connection.
692   async def single_connection():
693      redis = await aioredis.create_redis(
694         'redis://localhost')
695      val = await redis.get('my-key')
696
697   # Create Redis client bound to connections pool.
698   async def pool_of_connections():
699      redis = await aioredis.create_redis_pool(
700         'redis://localhost')
701      val = await redis.get('my-key')
702
703      # we can also use pub/sub as underlying pool
704      #  has several free connections:
705      ch1, ch2 = await redis.subscribe('chan:1', 'chan:2')
706      # publish using free connection
707      await redis.publish('chan:1', 'Hello')
708      await ch1.get()
709
710For commands reference ---
711see :ref:`commands mixins reference <aioredis-commands>`.
712
713
714.. cofunction:: create_redis(address, \*, db=0, password=None, ssl=None,\
715                             encoding=None, commands_factory=Redis,\
716                             parser=None, timeout=None,\
717                             connection_cls=None)
718
719   This :ref:`coroutine<coroutine>` creates high-level Redis
720   interface instance bound to single Redis connection
721   (without auto-reconnect).
722
723   .. versionadded:: v1.0
724      ``parser``, ``timeout`` and ``connection_cls`` arguments added.
725
726   .. deprecated:: v1.3.1
727      ``loop`` argument deprecated for Python 3.8 compatibility.
728
729   See also :class:`~aioredis.RedisConnection` for parameters description.
730
731   :param address: An address where to connect. Can be a (host, port) tuple,
732                   unix domain socket path string or a Redis URI string.
733   :type address: tuple or str
734
735   :param int db: Redis database index to switch to when connected.
736
737   :param password: Password to use if Redis server instance requires
738                    authorization.
739   :type password: str or bytes or None
740
741   :param ssl: SSL context that is passed through to
742               :func:`asyncio.BaseEventLoop.create_connection`.
743   :type ssl: :class:`ssl.SSLContext` or True or None
744
745   :param encoding: Codec to use for response decoding.
746   :type encoding: str or None
747
748   :param commands_factory: A factory accepting single parameter --
749    object implementing :class:`~abc.AbcConnection`
750    and returning an instance providing
751    high-level interface to Redis. :class:`Redis` by default.
752   :type commands_factory: callable
753
754   :param parser: Protocol parser class. Can be used to set custom protocol
755      reader; expected same interface as :class:`hiredis.Reader`.
756   :type parser: callable or None
757
758   :param timeout: Max time to open a connection, otherwise
759                   raise :exc:`asyncio.TimeoutError` exception.
760                   ``None`` by default
761   :type timeout: float greater than 0 or None
762
763   :param connection_cls: Can be used to instantiate custom
764      connection class. This argument **must be** a subclass of
765      :class:`~aioredis.abc.AbcConnection`.
766   :type connection_cls: aioredis.abc.AbcConnection
767
768   :returns: Redis client (result of ``commands_factory`` call),
769             :class:`Redis` by default.
770
771
772.. cofunction:: create_redis_pool(address, \*, db=0, password=None, ssl=None,\
773                                  encoding=None, commands_factory=Redis,\
774                                  minsize=1, maxsize=10,\
775                                  parser=None, timeout=None,\
776                                  pool_cls=None, connection_cls=None,\
777                                  )
778
779   This :ref:`coroutine<coroutine>` create high-level Redis client instance
780   bound to connections pool (this allows auto-reconnect and simple pub/sub
781   use).
782
783   See also :class:`~aioredis.ConnectionsPool` for parameters description.
784
785   .. versionchanged:: v1.0
786      ``parser``, ``timeout``, ``pool_cls`` and ``connection_cls``
787      arguments added.
788
789   .. deprecated:: v1.3.1
790      ``loop`` argument deprecated for Python 3.8 compatibility.
791
792   :param address: An address where to connect. Can be a (host, port) tuple,
793                   unix domain socket path string or a Redis URI string.
794   :type address: tuple or str
795
796   :param int db: Redis database index to switch to when connected.
797   :param password: Password to use if Redis server instance requires
798                    authorization.
799   :type password: str or bytes or None
800
801   :param ssl: SSL context that is passed through to
802               :func:`asyncio.BaseEventLoop.create_connection`.
803   :type ssl: :class:`ssl.SSLContext` or True or None
804
805   :param encoding: Codec to use for response decoding.
806   :type encoding: str or None
807
808   :param commands_factory: A factory accepting single parameter --
809    object implementing :class:`~abc.AbcConnection` interface
810    and returning an instance providing
811    high-level interface to Redis. :class:`Redis` by default.
812   :type commands_factory: callable
813
814   :param int minsize: Minimum number of connections to initialize
815                       and keep in pool. Default is 1.
816
817   :param int maxsize: Maximum number of connections that can be created
818                       in pool. Default is 10.
819
820   :param parser: Protocol parser class. Can be used to set custom protocol
821      reader; expected same interface as :class:`hiredis.Reader`.
822   :type parser: callable or None
823
824   :param timeout: Max time to open a connection, otherwise
825                   raise :exc:`asyncio.TimeoutError` exception.
826                   ``None`` by default
827   :type timeout: float greater than 0 or None
828
829   :param pool_cls: Can be used to instantiate custom pool class.
830      This argument **must be** a subclass of :class:`~aioredis.abc.AbcPool`.
831   :type pool_cls: aioredis.abc.AbcPool
832
833   :param connection_cls: Can be used to make pool instantiate custom
834      connection classes. This argument **must be** a subclass of
835      :class:`~aioredis.abc.AbcConnection`.
836   :type connection_cls: aioredis.abc.AbcConnection
837
838   :returns: Redis client (result of ``commands_factory`` call),
839             :class:`Redis` by default.
840