# Path: feedhq/utils.py
# def get_redis_connection():
#     """
#     Helper used for obtain a raw redis client.
#     """
#     from redis_cache.cache import pool
#     client = redis.Redis(**settings.REDIS)
#     client.connection_pool = pool.get_connection_pool(
#         client,
#         parser_class=redis.connection.HiredisParser,
#         connection_pool_class=redis.ConnectionPool,
#         connection_pool_class_kwargs={},
#         **settings.REDIS)
#     return client


import json
import pytz
from datetime import timedelta
from django.conf import settings
from django.contrib.auth.models import (AbstractBaseUser, PermissionsMixin,
                                        UserManager)
from django.db import models
from django.db.models import Max
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from .. import es
from ..utils import get_redis_connection
                    'Starred items are not deleted.'))

    objects = UserManager()

    class Meta:
        db_table = 'auth_user'

    def get_short_name(self):
        return self.username

    @property
    def last_update_key(self):
        return 'user:{0}:updates'.format(self.pk)

    @property
    def wallabag_url(self):
        return json.loads(self.read_later_credentials)['wallabag_url']

    @property
    def unread_count(self):
        if hasattr(self, '_unread_count'):
            return self._unread_count
        return es.client.count(es.user_alias(self.pk),
                               doc_type='entries',
                               body={'query': {
                                   'term': {
                                       'read': False,
                                   }}})['count']

    def last_updates(self):

# Path: feedhq/utils.py
# def get_redis_connection():
#     """
#     Helper used for obtain a raw redis client.
#     """
#     from redis_cache.cache import pool
#     client = redis.Redis(**settings.REDIS)
#     client.connection_pool = pool.get_connection_pool(
#         client,
#         parser_class=redis.connection.HiredisParser,
#         connection_pool_class=redis.ConnectionPool,
#         connection_pool_class_kwargs={},
#         **settings.REDIS)
#     return client


# Path: feedhq/profiles/models.py
import json
import pytz
from datetime import timedelta
from django.conf import settings
from django.contrib.auth.models import (AbstractBaseUser, PermissionsMixin,
                                        UserManager)
from django.db import models
from django.db.models import Max
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from .. import es
from ..utils import get_redis_connection

                    'Starred items are not deleted.'))

    objects = UserManager()

    class Meta:
        db_table = 'auth_user'

    def get_short_name(self):
        return self.username

    @property
    def last_update_key(self):
        return 'user:{0}:updates'.format(self.pk)

    @property
    def wallabag_url(self):
        return json.loads(self.read_later_credentials)['wallabag_url']

    @property
    def unread_count(self):
        if hasattr(self, '_unread_count'):
            return self._unread_count
        return es.client.count(es.user_alias(self.pk),
                               doc_type='entries',
                               body={'query': {
                                   'term': {
                                       'read': False,
                                   }}})['count']

    def last_updates(self):

        redis = get_redis_connection()