# Path: aredis/client.py
# class StrictRedis(*mixins):
#     """
#     Implementation of the Redis protocol.
# 
#     This abstract class provides a Python interface to all Redis commands
#     and an implementation of the Redis protocol.
# 
#     Connection and Pipeline derive from this, implementing how
#     the commands are sent and received to the Redis server
#     """
# 
#     RESPONSE_CALLBACKS = dict_merge(*[mixin.RESPONSE_CALLBACKS for mixin in mixins])
# 
#     @classmethod
#     def from_url(cls, url, db=None, **kwargs):
#         """
#         Return a Redis client object configured from the given URL, which must
#         use either `the ``redis://`` scheme
#         <http://www.iana.org/assignments/uri-schemes/prov/redis>`_ for RESP
#         connections or the ``unix://`` scheme for Unix domain sockets.
# 
#         For example:
# 
#         redis://[:password]@localhost:6379/0
#         unix://[:password]@/path/to/socket.sock?db=0
# 
#         There are several ways to specify a database number. The parse function
#         will return the first specified option:
#         1. A ``db`` querystring option, e.g. redis://localhost?db=0
#         2. If using the redis:// scheme, the path argument of the url, e.g.
#         redis://localhost/0
#         3. The ``db`` argument to this function.
# 
#         If none of these options are specified, db=0 is used.
# 
#         Any additional querystring arguments and keyword arguments will be
#         passed along to the ConnectionPool class's initializer. In the case
#         of conflicting arguments, querystring arguments always win.
#         """
#         connection_pool = ConnectionPool.from_url(url, db=db, **kwargs)
#         return cls(connection_pool=connection_pool)
# 
#     def __init__(self, host='localhost', port=6379,
#                  db=0, password=None, stream_timeout=None,
#                  connect_timeout=None, connection_pool=None,
#                  unix_socket_path=None, encoding='utf-8',
#                  decode_responses=False, ssl=False, ssl_context=None,
#                  ssl_keyfile=None, ssl_certfile=None,
#                  ssl_cert_reqs=None, ssl_ca_certs=None,
#                  max_connections=None, retry_on_timeout=False,
#                  max_idle_time=0, idle_check_interval=1,
#                  loop=None, **kwargs):
#         if not connection_pool:
#             kwargs = {
#                 'db': db,
#                 'password': password,
#                 'encoding': encoding,
#                 'stream_timeout': stream_timeout,
#                 'connect_timeout': connect_timeout,
#                 'max_connections': max_connections,
#                 'retry_on_timeout': retry_on_timeout,
#                 'decode_responses': decode_responses,
#                 'max_idle_time': max_idle_time,
#                 'idle_check_interval': idle_check_interval,
#                 'loop': loop
#             }
#             # based on input, setup appropriate connection args
#             if unix_socket_path is not None:
#                 kwargs.update({
#                     'path': unix_socket_path,
#                     'connection_class': UnixDomainSocketConnection
#                 })
#             else:
#                 # TCP specific options
#                 kwargs.update({
#                     'host': host,
#                     'port': port
#                 })
#                 if ssl_context is not None:
#                     kwargs['ssl_context'] = ssl_context
#                 elif ssl:
#                     ssl_context = RedisSSLContext(ssl_keyfile, ssl_certfile, ssl_cert_reqs, ssl_ca_certs).get()
#                     kwargs['ssl_context'] = ssl_context
#             connection_pool = ConnectionPool(**kwargs)
#         self.connection_pool = connection_pool
#         self._use_lua_lock = None
# 
#         self.response_callbacks = self.__class__.RESPONSE_CALLBACKS.copy()
# 
#     def __repr__(self):
#         return "{}<{}>".format(type(self).__name__, repr(self.connection_pool))
# 
#     def set_response_callback(self, command, callback):
#         """Sets a custom Response Callback"""
#         self.response_callbacks[command] = callback
# 
#     # COMMAND EXECUTION AND PROTOCOL PARSING
#     async def execute_command(self, *args, **options):
#         """Executes a command and returns a parsed response"""
#         pool = self.connection_pool
#         command_name = args[0]
#         connection = pool.get_connection()
#         try:
#             await connection.send_command(*args)
#             return await self.parse_response(connection, command_name, **options)
#         except CancelledError:
#             # do not retry when coroutine is cancelled
#             connection.disconnect()
#             raise
#         except (ConnectionError, TimeoutError) as e:
#             connection.disconnect()
#             if not connection.retry_on_timeout and isinstance(e, TimeoutError):
#                 raise
#             await connection.send_command(*args)
#             return await self.parse_response(connection, command_name, **options)
#         finally:
#             pool.release(connection)
# 
#     async def parse_response(self, connection, command_name, **options):
#         """Parses a response from the Redis server"""
#         response = await connection.read_response()
#         if command_name in self.response_callbacks:
#             callback = self.response_callbacks[command_name]
#             return callback(response, **options)
#         return response
# 
#     async def pipeline(self, transaction=True, shard_hint=None):
#         """
#         Returns a new pipeline object that can queue multiple commands for
#         later execution. ``transaction`` indicates whether all commands
#         should be executed atomically. Apart from making a group of operations
#         atomic, pipelines are useful for reducing the back-and-forth overhead
#         between the client and server.
#         """
#         from aredis.pipeline import StrictPipeline
#         pipeline = StrictPipeline(self.connection_pool, self.response_callbacks,
#                                   transaction, shard_hint)
#         await pipeline.reset()
#         return pipeline


import asyncio
from aredis import StrictRedis
#!/usr/bin/python
# -*- coding: utf-8 -*-



async def pipeline(client):
    async with await client.pipeline(transaction=True) as pipe:
        # will return self to send another command
        pipe = await (await pipe.flushdb()).set('foo', 'bar')
        # can also directly send command
        await pipe.set('bar', 'foo')
        await pipe.keys('*')

# Path: aredis/client.py
# class StrictRedis(*mixins):
#     """
#     Implementation of the Redis protocol.
# 
#     This abstract class provides a Python interface to all Redis commands
#     and an implementation of the Redis protocol.
# 
#     Connection and Pipeline derive from this, implementing how
#     the commands are sent and received to the Redis server
#     """
# 
#     RESPONSE_CALLBACKS = dict_merge(*[mixin.RESPONSE_CALLBACKS for mixin in mixins])
# 
#     @classmethod
#     def from_url(cls, url, db=None, **kwargs):
#         """
#         Return a Redis client object configured from the given URL, which must
#         use either `the ``redis://`` scheme
#         <http://www.iana.org/assignments/uri-schemes/prov/redis>`_ for RESP
#         connections or the ``unix://`` scheme for Unix domain sockets.
# 
#         For example:
# 
#         redis://[:password]@localhost:6379/0
#         unix://[:password]@/path/to/socket.sock?db=0
# 
#         There are several ways to specify a database number. The parse function
#         will return the first specified option:
#         1. A ``db`` querystring option, e.g. redis://localhost?db=0
#         2. If using the redis:// scheme, the path argument of the url, e.g.
#         redis://localhost/0
#         3. The ``db`` argument to this function.
# 
#         If none of these options are specified, db=0 is used.
# 
#         Any additional querystring arguments and keyword arguments will be
#         passed along to the ConnectionPool class's initializer. In the case
#         of conflicting arguments, querystring arguments always win.
#         """
#         connection_pool = ConnectionPool.from_url(url, db=db, **kwargs)
#         return cls(connection_pool=connection_pool)
# 
#     def __init__(self, host='localhost', port=6379,
#                  db=0, password=None, stream_timeout=None,
#                  connect_timeout=None, connection_pool=None,
#                  unix_socket_path=None, encoding='utf-8',
#                  decode_responses=False, ssl=False, ssl_context=None,
#                  ssl_keyfile=None, ssl_certfile=None,
#                  ssl_cert_reqs=None, ssl_ca_certs=None,
#                  max_connections=None, retry_on_timeout=False,
#                  max_idle_time=0, idle_check_interval=1,
#                  loop=None, **kwargs):
#         if not connection_pool:
#             kwargs = {
#                 'db': db,
#                 'password': password,
#                 'encoding': encoding,
#                 'stream_timeout': stream_timeout,
#                 'connect_timeout': connect_timeout,
#                 'max_connections': max_connections,
#                 'retry_on_timeout': retry_on_timeout,
#                 'decode_responses': decode_responses,
#                 'max_idle_time': max_idle_time,
#                 'idle_check_interval': idle_check_interval,
#                 'loop': loop
#             }
#             # based on input, setup appropriate connection args
#             if unix_socket_path is not None:
#                 kwargs.update({
#                     'path': unix_socket_path,
#                     'connection_class': UnixDomainSocketConnection
#                 })
#             else:
#                 # TCP specific options
#                 kwargs.update({
#                     'host': host,
#                     'port': port
#                 })
#                 if ssl_context is not None:
#                     kwargs['ssl_context'] = ssl_context
#                 elif ssl:
#                     ssl_context = RedisSSLContext(ssl_keyfile, ssl_certfile, ssl_cert_reqs, ssl_ca_certs).get()
#                     kwargs['ssl_context'] = ssl_context
#             connection_pool = ConnectionPool(**kwargs)
#         self.connection_pool = connection_pool
#         self._use_lua_lock = None
# 
#         self.response_callbacks = self.__class__.RESPONSE_CALLBACKS.copy()
# 
#     def __repr__(self):
#         return "{}<{}>".format(type(self).__name__, repr(self.connection_pool))
# 
#     def set_response_callback(self, command, callback):
#         """Sets a custom Response Callback"""
#         self.response_callbacks[command] = callback
# 
#     # COMMAND EXECUTION AND PROTOCOL PARSING
#     async def execute_command(self, *args, **options):
#         """Executes a command and returns a parsed response"""
#         pool = self.connection_pool
#         command_name = args[0]
#         connection = pool.get_connection()
#         try:
#             await connection.send_command(*args)
#             return await self.parse_response(connection, command_name, **options)
#         except CancelledError:
#             # do not retry when coroutine is cancelled
#             connection.disconnect()
#             raise
#         except (ConnectionError, TimeoutError) as e:
#             connection.disconnect()
#             if not connection.retry_on_timeout and isinstance(e, TimeoutError):
#                 raise
#             await connection.send_command(*args)
#             return await self.parse_response(connection, command_name, **options)
#         finally:
#             pool.release(connection)
# 
#     async def parse_response(self, connection, command_name, **options):
#         """Parses a response from the Redis server"""
#         response = await connection.read_response()
#         if command_name in self.response_callbacks:
#             callback = self.response_callbacks[command_name]
#             return callback(response, **options)
#         return response
# 
#     async def pipeline(self, transaction=True, shard_hint=None):
#         """
#         Returns a new pipeline object that can queue multiple commands for
#         later execution. ``transaction`` indicates whether all commands
#         should be executed atomically. Apart from making a group of operations
#         atomic, pipelines are useful for reducing the back-and-forth overhead
#         between the client and server.
#         """
#         from aredis.pipeline import StrictPipeline
#         pipeline = StrictPipeline(self.connection_pool, self.response_callbacks,
#                                   transaction, shard_hint)
#         await pipeline.reset()
#         return pipeline


# Path: examples/pipeline.py
import asyncio
from aredis import StrictRedis

#!/usr/bin/python
# -*- coding: utf-8 -*-



async def pipeline(client):
    async with await client.pipeline(transaction=True) as pipe:
        # will return self to send another command
        pipe = await (await pipe.flushdb()).set('foo', 'bar')
        # can also directly send command
        await pipe.set('bar', 'foo')
        await pipe.keys('*')

        res = await pipe.execute()