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


Python aioredis.create_redis方法代码示例

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


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

示例1: start_work

# 需要导入模块: import aioredis [as 别名]
# 或者: from aioredis import create_redis [as 别名]
def start_work():
    global aredis
    loop = asyncio.get_event_loop()
    aredis = await aioredis.create_redis('redis://localhost', loop=loop)

    if await aredis.get('state') == b'running':
        return "<center>Please wait for current work to finish.</center>"
    else:
        await aredis.set('state', 'ready')

    if await aredis.get('state') == b'ready':
        loop.create_task(some_work())
        body = '''
        <center>
        work started!
        </center>
        <script type="text/javascript">
            window.location = "''' + url_for('progress') + '''";
        </script>'''
        return body 
开发者ID:pgjones,项目名称:quart,代码行数:22,代码来源:progress_bar.py

示例2: __init__

# 需要导入模块: import aioredis [as 别名]
# 或者: from aioredis import create_redis [as 别名]
def __init__(self, io_loop: asyncio.AbstractEventLoop = None):
        super().__init__()
        self.io_loop = io_loop or asyncio.get_event_loop()
        self.sub_client = self.io_loop.run_until_complete(
                aioredis.create_redis((config.get('REDIS', 'host', fallback='localhost'),
                                       config.getint('REDIS', 'port', fallback=6379)),
                                      db=config.getint('REDIS', 'db', fallback=1)))
        self.redis_client = redis.StrictRedis(
            host=config.get('REDIS', 'host', fallback='localhost'),
            db=config.getint('REDIS', 'db', fallback=1), decode_responses=True)
        self.initialized = False
        self.sub_tasks = list()
        self.sub_channels = list()
        self.channel_router = dict()
        self.crontab_router = defaultdict(dict)
        self.datetime = None
        self.time = None
        self.loop_time = None 
开发者ID:BigBrotherTrade,项目名称:trader,代码行数:20,代码来源:__init__.py

示例3: main

# 需要导入模块: import aioredis [as 别名]
# 或者: from aioredis import create_redis [as 别名]
def main():
    pub = await aioredis.create_redis(
        'redis://localhost')
    sub = await aioredis.create_redis(
        'redis://localhost')
    res = await sub.subscribe('chan:1')
    ch1 = res[0]

    tsk = asyncio.ensure_future(reader(ch1))

    res = await pub.publish_json('chan:1', ["Hello", "world"])
    assert res == 1

    await sub.unsubscribe('chan:1')
    await tsk
    sub.close()
    pub.close() 
开发者ID:aio-libs,项目名称:aioredis,代码行数:19,代码来源:pubsub.py

示例4: config_ctx

# 需要导入模块: import aioredis [as 别名]
# 或者: from aioredis import create_redis [as 别名]
def config_ctx(cli_ctx):
    config = cli_ctx.config
    ctx = {}
    ctx['config'] = config
    # scope_prefix_map is created inside ConfigServer
    config_server = ConfigServer(
        ctx, config['etcd']['addr'],
        config['etcd']['user'], config['etcd']['password'],
        config['etcd']['namespace'])
    raw_redis_config = await config_server.etcd.get_prefix('config/redis')
    config['redis'] = redis_config_iv.check(raw_redis_config)
    ctx['redis_image'] = await aioredis.create_redis(
        config['redis']['addr'].as_sockaddr(),
        password=config['redis']['password'] if config['redis']['password'] else None,
        timeout=3.0,
        encoding='utf8',
        db=REDIS_IMAGE_DB)
    try:
        yield config_server
    finally:
        ctx['redis_image'].close()
        await ctx['redis_image'].wait_closed()
        await config_server.close() 
开发者ID:lablup,项目名称:backend.ai-manager,代码行数:25,代码来源:etcd.py

示例5: home

# 需要导入模块: import aioredis [as 别名]
# 或者: from aioredis import create_redis [as 别名]
def home(request):
    redis = await create_redis(REDIS_URL)
    cases = await redis.get("cases")

    if cases:
        cases = pickle.loads(cases)
    else:
        data = Data()
        cases = await data.cases()
        await redis.set("cases", pickle.dumps(cases))

    redis.close()
    await redis.wait_closed()

    return {
        "cases": cases,
        "title": TITLE,
        "url_path": "/",
        "max_chars": CASE_MAX_CHARS,
    } 
开发者ID:okfn-brasil,项目名称:vitimas-da-intolerancia,代码行数:22,代码来源:__init__.py

示例6: _publish

# 需要导入模块: import aioredis [as 别名]
# 或者: from aioredis import create_redis [as 别名]
def _publish(self, data):
        retry = True
        while True:
            try:
                if self.pub is None:
                    self.pub = await aioredis.create_redis(
                        (self.host, self.port), db=self.db,
                        password=self.password, ssl=self.ssl
                    )
                return await self.pub.publish(self.channel,
                                              pickle.dumps(data))
            except (aioredis.RedisError, OSError):
                if retry:
                    self._get_logger().error('Cannot publish to redis... '
                                             'retrying')
                    self.pub = None
                    retry = False
                else:
                    self._get_logger().error('Cannot publish to redis... '
                                             'giving up')
                    break 
开发者ID:miguelgrinberg,项目名称:python-socketio,代码行数:23,代码来源:asyncio_redis_manager.py

示例7: _listen

# 需要导入模块: import aioredis [as 别名]
# 或者: from aioredis import create_redis [as 别名]
def _listen(self):
        retry_sleep = 1
        while True:
            try:
                if self.sub is None:
                    self.sub = await aioredis.create_redis(
                        (self.host, self.port), db=self.db,
                        password=self.password, ssl=self.ssl
                    )
                self.ch = (await self.sub.subscribe(self.channel))[0]
                return await self.ch.get()
            except (aioredis.RedisError, OSError):
                self._get_logger().error('Cannot receive from redis... '
                                         'retrying in '
                                         '{} secs'.format(retry_sleep))
                self.sub = None
                await asyncio.sleep(retry_sleep)
                retry_sleep *= 2
                if retry_sleep > 60:
                    retry_sleep = 60 
开发者ID:miguelgrinberg,项目名称:python-socketio,代码行数:22,代码来源:asyncio_redis_manager.py

示例8: test_redis_handler

# 需要导入模块: import aioredis [as 别名]
# 或者: from aioredis import create_redis [as 别名]
def test_redis_handler(event_loop):
    import redis
    r = redis.Redis()
    logger = logging.getLogger('qulabtest2')
    logger.setLevel(logging.DEBUG)
    handler = RedisHandler(r)
    handler.setLevel(logging.DEBUG)
    logger.addHandler(handler)

    sub = await aioredis.create_redis('redis://localhost')
    logChannel, = await sub.subscribe('log')

    logger.debug('hello')

    if await logChannel.wait_message():
        bmsg = await logChannel.get()
        record = logging.makeLogRecord(unpack(bmsg))
        assert record.msg == 'hello'
    pass 
开发者ID:feihoo87,项目名称:QuLab,代码行数:21,代码来源:test_log.py

示例9: query

# 需要导入模块: import aioredis [as 别名]
# 或者: from aioredis import create_redis [as 别名]
def query(self, query_type: str, **kwargs):
        sub_client = None
        channel_name1, channel_name2 = None, None
        try:
            sub_client = await aioredis.create_redis(
                (config.get('REDIS', 'host', fallback='localhost'),
                 config.getint('REDIS', 'port', fallback=6379)),
                db=config.getint('REDIS', 'db', fallback=1))
            request_id = self.next_id()
            kwargs['RequestID'] = request_id
            channel_name1 = self.__trade_response_format.format('OnRspQry' + query_type, request_id)
            channel_name2 = self.__trade_response_format.format('OnRspError', request_id)
            ch1, ch2 = await sub_client.psubscribe(channel_name1, channel_name2)
            cb = self.io_loop.create_future()
            tasks = [
                asyncio.ensure_future(self.query_reader(ch1, cb), loop=self.io_loop),
                asyncio.ensure_future(self.query_reader(ch2, cb), loop=self.io_loop),
            ]
            self.redis_client.publish(self.__request_format.format('ReqQry' + query_type), json.dumps(kwargs))
            rst = await asyncio.wait_for(cb, HANDLER_TIME_OUT, loop=self.io_loop)
            await sub_client.punsubscribe(channel_name1, channel_name2)
            sub_client.close()
            await asyncio.wait(tasks, loop=self.io_loop)
            return rst
        except Exception as e:
            logger.error('%s failed: %s', query_type, repr(e), exc_info=True)
            if sub_client and sub_client.in_pubsub and channel_name1:
                await sub_client.unsubscribe(channel_name1, channel_name2)
                sub_client.close()
            return None 
开发者ID:BigBrotherTrade,项目名称:trader,代码行数:32,代码来源:brother2.py

示例10: SubscribeMarketData

# 需要导入模块: import aioredis [as 别名]
# 或者: from aioredis import create_redis [as 别名]
def SubscribeMarketData(self, inst_ids: list):
        sub_client = None
        channel_name1, channel_name2 = None, None
        try:
            sub_client = await aioredis.create_redis(
                (config.get('REDIS', 'host', fallback='localhost'),
                 config.getint('REDIS', 'port', fallback=6379)),
                db=config.getint('REDIS', 'db', fallback=1))
            channel_name1 = self.__market_response_format.format('OnRspSubMarketData', 0)
            channel_name2 = self.__market_response_format.format('OnRspError', 0)
            ch1, ch2 = await sub_client.psubscribe(channel_name1, channel_name2)
            cb = self.io_loop.create_future()
            tasks = [
                asyncio.ensure_future(self.query_reader(ch1, cb), loop=self.io_loop),
                asyncio.ensure_future(self.query_reader(ch2, cb), loop=self.io_loop),
            ]
            self.redis_client.publish(self.__request_format.format('SubscribeMarketData'), json.dumps(inst_ids))
            rst = await asyncio.wait_for(cb, HANDLER_TIME_OUT, loop=self.io_loop)
            await sub_client.punsubscribe(channel_name1, channel_name2)
            sub_client.close()
            await asyncio.wait(tasks, loop=self.io_loop)
            return rst
        except Exception as e:
            logger.error('SubscribeMarketData failed: %s', repr(e), exc_info=True)
            if sub_client and sub_client.in_pubsub and channel_name1:
                await sub_client.unsubscribe(channel_name1, channel_name2)
                sub_client.close()
            return None 
开发者ID:BigBrotherTrade,项目名称:trader,代码行数:30,代码来源:brother2.py

示例11: UnSubscribeMarketData

# 需要导入模块: import aioredis [as 别名]
# 或者: from aioredis import create_redis [as 别名]
def UnSubscribeMarketData(self, inst_ids: list):
        sub_client = None
        channel_name1, channel_name2 = None, None
        try:
            sub_client = await aioredis.create_redis(
                (config.get('REDIS', 'host', fallback='localhost'),
                 config.getint('REDIS', 'port', fallback=6379)),
                db=config.getint('REDIS', 'db', fallback=1))
            channel_name1 = self.__market_response_format.format('OnRspUnSubMarketData', 0)
            channel_name2 = self.__market_response_format.format('OnRspError', 0)
            ch1, ch2 = await sub_client.psubscribe(channel_name1, channel_name2)
            cb = self.io_loop.create_future()
            tasks = [
                asyncio.ensure_future(self.query_reader(ch1, cb), loop=self.io_loop),
                asyncio.ensure_future(self.query_reader(ch2, cb), loop=self.io_loop),
            ]
            self.redis_client.publish(self.__request_format.format('UnSubscribeMarketData'), json.dumps(inst_ids))
            rst = await asyncio.wait_for(cb, HANDLER_TIME_OUT, loop=self.io_loop)
            await sub_client.punsubscribe(channel_name1, channel_name2)
            sub_client.close()
            await asyncio.wait(tasks, loop=self.io_loop)
            return rst
        except Exception as e:
            logger.error('SubscribeMarketData failed: %s', repr(e), exc_info=True)
            if sub_client and sub_client.in_pubsub and channel_name1:
                await sub_client.unsubscribe(channel_name1, channel_name2)
                sub_client.close()
            return None 
开发者ID:BigBrotherTrade,项目名称:trader,代码行数:30,代码来源:brother2.py

示例12: main

# 需要导入模块: import aioredis [as 别名]
# 或者: from aioredis import create_redis [as 别名]
def main():
    redis = await aioredis.create_redis(
        'redis://localhost')
    await redis.delete('foo', 'bar')
    tr = redis.multi_exec()
    fut1 = tr.incr('foo')
    fut2 = tr.incr('bar')
    res = await tr.execute()
    res2 = await asyncio.gather(fut1, fut2)
    print(res)
    assert res == res2

    redis.close()
    await redis.wait_closed() 
开发者ID:aio-libs,项目名称:aioredis,代码行数:16,代码来源:transaction.py

示例13: main

# 需要导入模块: import aioredis [as 别名]
# 或者: from aioredis import create_redis [as 别名]
def main():
    redis = await aioredis.create_redis(
        'redis://localhost')

    async def transaction():
        tr = redis.multi_exec()
        future1 = tr.set('foo', '123')
        future2 = tr.set('bar', '321')
        result = await tr.execute()
        assert result == await asyncio.gather(future1, future2)
        return result

    await transaction()
    redis.close()
    await redis.wait_closed() 
开发者ID:aio-libs,项目名称:aioredis,代码行数:17,代码来源:transaction2.py

示例14: main

# 需要导入模块: import aioredis [as 别名]
# 或者: from aioredis import create_redis [as 别名]
def main():
    """Scan command example."""
    redis = await aioredis.create_redis(
        'redis://localhost')

    await redis.mset('key:1', 'value1', 'key:2', 'value2')
    cur = b'0'  # set initial cursor to 0
    while cur:
        cur, keys = await redis.scan(cur, match='key:*')
        print("Iteration results:", keys)

    redis.close()
    await redis.wait_closed() 
开发者ID:aio-libs,项目名称:aioredis,代码行数:15,代码来源:scan.py

示例15: main

# 需要导入模块: import aioredis [as 别名]
# 或者: from aioredis import create_redis [as 别名]
def main():
    # Redis client bound to single connection (no auto reconnection).
    redis = await aioredis.create_redis(
        '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


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