Exemple #1
0
def mock_redis_two_instances(redis_two_connections):
    pool = FakePool()
    redis = Redis(redis_two_connections, 10)

    for instance in redis.instances:
        instance._pool = pool

    yield redis, pool
Exemple #2
0
    def test_initialization(self, redis_two_connections):
        with patch("aioredlock.redis.Instance.__init__") as mock_instance:
            mock_instance.return_value = None

            redis = Redis(redis_two_connections)

            calls = [
                call({'host': 'localhost', 'port': 6379}),
                call({'host': '127.0.0.1', 'port': 6378})
            ]
            mock_instance.assert_has_calls(calls)
            assert len(redis.instances) == 2
Exemple #3
0
    def test_initialization(self, redis_two_connections):
        with patch("aioredlock.redis.Instance.__init__") as mock_instance:
            mock_instance.return_value = None

            redis = Redis(redis_two_connections, 10)

            calls = [
                call(host='localhost', port=6379),
                call(host='127.0.0.1', port=6378)
            ]
            mock_instance.assert_has_calls(calls)
            assert len(redis.instances) == 2
            assert redis.lock_timeout == 10
Exemple #4
0
    def __init__(self,
                 redis_connections=[{
                     'host': 'localhost',
                     'port': 6379
                 }]):
        """
        Initializes Aioredlock with the list of redis instances

        :param redis_connections: A list of dicts like:
        [{"host": "localhost", "port": 6379}]
        """

        self.redis = Redis(redis_connections, self.LOCK_TIMEOUT)

        # Proportional drift time to the length of the lock
        # See https://redis.io/topics/distlock#is-the-algorithm-asynchronous for more info
        self.drift = int(self.LOCK_TIMEOUT * 0.01) + 2
Exemple #5
0
 def __attrs_post_init__(self):
     self.redis = Redis(self.redis_connections)
     self._watchdogs = {}
     self._locks = {}
Exemple #6
0
 def __attrs_post_init__(self):
     self.redis = Redis(self.redis_connections, self.lock_timeout)