# -*- coding: utf-8 -*-

from utils.redis.connect import r
from utils.redis.rkeys import LATEST_APP_INFO


def set_latest_app(src=0):
    """ 设置最新 APP 信息 """
    from operation.models import LatestAppInfo
    try:
        appinfo = LatestAppInfo.objects.filter(src=src, status=True)[0].data
    except IndexError:
        appinfo = {}
    r.setjson(LATEST_APP_INFO % src, appinfo)
    return appinfo


def get_latest_app(src=0):
    """ 获取最新 APP 信息 """
    return r.getjson(LATEST_APP_INFO % src) or set_latest_app(src)
