use redis::{
aio::{ConnectionLike, ConnectionManager},
Cmd, RedisError, RedisFuture, Value,
};
use std::task::{Context, Poll};
#[derive(Clone)]
pub struct RedisService {
inner: ConnectionManager,
}
impl RedisService {
pub fn new(inner: ConnectionManager) -> Self {
Self { inner }
}
}
impl tower::Service<Cmd> for RedisService {
type Response = Value;
type Error = RedisError;
type Future = RedisFuture<'static, Value>;
fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}
fn call(&mut self, req: Cmd) -> Self::Future {
let mut inner = self.inner.clone();
Box::pin(async move { inner.req_packed_command(&req).await })
}
}