Ejemplo n.º 1
0
 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
Ejemplo n.º 2
0
 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
Ejemplo n.º 3
0
 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
Ejemplo n.º 4
0
 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
Ejemplo n.º 5
0
 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)
Ejemplo n.º 6
0
 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)
Ejemplo n.º 7
0
 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
Ejemplo n.º 8
0
 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
Ejemplo n.º 9
0
 def __init__(self, name, client):
     self.name = mkey(name)
     self.client = client
Ejemplo n.º 10
0
 def __contains__(self, name):
     """``x.__contains__(name) <==> name in x``"""
     return self.api.exists(mkey(name))
Ejemplo n.º 11
0
 def __setitem__(self, name, value):
     """``x.__setitem(name, value) <==> x[name] = value``"""
     return self.api.set(mkey(name), self.prepare_value(value))
Ejemplo n.º 12
0
 def set(self, name, value):
     """x.set(name, value) <==> x[name] = value"""
     return self.api.set(mkey(name), self.prepare_value(value))
Ejemplo n.º 13
0
 def __contains__(self, name):
     """``x.__contains__(name) <==> name in x``"""
     return self.api.exists(mkey(name))
Ejemplo n.º 14
0
 def __setitem__(self, name, value):
     """``x.__setitem(name, value) <==> x[name] = value``"""
     return self.api.set(mkey(name), self.prepare_value(value))
Ejemplo n.º 15
0
 def set(self, name, value):
     """x.set(name, value) <==> x[name] = value"""
     return self.api.set(mkey(name), self.prepare_value(value))