当前位置: 首页>>代码示例>>Python>>正文


Python aioredis.create_pool方法代码示例

本文整理汇总了Python中aioredis.create_pool方法的典型用法代码示例。如果您正苦于以下问题:Python aioredis.create_pool方法的具体用法?Python aioredis.create_pool怎么用?Python aioredis.create_pool使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在aioredis的用法示例。


在下文中一共展示了aioredis.create_pool方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import aioredis [as 别名]
# 或者: from aioredis import create_pool [as 别名]
def __init__(self, redis_pool, *, cookie_name="AIOHTTP_SESSION",
                 domain=None, max_age=None, path='/',
                 secure=None, httponly=True,
                 key_factory=lambda: uuid.uuid4().hex,
                 encoder=json.dumps, decoder=json.loads):
        super().__init__(cookie_name=cookie_name, domain=domain,
                         max_age=max_age, path=path, secure=secure,
                         httponly=httponly,
                         encoder=encoder, decoder=decoder)
        if aioredis is None:
            raise RuntimeError("Please install aioredis")
        if StrictVersion(aioredis.__version__).version < (1, 0):
            raise RuntimeError("aioredis<1.0 is not supported")
        self._key_factory = key_factory
        if isinstance(redis_pool, aioredis.pool.ConnectionsPool):
            warnings.warn(
                "using a pool created with aioredis.create_pool is deprecated"
                "please use a pool created with aioredis.create_redis_pool",
                DeprecationWarning
            )
            redis_pool = aioredis.commands.Redis(redis_pool)
        elif not isinstance(redis_pool, aioredis.commands.Redis):
            raise TypeError("Expexted aioredis.commands.Redis got {}".format(
                    type(redis_pool)))
        self._redis = redis_pool 
开发者ID:aio-libs,项目名称:aiohttp-session,代码行数:27,代码来源:redis_storage.py

示例2: init

# 需要导入模块: import aioredis [as 别名]
# 或者: from aioredis import create_pool [as 别名]
def init(loop):
    redis_pool = await create_pool(('localhost', 6379))
    db_engine = await create_engine(user='aiohttp_security',
                                    password='aiohttp_security',
                                    database='aiohttp_security',
                                    host='127.0.0.1')
    app = web.Application()
    app.db_engine = db_engine
    setup_session(app, RedisStorage(redis_pool))
    setup_security(app,
                   SessionIdentityPolicy(),
                   DBAuthorizationPolicy(db_engine))

    web_handlers = Web()
    web_handlers.configure(app)

    handler = app.make_handler()
    srv = await loop.create_server(handler, '127.0.0.1', 8080)
    print('Server started at http://127.0.0.1:8080')
    return srv, app, handler 
开发者ID:aio-libs,项目名称:aiohttp-security,代码行数:22,代码来源:main.py

示例3: _get_pool

# 需要导入模块: import aioredis [as 别名]
# 或者: from aioredis import create_pool [as 别名]
def _get_pool(self):
        async with self._pool_lock:
            if self._pool is None:
                kwargs = {
                    "db": self.db,
                    "password": self.password,
                    "loop": self._loop,
                    "encoding": "utf-8",
                    "minsize": self.pool_min_size,
                    "maxsize": self.pool_max_size,
                }
                if not AIOREDIS_BEFORE_ONE:
                    kwargs["create_connection_timeout"] = self.create_connection_timeout

                self._pool = await aioredis.create_pool((self.endpoint, self.port), **kwargs)

            return self._pool 
开发者ID:argaen,项目名称:aiocache,代码行数:19,代码来源:redis.py

示例4: main

# 需要导入模块: import aioredis [as 别名]
# 或者: from aioredis import create_pool [as 别名]
def main():
    pool = await aioredis.create_pool(
        'redis://localhost',
        minsize=5, maxsize=10)
    with await pool as conn:    # low-level redis connection
        await conn.execute('set', 'my-key', 'value')
        val = await conn.execute('get', 'my-key')
    print('raw value:', val)
    pool.close()
    await pool.wait_closed()    # closing all open connections 
开发者ID:aio-libs,项目名称:aioredis,代码行数:12,代码来源:pool.py

示例5: pubsub

# 需要导入模块: import aioredis [as 别名]
# 或者: from aioredis import create_pool [as 别名]
def pubsub():
    pool = await aioredis.create_pool(
        'redis://localhost',
        minsize=5, maxsize=10)

    async def reader(channel):
        while (await channel.wait_message()):
            msg = await channel.get(encoding='utf-8')
            # ... process message ...
            print("message in {}: {}".format(channel.name, msg))

            if msg == STOPWORD:
                return

    with await pool as conn:
        await conn.execute_pubsub('subscribe', 'channel:1')
        channel = conn.pubsub_channels['channel:1']
        await reader(channel)  # wait for reader to complete
        await conn.execute_pubsub('unsubscribe', 'channel:1')

    # Explicit connection usage
    conn = await pool.acquire()
    try:
        await conn.execute_pubsub('subscribe', 'channel:1')
        channel = conn.pubsub_channels['channel:1']
        await reader(channel)  # wait for reader to complete
        await conn.execute_pubsub('unsubscribe', 'channel:1')
    finally:
        pool.release(conn)

    pool.close()
    await pool.wait_closed()    # closing all open connections 
开发者ID:aio-libs,项目名称:aioredis,代码行数:34,代码来源:pool_pubsub.py

示例6: pool_or_redis

# 需要导入模块: import aioredis [as 别名]
# 或者: from aioredis import create_pool [as 别名]
def pool_or_redis(_closable, server):
    version = tuple(map(int, aioredis.__version__.split('.')[:2]))
    if version >= (1, 0):
        factory = aioredis.create_redis_pool
    else:
        factory = aioredis.create_pool

    async def redis_factory(maxsize):
        redis = await factory(server.tcp_address,
                              minsize=1, maxsize=maxsize)
        _closable(redis)
        return redis
    return redis_factory 
开发者ID:aio-libs,项目名称:aioredis,代码行数:15,代码来源:integration_test.py

示例7: create_pool

# 需要导入模块: import aioredis [as 别名]
# 或者: from aioredis import create_pool [as 别名]
def create_pool(_closable):
    """Wrapper around aioredis.create_pool."""

    async def f(*args, **kw):
        redis = await aioredis.create_pool(*args, **kw)
        _closable(redis)
        return redis
    return f 
开发者ID:aio-libs,项目名称:aioredis,代码行数:10,代码来源:conftest.py

示例8: pool

# 需要导入模块: import aioredis [as 别名]
# 或者: from aioredis import create_pool [as 别名]
def pool(create_pool, server, loop):
    """Returns RedisPool instance."""
    return loop.run_until_complete(create_pool(server.tcp_address)) 
开发者ID:aio-libs,项目名称:aioredis,代码行数:5,代码来源:conftest.py

示例9: start

# 需要导入模块: import aioredis [as 别名]
# 或者: from aioredis import create_pool [as 别名]
def start(self, *args, **kwargs):
        t = threading.Thread(target=block_check, args=(self.loop,))
        t.setDaemon(True)
        t.start()
        self.redis = aioredis.Redis(await aioredis.create_pool("redis://" + self.config.redis_host))
        # self.loop.create_task(self._shards_reader())

        return await super().start(*args, **kwargs) 
开发者ID:Xenon-Bot,项目名称:xenon,代码行数:10,代码来源:bot.py

示例10: test_redis_from_create_pool

# 需要导入模块: import aioredis [as 别名]
# 或者: from aioredis import create_pool [as 别名]
def test_redis_from_create_pool(redis_params):

    async def handler(request):
        pass

    redis = await aioredis.create_pool(**redis_params)
    with pytest.warns(DeprecationWarning):
        create_app(handler=handler, redis=redis) 
开发者ID:aio-libs,项目名称:aiohttp-session,代码行数:10,代码来源:test_redis_storage.py

示例11: event_handler

# 需要导入模块: import aioredis [as 别名]
# 或者: from aioredis import create_pool [as 别名]
def event_handler(self):
        self.redis = await aioredis.create_pool("redis://localhost", minsize=1, maxsize=2)
        await self.redis.execute_pubsub("SUBSCRIBE", config.ipc_channel)
        channel = self.redis.pubsub_channels[bytes(config.ipc_channel, "utf-8")]
        while await channel.wait_message():
            payload = await channel.get_json(encoding="utf-8")
            if payload.get("scope") != "launcher" or not payload.get("action"):
                pass
            elif payload.get("action") == "restart":
                print(f"[Cluster Manager] Received signal to restart cluster {payload.get('id')}.")
                self.loop.create_task(self.get_instance(self.instances, payload.get("id")).restart())
            elif payload.get("action") == "stop":
                print(f"[Cluster Manager] Received signal to stop cluster {payload.get('id')}.")
                self.loop.create_task(self.get_instance(self.instances, payload.get("id")).stop())
            elif payload.get("action") == "start":
                print(f"[Cluster Manager] Received signal to start cluster {payload.get('id')}.")
                self.loop.create_task(self.get_instance(self.instances, payload.get("id")).start())
            elif payload.get("action") == "statuses" and payload.get("command_id"):
                statuses = {}
                for instance in self.instances:
                    statuses[str(instance.id)] = {
                        "active": instance.is_active,
                        "status": instance.status,
                        "started_at": instance.started_at,
                    }
                await self.redis.execute(
                    "PUBLISH",
                    config.ipc_channel,
                    json.dumps({"command_id": payload["command_id"], "output": statuses}),
                )
            elif payload.get("action") == "roll_restart":
                print("[Cluster Manager] Received signal to perform a rolling restart.")
                for instance in self.instances:
                    self.loop.create_task(instance.restart())
                    await asyncio.sleep(config.shards_per_cluster * 10) 
开发者ID:CHamburr,项目名称:modmail,代码行数:37,代码来源:launcher.py

示例12: connect_redis

# 需要导入模块: import aioredis [as 别名]
# 或者: from aioredis import create_pool [as 别名]
def connect_redis(self):
        self.redis = await aioredis.create_pool("redis://localhost", minsize=5, maxsize=10, loop=self.loop, db=0)
        info = (await self.redis.execute("INFO")).decode()
        for line in info.split("\n"):
            if line.startswith("redis_version"):
                self.redis_version = line.split(":")[1]
                break 
开发者ID:CHamburr,项目名称:modmail,代码行数:9,代码来源:bot.py

示例13: connect_postgres

# 需要导入模块: import aioredis [as 别名]
# 或者: from aioredis import create_pool [as 别名]
def connect_postgres(self):
        self.pool = await asyncpg.create_pool(**self.config.database, max_size=20, command_timeout=60) 
开发者ID:CHamburr,项目名称:modmail,代码行数:4,代码来源:bot.py

示例14: _create_redis_pool

# 需要导入模块: import aioredis [as 别名]
# 或者: from aioredis import create_pool [as 别名]
def _create_redis_pool(*args, **kwargs):
        """
        Adapter to support both aioredis-0.3.0 and aioredis-1.0.0
        For aioredis-1.0.0 and later calls:
            aioredis.create_redis_pool(*args, **kwargs)
        For aioredis-0.3.0 calls:
            aioredis.create_pool(*args, **kwargs)
        """

        if StrictVersion(aioredis.__version__) >= StrictVersion('1.0.0'):  # pragma no cover
            return await aioredis.create_redis_pool(*args, **kwargs)
        else:  # pragma no cover
            return await aioredis.create_pool(*args, **kwargs) 
开发者ID:joanvila,项目名称:aioredlock,代码行数:15,代码来源:redis.py

示例15: __init__

# 需要导入模块: import aioredis [as 别名]
# 或者: from aioredis import create_pool [as 别名]
def __init__(self, server, loop):
        self.pool = aioredis.create_pool(
            server,
            minsize=5, maxsize=15,
            loop=loop
        ) 
开发者ID:guilhermelawless,项目名称:nano-dpow,代码行数:8,代码来源:redis_db.py


注:本文中的aioredis.create_pool方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。