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

import redis
from django.conf import settings


class _PoolMinx(object):
    pool = redis.ConnectionPool(**settings.REDIS['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)

