Advanced: Read with explicit consistency policy. For fine-grained control over read consistency vs performance trade-off. # Consistency Policies - `LinearizableRead`: Read from Leader (strong consistency, may be slower) - `EventualConsistency`: Read from local node (fast, may be stale) - `LeaseRead`: Optimized Leader read using lease mechanism # Example ```ignore use d_engine_proto::client::Rea
(
&self,
key: impl AsRef<[u8]>,
consistency: ReadConsistencyPolicy,
)
| 287 | /// ).await?; |
| 288 | /// ``` |
| 289 | pub async fn get_with_consistency( |
| 290 | &self, |
| 291 | key: impl AsRef<[u8]>, |
| 292 | consistency: ReadConsistencyPolicy, |
| 293 | ) -> ClientApiResult<Option<Bytes>> { |
| 294 | let request = ClientReadRequest { |
| 295 | client_id: self.client_id, |
| 296 | keys: vec![Bytes::copy_from_slice(key.as_ref())], |
| 297 | consistency_policy: Some(consistency), |
| 298 | }; |
| 299 | |
| 300 | let (resp_tx, resp_rx) = MaybeCloneOneshot::new(); |
| 301 | |
| 302 | self.cmd_tx |
| 303 | .send(d_engine_core::ClientCmd::Read(request, resp_tx)) |
| 304 | .await |
| 305 | .map_err(|_| channel_closed_error())?; |
| 306 | |
| 307 | let result = tokio::time::timeout(self.timeout, resp_rx) |
| 308 | .await |
| 309 | .map_err(|_| timeout_error(self.timeout))? |
| 310 | .map_err(|_| channel_closed_error())?; |
| 311 | |
| 312 | let response = |
| 313 | result.map_err(|status| server_error(format!("RPC error: {}", status.message())))?; |
| 314 | |
| 315 | if response.error != ErrorCode::Success { |
| 316 | return Err(Self::map_error_response( |
| 317 | response.error, |
| 318 | response.leader_hint, |
| 319 | response.retry_after_ms, |
| 320 | )); |
| 321 | } |
| 322 | |
| 323 | let read_results = extract_read_payload(response.result)?; |
| 324 | Ok(read_results.entries.first().map(|e| e.value.clone())) |
| 325 | } |
| 326 | |
| 327 | /// Get multiple keys with linearizable consistency. |
| 328 | /// |