Completed
Push — master ( 95d8d5...80ebcd )
by Ionel Cristian
6s
created

RedisCache.__client()   A

Complexity

Conditions 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 2
dl 0
loc 8
rs 9.4285
1
from django_redis.cache import RedisCache as PlainRedisCache
2
3
from redis_lock import Lock
4
from redis_lock import reset_all
5
6
7
class RedisCache(PlainRedisCache):
8
9
    @property
10
    def __client(self):
11
        try:
12
            return self.client.get_client()
13
        except Exception as exc:
14
            raise NotImplementedError(
15
                "RedisCache doesn't have a raw client: %r. "
16
                "Use 'redis_cache.client.DefaultClient' as the CLIENT_CLASS !" % exc
17
            )
18
19
    def lock(self, key, expire=None, id=None):
20
        return Lock(self.__client, key, expire=expire, id=id)
21
22
    def reset_all(self):
23
        """
24
        Forcibly deletes all locks if its remains (like a crash reason). Use this with care.
25
        """
26
        reset_all(self.__client)
27