def test_repr_contains_db_info_tcp(self):
     pool = redis.ConnectionPool(host="localhost",
                                 port=6379,
                                 client_name="test-client")
     expected = ("ConnectionPool<Connection<"
                 "host=localhost,port=6379,db=0,client_name=test-client>>")
     assert repr(pool) == expected
Пример #2
0
    async def f(url: str = request.config.getoption("--redis-url"), **kwargs):
        single = kwargs.pop("single_connection_client",
                            False) or single_connection
        parser_class = kwargs.pop("parser_class", None) or parser_cls
        url_options = parse_url(url)
        url_options.update(kwargs)
        pool = redis.ConnectionPool(parser_class=parser_class, **url_options)
        client: redis.Redis = redis.Redis(connection_pool=pool)
        if single:
            client = client.client()
            await client.initialize()

        def teardown():
            async def ateardown():
                if "username" in kwargs:
                    return
                try:
                    await client.flushdb()
                except redis.ConnectionError:
                    # handle cases where a test disconnected a client
                    # just manually retry the flushdb
                    await client.flushdb()
                await client.close()
                await client.connection_pool.disconnect()

            if event_loop.is_running():
                event_loop.create_task(ateardown())
            else:
                event_loop.run_until_complete(ateardown())

        request.addfinalizer(teardown)

        return client
 def test_repr_contains_db_info_unix(self):
     pool = redis.ConnectionPool(
         connection_class=redis.UnixDomainSocketConnection,
         path="abc",
         client_name="test-client",
     )
     expected = ("ConnectionPool<UnixDomainSocketConnection<"
                 "path=abc,db=0,client_name=test-client>>")
     assert repr(pool) == expected
Пример #4
0
    async def f(
        url: str = request.config.getoption("--redis-url"),
        cls=redis.Redis,
        flushdb=True,
        **kwargs,
    ):
        cluster_mode = REDIS_INFO["cluster_enabled"]
        if not cluster_mode:
            single = kwargs.pop("single_connection_client",
                                False) or single_connection
            parser_class = kwargs.pop("parser_class", None) or parser_cls
            url_options = parse_url(url)
            url_options.update(kwargs)
            pool = redis.ConnectionPool(parser_class=parser_class,
                                        **url_options)
            client = cls(connection_pool=pool)
        else:
            client = redis.RedisCluster.from_url(url, **kwargs)
            await client.initialize()
            single = False
        if single:
            client = client.client()
            await client.initialize()

        def teardown():
            async def ateardown():
                if not cluster_mode:
                    if "username" in kwargs:
                        return
                    if flushdb:
                        try:
                            await client.flushdb()
                        except redis.ConnectionError:
                            # handle cases where a test disconnected a client
                            # just manually retry the flushdb
                            await client.flushdb()
                    await client.close()
                    await client.connection_pool.disconnect()
                else:
                    if flushdb:
                        try:
                            await client.flushdb(target_nodes="primaries")
                        except redis.ConnectionError:
                            # handle cases where a test disconnected a client
                            # just manually retry the flushdb
                            await client.flushdb(target_nodes="primaries")
                    await client.close()

            if event_loop.is_running():
                event_loop.create_task(ateardown())
            else:
                event_loop.run_until_complete(ateardown())

        request.addfinalizer(teardown)

        return client
 def get_pool(
     self,
     connection_kwargs=None,
     max_connections=None,
     connection_class=redis.Connection,
 ):
     connection_kwargs = connection_kwargs or {}
     pool = redis.ConnectionPool(
         connection_class=connection_class,
         max_connections=max_connections,
         **connection_kwargs,
     )
     return pool