pub struct PeerConnection {
pub config: PeerConfig,
/* private fields */
}Expand description
A managed connection to a peer’s Redis.
Uses redis::aio::ConnectionManager internally, which provides:
- Automatic reconnection on connection loss
- Multiplexed connection (single TCP socket, multiple in-flight requests)
- Connection pooling semantics (cloning is cheap, shares underlying connection)
Fields§
§config: PeerConfigPeer configuration
Implementations§
Source§impl PeerConnection
impl PeerConnection
Sourcepub fn new(config: PeerConfig) -> Self
pub fn new(config: PeerConfig) -> Self
Create a new peer connection (not yet connected).
Sourcepub fn cdc_stream_key(&self) -> String
pub fn cdc_stream_key(&self) -> String
Get the CDC stream key for this peer.
Sourcepub async fn is_connected(&self) -> bool
pub async fn is_connected(&self) -> bool
Check if connected.
Sourcepub async fn circuit_state(&self) -> PeerCircuitState
pub async fn circuit_state(&self) -> PeerCircuitState
Get the current circuit breaker state.
Sourcepub async fn is_circuit_open(&self) -> bool
pub async fn is_circuit_open(&self) -> bool
Check if the circuit is open (should reject requests).
Sourcepub async fn record_success(&self)
pub async fn record_success(&self)
Record a successful operation (resets failure count).
Sourcepub async fn record_failure(&self)
pub async fn record_failure(&self)
Record a failed operation (increments failure count, may open circuit).
Sourcepub async fn connect(&self, retry_config: &RetryConfig) -> Result<()>
pub async fn connect(&self, retry_config: &RetryConfig) -> Result<()>
Connect to the peer’s Redis with retry logic.
Sourcepub async fn connection(&self) -> Option<ConnectionManager>
pub async fn connection(&self) -> Option<ConnectionManager>
Get the stream connection (for XREAD and other potentially blocking ops).
Returns None if not connected.
Sourcepub async fn query_connection(&self) -> Option<ConnectionManager>
pub async fn query_connection(&self) -> Option<ConnectionManager>
Get the query connection (for GET, HGET, and other fast point queries).
This is a separate connection that won’t be blocked by XREAD BLOCK on the stream connection.
Returns None if not connected.
Sourcepub async fn ensure_connected(&self) -> Result<ConnectionManager>
pub async fn ensure_connected(&self) -> Result<ConnectionManager>
Ensure the peer is connected, connecting lazily if needed.
This provides a convenient way to get a connection without
manually calling connect() first. Uses default retry config.
§Returns
The connection manager, or an error if connection failed.
Sourcepub fn failure_count(&self) -> u64
pub fn failure_count(&self) -> u64
Get consecutive failure count.
Sourcepub fn millis_since_success(&self) -> u64
pub fn millis_since_success(&self) -> u64
Get milliseconds since last success.
Sourcepub async fn mark_disconnected(&self)
pub async fn mark_disconnected(&self)
Mark connection as failed (triggers reconnect).
Sourcepub async fn ping(&self) -> Result<Duration>
pub async fn ping(&self) -> Result<Duration>
Ping the peer’s Redis to check connection health.
Returns the round-trip latency on success.
Updates last_success timestamp on success.
Sourcepub async fn get_merkle_root(&self) -> Result<Option<[u8; 32]>>
pub async fn get_merkle_root(&self) -> Result<Option<[u8; 32]>>
Get the peer’s Merkle root hash (cached with TTL).
Uses a short-lived cache to avoid hammering the peer during repair cycles.
The cache is automatically invalidated after MERKLE_CACHE_TTL.
Sourcepub async fn invalidate_merkle_cache(&self)
pub async fn invalidate_merkle_cache(&self)
Invalidate the Merkle root cache (call after local writes).
Auto Trait Implementations§
impl !Freeze for PeerConnection
impl !RefUnwindSafe for PeerConnection
impl Send for PeerConnection
impl Sync for PeerConnection
impl Unpin for PeerConnection
impl !UnwindSafe for PeerConnection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more