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

RedisCache   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %
Metric Value
dl 0
loc 20
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __client() 0 8 2
A reset_all() 0 5 1
A lock() 0 2 1
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