# coding=utf8

from __future__ import unicode_literals, absolute_import, print_function

from .base import take_sofa_diary_cache


class TakeSofaCache(object):
    """cache take sofa diary and topics"""

    TAKE_SOFA_DIARY_ZSET = 'take_sofa:diary_zset'

    def get_diary_cache_data(self, start_num=0, count=10):
        return take_sofa_diary_cache.zrevrange(TakeSofaCache.TAKE_SOFA_DIARY_ZSET, start_num, count)

    def set_diary_cache_data(self, score=0, diary_id=0):
        take_sofa_diary_cache.zadd(TakeSofaCache.TAKE_SOFA_DIARY_ZSET, score, diary_id)

    def del_diary_cache_data(self, diary_id=0):
        take_sofa_diary_cache.zrem(TakeSofaCache.TAKE_SOFA_DIARY_ZSET, diary_id)

    def del_diary_all_cache(self, first_rank, last_rank):
        take_sofa_diary_cache.zremrangebyrank(TakeSofaCache.TAKE_SOFA_DIARY_ZSET, first_rank, last_rank)


take_sofa_cache = TakeSofaCache()