Skip to content

Commit

Permalink
redis: Use associated type bounds to simplify RedisConnection trait (#88
Browse files Browse the repository at this point in the history
)
  • Loading branch information
svix-jplatte authored Jun 13, 2024
1 parent 2fe5fd0 commit 379b34b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
2 changes: 1 addition & 1 deletion omniqueue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description = "An abstraction layer over various queue backends"
authors = ["Svix Inc. <[email protected]>"]
repository = "https://github.com/svix/omniqueue-rs/"
readme = "../README.md"
rust-version = "1.75"
rust-version = "1.79"
edition = "2021"

[dependencies]
Expand Down
15 changes: 3 additions & 12 deletions omniqueue/src/backends/redis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,30 +65,21 @@ pub use cluster::RedisClusterConnectionManager;

pub trait RedisConnection:
ManageConnection<
Connection = <Self as RedisConnection>::Connection,
Error = <Self as RedisConnection>::Error,
Connection: redis::aio::ConnectionLike + Send + Sync,
Error: std::error::Error + Send + Sync + 'static,
>
{
type Connection: redis::aio::ConnectionLike + Send + Sync;
type Error: std::error::Error + Send + Sync + 'static;

fn from_dsn(dsn: &str) -> Result<Self>;
}

impl RedisConnection for RedisConnectionManager {
type Connection = <Self as ManageConnection>::Connection;
type Error = <Self as ManageConnection>::Error;

fn from_dsn(dsn: &str) -> Result<Self> {
Self::new(dsn).map_err(QueueError::generic)
}
}

#[cfg(feature = "redis_cluster")]
impl RedisConnection for RedisClusterConnectionManager {
type Connection = <Self as ManageConnection>::Connection;
type Error = <Self as ManageConnection>::Error;

fn from_dsn(dsn: &str) -> Result<Self> {
Self::new(dsn).map_err(QueueError::generic)
}
Expand All @@ -113,7 +104,7 @@ async fn check_eviction_policy<R: RedisConnection>(
let results: Vec<String> = redis::cmd("CONFIG")
.arg("GET")
.arg("maxmemory-policy")
.query_async::<<R as RedisConnection>::Connection, Vec<String>>(&mut *conn)
.query_async::<R::Connection, Vec<String>>(&mut *conn)
.await
.map_err(|_| EvictionCheckError::CheckEvictionPolicyFailed)?;

Expand Down

0 comments on commit 379b34b

Please sign in to comment.