Hi!
I have a simple web service with an endpoint (/foo). For each request on /foo I need to perform a redis request to get fresh data. I'm wondering the best way to handle the redis connection on the web service.
For the moment, I have a struct like this:
pub struct Deps {
pub redis_conn: Mutex<redis::Connection>>
}
And when my service start, I wrap my deps with web::Data (Arc)
let deps = Deps::new();
let deps_data = web::Data::new(deps);
HttpServer::new(move || {
App::new()
.app_data(deps_data.clone())
And inside the endpoint when I need the redis connection:
let mut redis_conn = deps.redis_conn.lock().unwrap()
The point whish affraid me is that the lock of Mutex block the current thread.
What do you think? It's ok with this method or should I use the async connection of redis?