def pop(self, name): """Get and remove key from database (atomic).""" name = mkey(name) temp = mkey((name, "__poptmp__")) self.rename(name, temp) value = self[temp] del (self[temp]) return value
def pop(self, name): """Get and remove key from database (atomic).""" name = mkey(name) temp = mkey((name, "__poptmp__")) self.rename(name, temp) value = self[temp] del(self[temp]) return value
def rename(self, old_name, new_name): """重命名redis的key Args: old_name: 旧版本key new_name: 新key Returns: False: 如果key不存在 True: key存在并且设置成功 """ try: self.api.rename(mkey(old_name), mkey(new_name)) return True except ResponseError as exc: LOG.error("zyredis rename error, error info=%s", exc) return False
def __getitem__(self, name): """``x.__getitem__(name) <==> x[name]``""" name = mkey(name) value = self.api.get(name) if value is None: return None return self.value_to_python(value)
def __delitem__(self, name): """``x.__delitem__(name) <==> del(x[name])`` Returns: True: delete success False: key is not exists """ name = mkey(name) if not self.api.delete(name): return False return True
def __init__(self, name, client): self.name = mkey(name) self.client = client
def __contains__(self, name): """``x.__contains__(name) <==> name in x``""" return self.api.exists(mkey(name))
def __setitem__(self, name, value): """``x.__setitem(name, value) <==> x[name] = value``""" return self.api.set(mkey(name), self.prepare_value(value))
def set(self, name, value): """x.set(name, value) <==> x[name] = value""" return self.api.set(mkey(name), self.prepare_value(value))