8923bc0
use std::io;
use redis::aio::ConnectionLike;
use redis::{Cmd, Pipeline, RedisError, RedisFuture, Value};
use crate::conn::{CacheConn, CacheConnection};
use crate::error::CacheError;
impl ConnectionLike for CacheConn {
fn req_packed_command<'a>(&'a mut self, cmd: &'a Cmd) -> RedisFuture<'a, Value> {
Box::pin(async move {
let mut connection = self.acquire().await.map_err(connect_error)?;
connection.req_packed_command(cmd).await
})
}
fn req_packed_commands<'a>(
&'a mut self,
pipeline: &'a Pipeline,
offset: usize,
count: usize,
) -> RedisFuture<'a, Vec<Value>> {
Box::pin(async move {
let mut connection = self.acquire().await.map_err(connect_error)?;
connection
.req_packed_commands(pipeline, offset, count)
.await
})
}
fn get_db(&self) -> i64 {
self.database()
}
}
impl ConnectionLike for CacheConnection {
fn req_packed_command<'a>(&'a mut self, cmd: &'a Cmd) -> RedisFuture<'a, Value> {
match self {
Self::Standard(connection) => connection.req_packed_command(cmd),
Self::Cluster(connection) => connection.req_packed_command(cmd),
}
}
fn req_packed_commands<'a>(
&'a mut self,
pipeline: &'a Pipeline,
offset: usize,
count: usize,
) -> RedisFuture<'a, Vec<Value>> {
match self {
Self::Standard(connection) => connection.req_packed_commands(pipeline, offset, count),
Self::Cluster(connection) => connection.req_packed_commands(pipeline, offset, count),
}
}
fn get_db(&self) -> i64 {
match self {
Self::Standard(connection) => connection.get_db(),
Self::Cluster(connection) => connection.get_db(),
}
}
}
fn connect_error(error: CacheError) -> RedisError {
match error {
CacheError::Backend(error) => error,
error => io::Error::other(error).into(),
}
}