當前位置: 首頁>>代碼示例>>Python>>正文


Python aioredis.create_redis_pool方法代碼示例

本文整理匯總了Python中aioredis.create_redis_pool方法的典型用法代碼示例。如果您正苦於以下問題:Python aioredis.create_redis_pool方法的具體用法?Python aioredis.create_redis_pool怎麽用?Python aioredis.create_redis_pool使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在aioredis的用法示例。


在下文中一共展示了aioredis.create_redis_pool方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _create_redis_session

# 需要導入模塊: import aioredis [as 別名]
# 或者: from aioredis import create_redis_pool [as 別名]
def _create_redis_session(self) -> None:
        """
        Create the Redis connection pool, and then open the redis event gate.

        If constants.Redis.use_fakeredis is True, we'll set up a fake redis pool instead
        of attempting to communicate with a real Redis server. This is useful because it
        means contributors don't necessarily need to get Redis running locally just
        to run the bot.

        The fakeredis cache won't have persistence across restarts, but that
        usually won't matter for local bot testing.
        """
        if constants.Redis.use_fakeredis:
            log.info("Using fakeredis instead of communicating with a real Redis server.")
            self.redis_session = await fakeredis.aioredis.create_redis_pool()
        else:
            self.redis_session = await aioredis.create_redis_pool(
                address=(constants.Redis.host, constants.Redis.port),
                password=constants.Redis.password,
            )

        self.redis_closed = False
        self.redis_ready.set() 
開發者ID:python-discord,項目名稱:bot,代碼行數:25,代碼來源:bot.py

示例2: main

# 需要導入模塊: import aioredis [as 別名]
# 或者: from aioredis import create_redis_pool [as 別名]
def main():
    redis = await aioredis.create_redis_pool('redis://localhost')

    ch, = await redis.psubscribe('channel:*')
    assert isinstance(ch, aioredis.Channel)

    async def reader(channel):
        async for ch, message in channel.iter():
            print("Got message in channel:", ch, ":", message)
    asyncio.get_running_loop().create_task(reader(ch))

    await redis.publish('channel:1', 'Hello')
    await redis.publish('channel:2', 'World')

    redis.close()
    await redis.wait_closed() 
開發者ID:aio-libs,項目名稱:aioredis,代碼行數:18,代碼來源:05_pubsub.py

示例3: main

# 需要導入模塊: import aioredis [as 別名]
# 或者: from aioredis import create_redis_pool [as 別名]
def main():
    redis = await aioredis.create_redis_pool('redis://localhost')

    await redis.hmset_dict('hash',
                           key1='value1',
                           key2='value2',
                           key3=123)

    result = await redis.hgetall('hash', encoding='utf-8')
    assert result == {
        'key1': 'value1',
        'key2': 'value2',
        'key3': '123',  # note that Redis returns int as string
    }

    redis.close()
    await redis.wait_closed() 
開發者ID:aio-libs,項目名稱:aioredis,代碼行數:19,代碼來源:02_decoding.py

示例4: main

# 需要導入模塊: import aioredis [as 別名]
# 或者: from aioredis import create_redis_pool [as 別名]
def main():
    redis = await aioredis.create_redis_pool('redis://localhost')

    ch1, ch2 = await redis.subscribe('channel:1', 'channel:2')
    assert isinstance(ch1, aioredis.Channel)
    assert isinstance(ch2, aioredis.Channel)

    async def reader(channel):
        async for message in channel.iter():
            print("Got message:", message)
    asyncio.get_running_loop().create_task(reader(ch1))
    asyncio.get_running_loop().create_task(reader(ch2))

    await redis.publish('channel:1', 'Hello')
    await redis.publish('channel:2', 'World')

    redis.close()
    await redis.wait_closed() 
開發者ID:aio-libs,項目名稱:aioredis,代碼行數:20,代碼來源:04_pubsub.py

示例5: redis

# 需要導入模塊: import aioredis [as 別名]
# 或者: from aioredis import create_redis_pool [as 別名]
def redis(loop, redis_params):
    pool = None

    async def start(*args, no_loop=False, **kwargs):
        nonlocal pool
        params = redis_params.copy()
        params.update(kwargs)
        useloop = None if no_loop else loop
        pool = await aioredis.create_redis_pool(loop=useloop, **params)
        return pool

    loop.run_until_complete(start())
    yield pool
    if pool is not None:
        pool.close()
        loop.run_until_complete(pool.wait_closed()) 
開發者ID:aio-libs,項目名稱:aiohttp-session,代碼行數:18,代碼來源:conftest.py

示例6: test_connect_pool_not_created

# 需要導入模塊: import aioredis [as 別名]
# 或者: from aioredis import create_redis_pool [as 別名]
def test_connect_pool_not_created(self, connection, address, redis_kwargs):
        with patch('aioredlock.redis.Instance._create_redis_pool') as \
                create_redis_pool:

            fake_pool = FakePool()
            create_redis_pool.side_effect = fake_create_redis_pool(fake_pool)
            instance = Instance(connection)

            assert instance._pool is None
            pool = await instance.connect()

            create_redis_pool.assert_called_once_with(
                address, **redis_kwargs,
                minsize=1, maxsize=100)
            assert pool is fake_pool
            assert instance._pool is fake_pool 
開發者ID:joanvila,項目名稱:aioredlock,代碼行數:18,代碼來源:test_redis.py

示例7: get_redis_pool_cli

# 需要導入模塊: import aioredis [as 別名]
# 或者: from aioredis import create_redis_pool [as 別名]
def get_redis_pool_cli(self):
        """
        :return: an async redis client
        """
        if self.redis_pool_cli is None:
            kwargs = {
                "db": int(self.db),
                "password": self.password,
                "encoding": self.encoding,
                "timeout": self.timeout,
                "minsize": 1,
                "maxsize": 3
            }
            if self.compress:
                del kwargs["encoding"]
            self.redis_pool_cli = await aioredis.create_redis_pool((self.host, self.port), **kwargs)
            if self.key_type == "LIST":
                if self.direction == "L":
                    self.redis_write_method = self.redis_pool_cli.lpush
                else:
                    self.redis_write_method = self.redis_pool_cli.rpush
            else:
                self.redis_write_method = self.redis_pool_cli.hset

        return self.redis_pool_cli 
開發者ID:zpoint,項目名稱:idataapi-transform,代碼行數:27,代碼來源:WriterConfig.py

示例8: main

# 需要導入模塊: import aioredis [as 別名]
# 或者: from aioredis import create_redis_pool [as 別名]
def main():
    redis = await aioredis.create_redis_pool('redis://localhost')

    tr = redis.multi_exec()
    tr.set('key1', 'value1')
    tr.set('key2', 'value2')
    ok1, ok2 = await tr.execute()
    assert ok1
    assert ok2 
開發者ID:aio-libs,項目名稱:aioredis,代碼行數:11,代碼來源:03_multiexec.py

示例9: main

# 需要導入模塊: import aioredis [as 別名]
# 或者: from aioredis import create_redis_pool [as 別名]
def main():
    redis = await aioredis.create_redis_pool('redis://localhost')
    await redis.set('my-key', 'value')
    value = await redis.get('my-key', encoding='utf-8')
    print(value)

    redis.close()
    await redis.wait_closed() 
開發者ID:aio-libs,項目名稱:aioredis,代碼行數:10,代碼來源:00_connect.py

示例10: redis_pool

# 需要導入模塊: import aioredis [as 別名]
# 或者: from aioredis import create_redis_pool [as 別名]
def redis_pool():
    # Redis client bound to pool of connections (auto-reconnecting).
    redis = await aioredis.create_redis_pool(
        'redis://localhost')
    await redis.set('my-key', 'value')
    val = await redis.get('my-key')
    print(val)

    # gracefully closing underlying connection
    redis.close()
    await redis.wait_closed() 
開發者ID:aio-libs,項目名稱:aioredis,代碼行數:13,代碼來源:commands.py

示例11: pool_or_redis

# 需要導入模塊: import aioredis [as 別名]
# 或者: from aioredis import create_redis_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

示例12: setup_rdb

# 需要導入模塊: import aioredis [as 別名]
# 或者: from aioredis import create_redis_pool [as 別名]
def setup_rdb(self):
        if config.TESTING:
            redis_url = self.credentials.test_redis_url
        else:
            redis_url = config.REDIS_URL
        return RedisIO(await aioredis.create_redis_pool(redis_url, db=config.REDIS_DB_NUM)) 
開發者ID:avrae,項目名稱:avrae,代碼行數:8,代碼來源:dbot.py

示例13: make_redis_pool

# 需要導入模塊: import aioredis [as 別名]
# 或者: from aioredis import create_redis_pool [as 別名]
def make_redis_pool():
    redis_address = ('127.0.0.1', '6379')
    return await aioredis.create_redis_pool(redis_address, timeout=1) 
開發者ID:aio-libs,項目名稱:aiohttp-session,代碼行數:5,代碼來源:redis_storage.py

示例14: arq_redis

# 需要導入模塊: import aioredis [as 別名]
# 或者: from aioredis import create_redis_pool [as 別名]
def arq_redis(loop):
    redis_ = await create_redis_pool(
        ('localhost', 6379), encoding='utf8', loop=loop, commands_factory=ArqRedis, minsize=5
    )
    await redis_.flushall()
    yield redis_
    redis_.close()
    await redis_.wait_closed() 
開發者ID:samuelcolvin,項目名稱:arq,代碼行數:10,代碼來源:conftest.py

示例15: arq_redis_msgpack

# 需要導入模塊: import aioredis [as 別名]
# 或者: from aioredis import create_redis_pool [as 別名]
def arq_redis_msgpack(loop):
    redis_ = await create_redis_pool(
        ('localhost', 6379),
        encoding='utf8',
        loop=loop,
        commands_factory=functools.partial(
            ArqRedis, job_serializer=msgpack.packb, job_deserializer=functools.partial(msgpack.unpackb, raw=False)
        ),
    )
    await redis_.flushall()
    yield redis_
    redis_.close()
    await redis_.wait_closed() 
開發者ID:samuelcolvin,項目名稱:arq,代碼行數:15,代碼來源:conftest.py


注:本文中的aioredis.create_redis_pool方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。