> unlink key OK
> flushall async OK
from collections import OrderedDict class LRUDict(OrderedDict): def __init__(self, capacity): self.capacity = capacity self.items = OrderedDict() def __setitem__(self, key, value): old_value = self.items.get(key) if old_value is not None: self.items.pop(key) self.items[key] = value elif len(self.items) < self.capacity: self.items[key] = value else: self.items.popitem(last=True) self.items[key] = value def __getitem__(self, key): value = self.items.get(key) if value is not None: self.items.pop(key) self.items[key] = value return value def __repr__(self): return repr(self.items) d = LRUDict(10) for i in range(15): d[i] = i print d
// redis 的对象头 typedef struct redisObject { unsigned type:4; // 对象类型如 zset/set/hash 等等 unsigned encoding:4; // 对象编码如 ziplist/intset/skiplist 等等 unsigned lru:24; // 对象的「热度」 int refcount; // 引用计数 void *ptr; // 对象的 body } robj;