def q(request):
    # print request.get('md5Str')
    print request.GET['md5Str']
    _md5 = request.GET['md5Str']

    a = Ins.objects.filter(md5=_md5).exclude()
    if len(a) > 0:
        print a[0].url
        url = a[0].url

    _redis_ = _redis.RedisC()
    r = _redis_._redis_()
    print url
    redisData = _get_redis_task(url)
    print redisData
    if redisData is not None:
        return render(redisData, _md5, url)
    else:
        # _write_redis_status('ins',url)
        r.rpush('ins', url)
        redisData = None
        # print  _get_redis_task(url)
        while redisData == None:
            redisData = _get_redis_task(url)
            print redisData
            if redisData is not None:
                return render(redisData, _md5, url)
def getOriginData(request):
    url = request.GET['url']
    print url
    redisData = _get_redis_task(url)
    isVideo = 'mp4' in url
    isImage = 'png' in url or 'jpg' in url or 'jpeg' in url
    print isVideo, isImage
    # print redisData
    print '--------------'
    if redisData is not None:
        contentType = ''
        if isVideo:
            contentType = 'video/mp4'
        elif isImage:
            contentType = 'image/jpeg'
        return HttpResponse(redisData, content_type=contentType)
    else:
        # _write_redis_status('ins',url)
        _redis_ = _redis.RedisC()
        r = _redis_._redis_()
        r.rpush('ins', url)
        redisData = None
        # print  _get_redis_task(url)
        startTime = time.time()
        endTime = time.time()
        while redisData == None and (endTime - startTime) < 8:
            redisData = _get_redis_task(url)
            # print redisData
            if redisData is not None:
                contentType = ''
                if isVideo:
                    contentType = 'video/mp4'
                elif isImage:
                    contentType = 'image/jpeg'
                return HttpResponse(redisData, content_type=contentType)
            endTime = time.time()
def _write_redis_status(key, content):
    _redis_ = _redis.RedisC()
    r = _redis_._redis_()
    r.set(key, content)
def _get_redis_task(key):
    _redis_ = _redis.RedisC()
    r = _redis_._redis_()
    return r.get(key)
def _redis_push(key, values):
    _redis_ = _redis.RedisC()
    r = _redis_._redis_()
    return r.rpush(key, values)