Example #1
0
 def _prune(self, now: int, timestamps: Sequence[bytes]) -> None:
     """
     Removes old timestamps from the Redis hash
     """
     oldest_time = now - self.__seconds
     old_timestamps = [k for k in timestamps if int(k) < oldest_time]
     if old_timestamps:
         redis_client.hdel(self.__name, *old_timestamps)
Example #2
0
def set_config(key: str, value: Optional[Any], user: Optional[str] = None) -> None:
    if value is not None:
        value = "{}".format(value).encode("utf-8")

    try:
        original_value = rds.hget(config_hash, key)
        if value == original_value:
            return

        change_record = (time.time(), user, original_value, value)
        if value is None:
            rds.hdel(config_hash, key)
            rds.hdel(config_history_hash, key)
        else:
            rds.hset(config_hash, key, value)
            rds.hset(config_history_hash, key, json.dumps(change_record))
        rds.lpush(config_changes_list, json.dumps((key, change_record)))
        rds.ltrim(config_changes_list, 0, config_changes_list_limit)
    except Exception as ex:
        logger.exception(ex)