本文整理汇总了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()
示例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()
示例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()
示例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()
示例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())
示例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
示例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
示例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
示例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()
示例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()
示例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
示例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))
示例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)
示例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()
示例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()