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


Python RedisManager.get方法代码示例

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


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

示例1: upgrade

# 需要导入模块: from pajbot.managers import RedisManager [as 别名]
# 或者: from pajbot.managers.RedisManager import get [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

示例2: test

# 需要导入模块: from pajbot.managers import RedisManager [as 别名]
# 或者: from pajbot.managers.RedisManager import get [as 别名]
def test():
    redis = RedisManager.get()
    current_quest_key = '{streamer}:current_quest'.format(streamer=StreamHelper.get_streamer())
    current_quest_id = redis.get(current_quest_key)
    current_quest = module_manager[current_quest_id]
    current_quest.load_data()
    return render_template('test.html', current_quest=current_quest)
开发者ID:kzf,项目名称:pajbot,代码行数:9,代码来源:app.py

示例3: on_stream_stop

# 需要导入模块: from pajbot.managers import RedisManager [as 别名]
# 或者: from pajbot.managers.RedisManager import get [as 别名]
    def on_stream_stop(self):
        if self.current_quest is None:
            log.info('No quest active on stream stop.')
            return False

        self.current_quest.stop_quest()
        self.current_quest = None
        self.bot.say('Stream ended, quest has been reset.')

        redis = RedisManager.get()

        # Remove any mentions of the current quest
        redis.delete(self.current_quest_key)

        last_stream_id = StreamHelper.get_last_stream_id()
        if last_stream_id is False:
            log.error('No last stream ID found.')
            # No last stream ID found. why?
            return False

        # XXX: Should we use a pipeline for any of this?
        # Go through user tokens and remove any from more than 2 streams ago
        for key in redis.keys('{streamer}:*:tokens'.format(streamer=StreamHelper.get_streamer())):
            all_tokens = redis.hgetall(key)
            for stream_id_str in all_tokens:
                try:
                    stream_id = int(stream_id_str)
                except (TypeError, ValueError):
                    log.error('Invalid stream id in tokens by {}'.format(key))
                    continue

                if last_stream_id - stream_id > 1:
                    log.info('Removing tokens for stream {}'.format(stream_id))
                    redis.hdel(key, stream_id)
开发者ID:kyroskoh,项目名称:pajbot,代码行数:36,代码来源:quest.py

示例4: on_duel_complete

# 需要导入模块: from pajbot.managers import RedisManager [as 别名]
# 或者: from pajbot.managers.RedisManager import get [as 别名]
    def on_duel_complete(self, winner, loser, points_won, points_bet):
        if points_won < 1:
            # This duel did not award any points.
            # That means it's entirely irrelevant to us
            return

        if winner.username in self.progress:
            total_points_won = self.progress[winner.username]

            if total_points_won >= self.points_required:
                # The user has already won enough points, and been rewarded already.
                return
        else:
            total_points_won = 0

        # If we get here, this means the user has not completed the quest yet.
        # And the user won some points in this duel
        total_points_won += points_won

        redis = RedisManager.get()

        if total_points_won >= self.points_required:
            # Reward the user with some tokens
            winner.award_tokens(self.REWARD, redis=redis)

        # Save the users "points won" progress
        self.progress[winner.username] = total_points_won
        redis.hset(self.progress_key, winner.username, total_points_won)
开发者ID:SnackMcOgrelord,项目名称:pajbot,代码行数:30,代码来源:winduelpoints.py

示例5: start_quest

# 需要导入模块: from pajbot.managers import RedisManager [as 别名]
# 或者: from pajbot.managers.RedisManager import get [as 别名]
    def start_quest(self):
        HandlerManager.add_handler('on_duel_complete', self.on_duel_complete)

        redis = RedisManager.get()

        self.progress = {}
        old_progress = redis.hgetall(self.progress_key)
        for user, progress in old_progress.items():
            try:
                self.progress[user.decode('utf8')] = int(progress)
            except (TypeError, ValueError):
                pass

        self.points_required = redis.get(self.points_required_key)
        try:
            self.points_required = int(self.points_required)
        except (TypeError, ValueError):
            pass
        if self.points_required is None:
            try:
                self.points_required = random.randint(self.settings['min_value'], self.settings['max_value'] + 1)
            except ValueError:
                # someone fucked up
                self.points_required = 500
            redis.set(self.points_required_key, self.points_required)
开发者ID:SnackMcOgrelord,项目名称:pajbot,代码行数:27,代码来源:winduelpoints.py

示例6: start_quest

# 需要导入模块: from pajbot.managers import RedisManager [as 别名]
# 或者: from pajbot.managers.RedisManager import get [as 别名]
    def start_quest(self):
        HandlerManager.add_handler('on_message', self.on_message)

        redis = RedisManager.get()

        self.load_progress(redis=redis)
        self.load_data(redis=redis)
开发者ID:kyroskoh,项目名称:pajbot,代码行数:9,代码来源:typeemote.py

示例7: get_follow_relationship

# 需要导入模块: from pajbot.managers import RedisManager [as 别名]
# 或者: from pajbot.managers.RedisManager import get [as 别名]
    def get_follow_relationship(self, username, streamer):
        """Returns the follow relationship between the user and a streamer.

        Returns False if `username` is not following `streamer`.
        Otherwise, return a datetime object.

        This value is cached in Redis for 2 minutes.
        """

        redis = RedisManager.get()

        fr_key = "fr_{username}_{streamer}".format(username=username, streamer=streamer)
        follow_relationship = redis.get(fr_key)

        if follow_relationship is None:
            try:
                data = self.get(endpoints=["users", username, "follows", "channels", streamer], base=self.kraken_url)
                created_at = data["created_at"]
                redis.setex(fr_key, time=120, value=created_at)
                return TwitchAPI.parse_datetime(created_at)
            except urllib.error.HTTPError:
                redis.setex(fr_key, time=120, value="-1")
                return False
            except:
                log.exception("Unhandled exception in get_follow_relationship")
                return False
        else:
            if follow_relationship == b"-1":
                return False
            else:
                return TwitchAPI.parse_datetime(follow_relationship.decode("utf-8"))
开发者ID:gigglearrows,项目名称:pajbot,代码行数:33,代码来源:apiwrappers.py

示例8: stop_quest

# 需要导入模块: from pajbot.managers import RedisManager [as 别名]
# 或者: from pajbot.managers.RedisManager import get [as 别名]
    def stop_quest(self):
        HandlerManager.remove_handler('on_message', self.on_message)

        redis = RedisManager.get()

        self.reset_progress(redis=redis)
        redis.delete(self.current_emote_key)
开发者ID:kyroskoh,项目名称:pajbot,代码行数:9,代码来源:typeemote.py

示例9: progress_quest

# 需要导入模块: from pajbot.managers import RedisManager [as 别名]
# 或者: from pajbot.managers.RedisManager import get [as 别名]
    def progress_quest(self, amount, limit, completion_reward):
        """ Progress the quest for `stream_id` by `amount`.
        We load data from redis in case no progress has been made yet.
        """
        streamer = StreamHelper.get_streamer()
        stream_id = StreamHelper.get_current_stream_id()

        if stream_id is False:
            return False

        redis = RedisManager.get()
        quest_progress_key = '{streamer}:{stream_id}:{username}:quest_progress'.format(
                streamer=streamer,
                stream_id=stream_id,
                username=self.username)

        if stream_id not in self.quest_progress:
            # Load the old progress, or set it to 0 if no progress was found
            self.init_quest_progress()

        if self.quest_progress[stream_id] >= limit:
            # The user has already completed this quest.
            return False

        self.quest_progress[stream_id] += amount

        if self.quest_progress[stream_id] >= limit:
            # The user just completed the quest for the first time
            self.award_tokens(completion_reward, redis=redis)
            return False

        redis.set(quest_progress_key, self.quest_progress[stream_id])
开发者ID:ManikDV,项目名称:pajbot,代码行数:34,代码来源:user.py

示例10: stop_quest

# 需要导入模块: from pajbot.managers import RedisManager [as 别名]
# 或者: from pajbot.managers.RedisManager import get [as 别名]
    def stop_quest(self):
        HandlerManager.remove_handler('on_duel_complete', self.on_duel_complete)

        redis = RedisManager.get()

        self.reset_progress(redis=redis)
        redis.delete(self.points_required_key)
开发者ID:Nacht123,项目名称:pajbot,代码行数:9,代码来源:winduelpoints.py

示例11: get_follow_relationship

# 需要导入模块: from pajbot.managers import RedisManager [as 别名]
# 或者: from pajbot.managers.RedisManager import get [as 别名]
    def get_follow_relationship(self, username, streamer):
        """Returns the follow relationship between the user and a streamer.

        Returns False if `username` is not following `streamer`.
        Otherwise, return a datetime object.

        This value is cached in Redis for 2 minutes.
        """

        redis = RedisManager.get()

        fr_key = 'fr_{username}_{streamer}'.format(username=username, streamer=streamer)
        follow_relationship = redis.get(fr_key)

        if follow_relationship is None:
            try:
                data = self.get(endpoints=['users', username, 'follows', 'channels', streamer], base=self.kraken_url)
                created_at = data['created_at']
                redis.setex(fr_key, time=120, value=created_at)
                return TwitchAPI.parse_datetime(created_at)
            except urllib.error.HTTPError:
                redis.setex(fr_key, time=120, value='-1')
                return False
            except:
                log.exception('Unhandled exception in get_follow_relationship')
                return False
        else:
            if follow_relationship == '-1':
                return False
            else:
                return TwitchAPI.parse_datetime(follow_relationship)
开发者ID:kzf,项目名称:pajbot,代码行数:33,代码来源:apiwrappers.py

示例12: timeout

# 需要导入模块: from pajbot.managers import RedisManager [as 别名]
# 或者: from pajbot.managers.RedisManager import get [as 别名]
    def timeout(self, timeout_length, warning_module=None, use_warnings=True):
        """ Returns a tuple with the follow data:
        How long to timeout the user for, and what the punishment string is
        set to.
        The punishment string is used to clarify whether this was a warning or the real deal.
        """

        punishment = 'timed out for {} seconds'.format(timeout_length)

        if use_warnings and warning_module is not None:
            redis = RedisManager.get()

            """ How many chances the user has before receiving a full timeout. """
            total_chances = warning_module.settings['total_chances']

            warning_keys = self.get_warning_keys(total_chances, warning_module.settings['redis_prefix'])
            warnings = self.get_warnings(redis, warning_keys)

            chances_used = self.get_chances_used(warnings)

            if chances_used < total_chances:
                """ The user used up one of his warnings.
                Calculate for how long we should time him out. """
                timeout_length = warning_module.settings['base_timeout'] * (chances_used + 1)
                punishment = 'timed out for {} seconds (warning)'.format(timeout_length)

                self.add_warning(redis, warning_module.settings['length'], warning_keys, warnings)

        return (timeout_length, punishment)
开发者ID:gigglearrows,项目名称:pajbot,代码行数:31,代码来源:user.py

示例13: award_tokens

# 需要导入模块: from pajbot.managers import RedisManager [as 别名]
# 或者: from pajbot.managers.RedisManager import get [as 别名]
    def award_tokens(self, tokens, redis=None, force=False):
        """ Returns True if tokens were awarded properly.
        Returns False if not.
        Tokens can only be rewarded once per stream ID.
        """

        streamer = StreamHelper.get_streamer()
        stream_id = StreamHelper.get_current_stream_id()

        if stream_id is False:
            return False

        if redis is None:
            redis = RedisManager.get()

        key = '{streamer}:{username}:tokens'.format(
                streamer=streamer, username=self.username)

        if force:
            res = True
            redis.hset(key, stream_id, tokens)
        else:
            res = True if redis.hsetnx(key, stream_id, tokens) == 1 else False
            if res is True:
                HandlerManager.trigger('on_user_gain_tokens', self, tokens)
        return res
开发者ID:kyroskoh,项目名称:pajbot,代码行数:28,代码来源:user.py

示例14: spend_tokens

# 需要导入模块: from pajbot.managers import RedisManager [as 别名]
# 或者: from pajbot.managers.RedisManager import get [as 别名]
    def spend_tokens(self, tokens_to_spend, redis=None):
        if redis is None:
            redis = RedisManager.get()

        user_token_key = '{streamer}:{username}:tokens'.format(
                streamer=StreamHelper.get_streamer(), username=self.username)

        token_dict = redis.hgetall(user_token_key)

        for stream_id in token_dict:
            try:
                num_tokens = int(token_dict[stream_id])
            except (TypeError, ValueError):
                continue

            if num_tokens == 0:
                continue

            decrease_by = min(tokens_to_spend, num_tokens)
            tokens_to_spend -= decrease_by
            num_tokens -= decrease_by

            redis.hset(user_token_key, stream_id, num_tokens)

            if tokens_to_spend == 0:
                return True

        return False
开发者ID:kyroskoh,项目名称:pajbot,代码行数:30,代码来源:user.py

示例15: get_tags

# 需要导入模块: from pajbot.managers import RedisManager [as 别名]
# 或者: from pajbot.managers.RedisManager import get [as 别名]
 def get_tags(self, redis=None):
     if redis is None:
         redis = RedisManager.get()
     val = redis.hget('global:usertags', self.username)
     if val:
         return json.loads(val)
     else:
         return {}
开发者ID:TalVivian,项目名称:pajbot,代码行数:10,代码来源:user.py


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