Example #1
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 = aioredis.ConnectionPool(parser_class=parser_class,
                                       **url_options)
        client: aioredis.Redis = aioredis.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 aioredis.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_tcp(self):
     pool = aioredis.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
Example #3
0
def redis_pool() -> Redis:
    connection_pool = aioredis.ConnectionPool(max_connections=100)
    REDIS_POOL = aioredis.Redis(host="127.0.0.1",
                                port=6379,
                                db=0,
                                connection_pool=connection_pool)
    return REDIS_POOL
 def test_repr_contains_db_info_unix(self):
     pool = aioredis.ConnectionPool(
         connection_class=aioredis.UnixDomainSocketConnection,
         path="abc",
         client_name="test-client",
     )
     expected = ("ConnectionPool<UnixDomainSocketConnection<"
                 "path=abc,db=0,client_name=test-client>>")
     assert repr(pool) == expected
 def get_pool(
     self,
     connection_kwargs=None,
     max_connections=None,
     connection_class=aioredis.Connection,
 ):
     connection_kwargs = connection_kwargs or {}
     pool = aioredis.ConnectionPool(connection_class=connection_class,
                                    max_connections=max_connections,
                                    **connection_kwargs)
     return pool
Example #6
0
 def __init__(self, block_num=3):
     """
     :param block_num: one blockNum for about 90,000,000; if you have more strings for filtering, increase it.
     """
     pool = aioredis.ConnectionPool(max_connections=5000,
                                    host=REDIS_HOST,
                                    port=REDIS_PORT,
                                    db=1,
                                    socket_timeout=10,
                                    retry_on_timeout=10,
                                    password=REDIS_PWD)
     self.server = redis.StrictRedis(connection_pool=pool)
     self.bit_size = 1 << 10  # Redis的String类型最大容量为512M,现使用256M
     self.seeds = [5, 7, 11, 13, 31, 37, 61]
     self.blockNum = block_num
     self.hashfunc = []
     for seed in self.seeds:
         self.hashfunc.append(SimpleHash(self.bit_size, seed))