# -*- coding: UTF-8 -*-
import redis
from django.conf import settings
from utils.common import big_data_iter


class _PoolMinx(object):
    # pool = redis.ConnectionPool(**settings.REDIS['view'])
    pool = redis.ConnectionPool(**settings.REDIS_TOPIC_1ST['view'])
    client = redis.Redis(connection_pool=pool)


class ViewRecord(_PoolMinx):
    def __init__(self, model_name):
        self.model_name = model_name

    def __getitem__(self, item):
        return self.client.hget(self.model_name, item) or 0

    def __setitem__(self, key, value):
        return self.client.hset(self.model_name, key, value)

    def view_hmget(self, item_list):
        result = []
        for _ids in big_data_iter(item_list):
            _vs = self.client.hmget(self.model_name, _ids)
            result.extend(_vs)
        return result
