Ticket #6464: 6464.memcached.incr.decr.diff

File 6464.memcached.incr.decr.diff, 973 bytes (added by Pete Crosier, 17 years ago)

Adds decr and incr support to the memcached backend

  • django/core/cache/backends/memcached.py

     
    3939
    4040    def get_many(self, keys):
    4141        return self._cache.get_multi(map(smart_str,keys))
     42
     43    def decr(self, key, delta=1):
     44        val = self._cache.get(smart_str(key))
     45        if val is None:
     46            return None
     47        else:
     48            if isinstance(val, int) and isinstance(delta, int):
     49                return self._cache.decr(key, delta)
     50            else:
     51                return val
     52
     53    def incr(self, key, delta=1):
     54        val = self._cache.get(smart_str(key))
     55        if val is None:
     56            return None
     57        else:
     58            if isinstance(val, int) and isinstance(delta, int):
     59                return self._cache.incr(key, delta)
     60            else:
     61                return val
Back to Top