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


Python RedisManager.pipeline_context方法代码示例

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


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

示例1: update_chatters_stage2

# 需要导入模块: from pajbot.managers import RedisManager [as 别名]
# 或者: from pajbot.managers.RedisManager import pipeline_context [as 别名]
    def update_chatters_stage2(self, chatters):
        points = 1 if self.bot.is_online else 0

        log.debug('Updating {0} chatters'.format(len(chatters)))

        self.bot.stream_manager.update_chatters(chatters, self.update_chatters_interval)

        with RedisManager.pipeline_context() as pipeline:
            with DBManager.create_session_scope() as db_session:
                user_models = UserManager.get().bulk_load_user_models(chatters, db_session)
                users = []
                for username in chatters:
                    user_model = user_models.get(username, None)
                    user = UserManager.get().get_user(username, db_session=db_session, user_model=user_model, redis=pipeline)
                    users.append(user)

                more_update_data = {}
                if self.bot.is_online:
                    more_update_data['minutes_in_chat_online'] = self.update_chatters_interval
                else:
                    more_update_data['minutes_in_chat_offline'] = self.update_chatters_interval

                points_to_give_out = {}
                dt_now = datetime.datetime.now().timestamp()
                for user in users:
                    user._set_last_seen(dt_now)

                    num_points = points
                    if user.subscriber:
                        num_points *= 5
                    # TODO: Load user tags during the pipeline redis data fetch
                    if self.bot.streamer == 'forsenlol' and 'trumpsc_sub' in user.get_tags():
                        num_points *= 0.5

                    num_points = int(num_points)

                    if num_points not in points_to_give_out:
                        points_to_give_out[num_points] = []

                    points_to_give_out[num_points].append(user.username)

                    user.save(save_to_db=False)

                for num_points, usernames in points_to_give_out.items():
                    payload = {
                            User.points: User.points + num_points,
                            }
                    if self.bot.is_online:
                        payload[User.minutes_in_chat_online] = User.minutes_in_chat_online + self.update_chatters_interval
                    else:
                        payload[User.minutes_in_chat_offline] = User.minutes_in_chat_offline + self.update_chatters_interval
                    db_session.query(User).filter(User.username.in_(usernames)).\
                            update(payload, synchronize_session=False)

                pipeline.execute()
开发者ID:Nacht123,项目名称:pajbot,代码行数:57,代码来源:chatters.py

示例2: upgrade

# 需要导入模块: from pajbot.managers import RedisManager [as 别名]
# 或者: from pajbot.managers.RedisManager import pipeline_context [as 别名]
def upgrade():
    bind = op.get_bind()
    session = Session(bind=bind)

    config_data = RedisManager.get().config_get('maxmemory')
    max_memory = config_data['maxmemory']
    print('redis max memory: {}'.format(max_memory))
    RedisManager.get().config_set('maxmemory', str(int(max_memory) * 10))
    with RedisManager.pipeline_context() as pipeline:
        streamer = pb_config['main']['streamer']

        num_lines_key = '{streamer}:users:num_lines'.format(streamer=streamer)
        ignored_key = '{streamer}:users:ignored'.format(streamer=streamer)
        last_active_key = '{streamer}:users:last_active'.format(streamer=streamer)
        last_seen_key = '{streamer}:users:last_seen'.format(streamer=streamer)
        banned_key = '{streamer}:users:banned'.format(streamer=streamer)
        username_raw_key = '{streamer}:users:username_raw'.format(streamer=streamer)
        pipeline.delete(num_lines_key, ignored_key, last_active_key, last_seen_key, banned_key, username_raw_key)

        for user in session.query(User):
            if user.num_lines > 0:
                pipeline.zadd(num_lines_key, user.username, user.num_lines)

            if user.ignored:
                pipeline.hset(ignored_key, user.username, 1)

            if user.banned:
                pipeline.hset(banned_key, user.username, 1)

            if user.username != user.username_raw:
                pipeline.hset(username_raw_key, user.username, user.username_raw)

            if user._last_seen:
                pipeline.hset(last_seen_key, user.username, user._last_seen.timestamp())

            if user._last_active:
                pipeline.hset(last_active_key, user.username, user._last_active.timestamp())

    RedisManager.get().config_set('maxmemory', int(max_memory))

    ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('tb_user') as batch_op:
        batch_op.drop_column('num_lines')
        batch_op.drop_column('ignored')
        batch_op.drop_column('last_active')
        batch_op.drop_column('last_seen')
        batch_op.drop_column('banned')
    ### end Alembic commands ###

    session.commit()
开发者ID:Nacht123,项目名称:pajbot,代码行数:52,代码来源:f7182019343e_moved_some_columns_from_tb_user_into_.py

示例3: upgrade

# 需要导入模块: from pajbot.managers import RedisManager [as 别名]
# 或者: from pajbot.managers.RedisManager import pipeline_context [as 别名]
def upgrade():
    bind = op.get_bind()
    session = Session(bind=bind)

    with RedisManager.pipeline_context() as pipeline:
        streamer = pb_config['main']['streamer']
        count_key = '{streamer}:emotes:count'.format(streamer=streamer)
        epmrecord_key = '{streamer}:emotes:epmrecord'.format(streamer=streamer)
        pipeline.delete(count_key, epmrecord_key)
        for emote in session.query(Emote):
            if emote.stats:
                pipeline.zincrby(count_key, emote.code, emote.stats.count)
                pipeline.zincrby(epmrecord_key, emote.code, emote.stats.tm_record)

    op.drop_table('tb_emote_stats')
    op.drop_table('tb_emote')
开发者ID:TalVivian,项目名称:pajbot,代码行数:18,代码来源:34d6f5a24cbe_remove_emote_tables.py


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