# Path: aredis/connection.py
# class ClusterConnection(Connection):
#     "Manages TCP communication to and from a Redis server"
#     description = "ClusterConnection<host={host},port={port}>"
# 
#     def __init__(self, *args, **kwargs):
#         self.readonly = kwargs.pop('readonly', False)
#         super(ClusterConnection, self).__init__(*args, **kwargs)
# 
#     async def on_connect(self):
#         """
#         Initialize the connection, authenticate and select a database and send READONLY if it is
#         set during object initialization.
#         """
#         if self.db:
#             warnings.warn('SELECT DB is not allowed in cluster mode')
#             self.db = ''
#         await super(ClusterConnection, self).on_connect()
#         if self.readonly:
#             await self.send_command('READONLY')
#             if nativestr(await self.read_response()) != 'OK':
#                 raise ConnectionError('READONLY command failed')
# 
# Path: aredis/exceptions.py
# class LockError(RedisError, ValueError):
#     """Errors acquiring or releasing a lock"""
#     # NOTE: For backwards compatability, this class derives from ValueError.
#     # This was originally chosen to behave like threading.Lock.
#     pass
# 
# class WatchError(RedisError):
#     pass
# 
# Path: aredis/utils.py
# def b(x):
#     return x.encode('latin-1') if not isinstance(x, bytes) else x
# 
# class dummy:
#     """
#     Instances of this class can be used as an attribute container.
#     """
# 
#     def __init__(self):
#         self.token = None
# 
#     def set(self, value):
#         self.token = value
# 
#     def get(self):
#         return self.token


import asyncio
import time as mod_time
import uuid
import warnings
import contextvars
from aredis.connection import ClusterConnection
from aredis.exceptions import LockError, WatchError
from aredis.utils import b, dummy
        conn_kwargs = self.redis.connection_pool.connection_kwargs
        conn_kwargs['readonly'] = True
        for node in slave_nodes:
            try:
                # todo: a little bit dirty here, try to reuse StrictRedis later
                # todo: it may be optimized by using a new connection pool
                conn = ClusterConnection(host=node['host'], port=node['port'], **conn_kwargs)
                await conn.send_command('get', self.name)
                res = await conn.read_response()
                if res == token:
                    count += 1
                if count >= quorum:
                    return True
            except Exception as exc:
                warnings.warn('error {} during check lock {} status in slave nodes'.format(exc, self.name))
        return False

    async def acquire(self, blocking=None, blocking_timeout=None):
        """
        Use Redis to hold a shared, distributed lock named ``name``.
        Returns True once the lock is acquired.

        If ``blocking`` is False, always return immediately. If the lock
        was acquired, return True, otherwise return False.

        ``blocking_timeout`` specifies the maximum number of seconds to
        wait trying to acquire the lock. It should not be greater than
        expire time of the lock
        """
        sleep = self.sleep

# Path: aredis/connection.py
# class ClusterConnection(Connection):
#     "Manages TCP communication to and from a Redis server"
#     description = "ClusterConnection<host={host},port={port}>"
# 
#     def __init__(self, *args, **kwargs):
#         self.readonly = kwargs.pop('readonly', False)
#         super(ClusterConnection, self).__init__(*args, **kwargs)
# 
#     async def on_connect(self):
#         """
#         Initialize the connection, authenticate and select a database and send READONLY if it is
#         set during object initialization.
#         """
#         if self.db:
#             warnings.warn('SELECT DB is not allowed in cluster mode')
#             self.db = ''
#         await super(ClusterConnection, self).on_connect()
#         if self.readonly:
#             await self.send_command('READONLY')
#             if nativestr(await self.read_response()) != 'OK':
#                 raise ConnectionError('READONLY command failed')
# 
# Path: aredis/exceptions.py
# class LockError(RedisError, ValueError):
#     """Errors acquiring or releasing a lock"""
#     # NOTE: For backwards compatability, this class derives from ValueError.
#     # This was originally chosen to behave like threading.Lock.
#     pass
# 
# class WatchError(RedisError):
#     pass
# 
# Path: aredis/utils.py
# def b(x):
#     return x.encode('latin-1') if not isinstance(x, bytes) else x
# 
# class dummy:
#     """
#     Instances of this class can be used as an attribute container.
#     """
# 
#     def __init__(self):
#         self.token = None
# 
#     def set(self, value):
#         self.token = value
# 
#     def get(self):
#         return self.token


# Path: aredis/lock.py
import asyncio
import time as mod_time
import uuid
import warnings
import contextvars
from aredis.connection import ClusterConnection
from aredis.exceptions import LockError, WatchError
from aredis.utils import b, dummy

        conn_kwargs = self.redis.connection_pool.connection_kwargs
        conn_kwargs['readonly'] = True
        for node in slave_nodes:
            try:
                # todo: a little bit dirty here, try to reuse StrictRedis later
                # todo: it may be optimized by using a new connection pool
                conn = ClusterConnection(host=node['host'], port=node['port'], **conn_kwargs)
                await conn.send_command('get', self.name)
                res = await conn.read_response()
                if res == token:
                    count += 1
                if count >= quorum:
                    return True
            except Exception as exc:
                warnings.warn('error {} during check lock {} status in slave nodes'.format(exc, self.name))
        return False

    async def acquire(self, blocking=None, blocking_timeout=None):
        """
        Use Redis to hold a shared, distributed lock named ``name``.
        Returns True once the lock is acquired.

        If ``blocking`` is False, always return immediately. If the lock
        was acquired, return True, otherwise return False.

        ``blocking_timeout`` specifies the maximum number of seconds to
        wait trying to acquire the lock. It should not be greater than
        expire time of the lock
        """
        sleep = self.sleep

        token = b(uuid.uuid1().hex)