#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
__title__ = ''
__author__ = 'xierong@gmei.com'
__mtime__ = '17/12/28'
'''
from celery import shared_task
from talos.cache.viewrecord import ViewRecord
from six.moves import xrange

def view_increase_amount(model_name, id_value, count, reverse=False):
    for _ in xrange(count):
        view_increase(model_name, id_value, reverse)


@shared_task
def view_increase(model_name, id_value, reverse=False):
    """

    :param model_name:
    :param id_value:
    :param reverse: 相反的，做减法
    :return:
    """
    view = ViewRecord(model_name)
    if reverse:
        view[id_value] = int(view[id_value] or '1') - 1
    else:
        view[id_value] = int(view[id_value] or '0') + 1

    return view[id_value]

