示例#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
示例#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
示例#3
0
 def rename(self, old_name, new_name):
     """Rename key to a new name."""
     try:
         self.api.rename(mkey(old_name), mkey(new_name))
     except ResponseError, exc:
         if "no such key" in exc.args:
             raise KeyError(old_name)
         raise
示例#4
0
 def rename(self, old_name, new_name):
     """Rename key to a new name."""
     try:
         self.api.rename(mkey(old_name), mkey(new_name))
     except ResponseError, exc:
         if "no such key" in exc.args:
             raise KeyError(old_name)
         raise
示例#5
0
 def __getitem__(self, name):
     """``x.__getitem__(name) <==> x[name]``"""
     name = mkey(name)
     value = self.api.get(name)
     if value is None:
         raise KeyError(name)
     return self.value_to_python(value)
示例#6
0
 def __getitem__(self, name):
     """``x.__getitem__(name) <==> x[name]``"""
     name = mkey(name)
     value = self.api.get(name)
     if value is None:
         raise KeyError(name)
     return self.value_to_python(value)
示例#7
0
 def __contains__(self, name):
     """``x.__contains__(name) <==> name in x``"""
     return self.api.exists(mkey(name))
示例#8
0
 def __delitem__(self, name):
     """``x.__delitem__(name) <==> del(x[name])``"""
     name = mkey(name)
     if not self.api.delete(name):
         raise KeyError(name)
示例#9
0
 def __setitem__(self, name, value):
     """``x.__setitem(name, value) <==> x[name] = value``"""
     return self.api.set(mkey(name), self.prepare_value(value))
示例#10
0
 def __contains__(self, name):
     """``x.__contains__(name) <==> name in x``"""
     return self.api.exists(mkey(name))
示例#11
0
 def __delitem__(self, name):
     """``x.__delitem__(name) <==> del(x[name])``"""
     name = mkey(name)
     if not self.api.delete(name):
         raise KeyError(name)
示例#12
0
 def __setitem__(self, name, value):
     """``x.__setitem(name, value) <==> x[name] = value``"""
     return self.api.set(mkey(name), self.prepare_value(value))
示例#13
0
 def test_mkey(self):
     self.assertEqual(utils.mkey("foo"), "foo")
     self.assertEqual(utils.mkey("foo:bar"), "foo:bar")
     self.assertEqual(utils.mkey(("foo", "bar", "baz")), "foo:bar:baz")
     self.assertEqual(utils.mkey(["foo", "bar", "baz"]), "foo:bar:baz")
示例#14
0
 def __init__(self, name, client):
     self.name = mkey(name)
     self.client = client
示例#15
0
 def __init__(self, name, client):
     self.name = mkey(name)
     self.client = client
示例#16
0
 def test_mkey(self):
     self.assertEqual(utils.mkey("foo"), "foo")
     self.assertEqual(utils.mkey("foo:bar"), "foo:bar")
     self.assertEqual(utils.mkey(("foo", "bar", "baz")), "foo:bar:baz")
     self.assertEqual(utils.mkey(["foo", "bar", "baz"]), "foo:bar:baz")