Пример #1
0
 def get(self, key):
     """
     Retrieves a certain value for a given key
     """
     try:
         return json.loads(ArakoonStore._try(self._client.get, key))
     except ValueError:
         raise KeyNotFoundException('Could not parse JSON stored for {0}'.format(key))
     except ArakoonNotFound as field:
         raise KeyNotFoundException(field)
Пример #2
0
 def get_multi(self, keys):
     """
     Get multiple keys at once
     """
     try:
         for item in PyrakoonStore._try(self._identifier,
                                        self._client.multiGet, keys):
             yield ujson.loads(item)
     except ValueError:
         raise KeyNotFoundException('Could not parse JSON stored')
     except ArakoonNotFound as field:
         raise KeyNotFoundException(field.message)
Пример #3
0
 def delete(self, key):
     """
     Deletes a given key from the store
     """
     try:
         return ArakoonStore._try(self._client.delete, key)
     except ArakoonNotFound as field:
         raise KeyNotFoundException(field)
Пример #4
0
 def get(self, key):
     """
     Retrieves a certain value for a given key
     """
     data = self._read()
     if key in data:
         return self._read()[key]
     else:
         raise KeyNotFoundException(key)
Пример #5
0
 def delete(self, key):
     """
     Deletes a given key from the store
     """
     data = self._read()
     if key in data:
         del data[key]
         self._save(data)
     else:
         raise KeyNotFoundException(key)
Пример #6
0
 def get_multi(self, keys):
     """
     Retrieves values for all given keys
     """
     data = self._read()
     for key in keys:
         if key in data:
             yield copy.deepcopy(data[key])
         else:
             raise KeyNotFoundException(key)
Пример #7
0
 def apply_transaction(self, transaction):
     """
     Applies a transaction
     """
     try:
         return PyrakoonStore._try(self._identifier, self._client.sequence,
                                   self._sequences[transaction])
     except ArakoonAssertionFailed as assertion:
         raise AssertException(assertion)
     except ArakoonNotFound as field:
         raise KeyNotFoundException(field.message)
Пример #8
0
 def delete(self, key, must_exist=True, transaction=None):
     """
     Deletes a given key from the store
     """
     if transaction is not None:
         return self._sequences[transaction].append(
             [self.delete, {
                 'key': key
             }])
     data = self._read()
     if key in data:
         del data[key]
         self._save(data)
     elif must_exist is True:
         raise KeyNotFoundException(key)
Пример #9
0
 def delete(self, key, must_exist=True, transaction=None):
     """
     Deletes a given key from the store
     """
     if transaction is not None:
         if must_exist is True:
             return self._sequences[transaction].addDelete(key)
         else:
             return self._sequences[transaction].addReplace(key, None)
     try:
         if must_exist is True:
             return PyrakoonStore._try(self._identifier,
                                       self._client.delete, key)
         else:
             return PyrakoonStore._try(self._identifier,
                                       self._client.replace, key, None)
     except ArakoonNotFound as field:
         raise KeyNotFoundException(field.message)