Esempio 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
Esempio 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
Esempio 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
Esempio 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
Esempio 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)
Esempio 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)
Esempio 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
Esempio 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
Esempio n. 9
0
 def __init__(self, name, client):
     self.name = mkey(name)
     self.client = client
Esempio n. 10
0
 def __contains__(self, name):
     """``x.__contains__(name) <==> name in x``"""
     return self.api.exists(mkey(name))
Esempio 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))
Esempio 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))
Esempio n. 13
0
 def __contains__(self, name):
     """``x.__contains__(name) <==> name in x``"""
     return self.api.exists(mkey(name))
Esempio 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))
Esempio 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))