Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions crates/key-value-store/src/redis_impl.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
use crate::Store;
use reactor::gcore::fastedge::key_value::{Error, Value};
use redis::aio::ConnectionManager;
use redis::{AsyncCommands, AsyncIter};

#[derive(Clone)]
pub struct RedisStore {
inner: redis::aio::MultiplexedConnection,
inner: ConnectionManager,
}

impl RedisStore {
/// Open a store backed by `ConnectionManager`, which holds a multiplexed
/// connection and transparently reconnects with exponential backoff when
/// the underlying socket dies (e.g. broken pipe on Redis restart). The
/// command that hits the dead socket still surfaces as an error, but
/// follow-up calls land on the freshly re-established connection.
pub async fn open(params: &str) -> Result<Self, Error> {
let conn = ::redis::Client::open(params)
.map_err(|error| {
tracing::warn!(error=?error, "redis open");
Error::InternalError
})?
.get_multiplexed_async_connection()
.await
.map_err(|error| {
tracing::warn!(error=?error, "redis open");
Error::InternalError
})?;
let client = ::redis::Client::open(params).map_err(|error| {
tracing::warn!(error=?error, "redis open");
Error::InternalError
})?;
let conn = ConnectionManager::new(client).await.map_err(|error| {
tracing::warn!(error=?error, "redis open");
Error::InternalError
})?;
Ok(Self { inner: conn })
}
}
Expand Down
Loading