def _delete(self, key, version): req = protocol.VoldemortRequest() req.should_route = True req.store = self.store_name req.type = protocol.DELETE req.delete.key = key req.delete.version.MergeFrom(version) # send request self._send_request(self.connection, req.SerializeToString()) # read and parse response resp_str = self._receive_response(self.connection) resp = protocol.DeleteResponse() resp.ParseFromString(resp_str) self._check_error(resp) return resp.success
def _put(self, key, value, version): req = protocol.VoldemortRequest() req.should_route = True req.store = self.store_name req.type = protocol.PUT req.put.key = key req.put.versioned.value = value req.put.versioned.version.MergeFrom(version) # send request self._send_request(self.connection, req.SerializeToString()) # read and parse response resp_str = self._receive_response(self.connection) resp = protocol.PutResponse() resp.ParseFromString(resp_str) self._check_error(resp) self._increment(version) return version
def _get_with_connection(self, connection, store_name, key, should_route): """Execute get request to the given store. Returns a (value, version) pair.""" req = protocol.VoldemortRequest() req.should_route = should_route req.store = store_name req.type = protocol.GET req.get.key = key # send request self._send_request(connection, req.SerializeToString()) # read and parse response resp_str = self._receive_response(connection) resp = protocol.GetResponse() resp.ParseFromString(resp_str) self._check_error(resp) return self._extract_versions(resp.versioned)
def _get_all(self, keys): req = protocol.VoldemortRequest() req.should_route = True req.store = self.store_name req.type = protocol.GET_ALL for key in keys: req.getAll.keys.append(key) # send request self._send_request(self.connection, req.SerializeToString()) # read and parse response resp_str = self._receive_response(self.connection) resp = protocol.GetAllResponse() resp.ParseFromString(resp_str) self._check_error(resp) values = {} for key_val in resp.values: values[key_val.key] = self._extract_versions(key_val.versions) return values