djc / bb8

Full-featured async (tokio-based) postgres connection pool (like r2d2)
MIT License
764 stars 109 forks source link

How to use bb8 with redis pubsub connections ? #70

Open sync opened 4 years ago

sync commented 4 years ago

First of all thank you for the recent update to bb8 :-)

I can never turn a conn in into a pubsub connection calling into_pubsub for some reason. Have you had a chance to have a look pubsub with redis ?

let mut conn = pool.get().await.unwrap();
let conn = conn.as_mut().unwrap();

From redis

let client = redis::Client::open("redis://127.0.0.1/").unwrap();
let mut publish_conn = client.get_async_connection().await?;
let mut pubsub_conn = client.get_async_connection().await?.into_pubsub();
sync commented 4 years ago

I hacked around it but it is definitely not a good solution:

https://github.com/sync/bb8/commit/876ed2c2b2b7d94922c83c1d87e69c3569341640

djc commented 4 years ago

Having a second pool for this doesn't seem so bad. Why do you think it's not a good solution?

khuey commented 4 years ago

Can you get yourself a dedicated connection (via Pool<M>::dedicated_connection) and use that? I'm not entirely sure how Redis's pub-sub stuff works but I added that for doing LISTENs on postgres.

sync commented 4 years ago

I didn't like the fact that i have to create a fake subscription to see if pool is working... I've opened a PR let me know what you think: https://github.com/khuey/bb8/pull/71

sync commented 4 years ago

@khuey i can't see any usage of the dedicated_connection in the codebase, do you have a sample somewhere ?

djc commented 4 years ago

Pool::dedicated_connection() is a simple method on the Pool that uses the address/authentication information contained in the Pool's ConnectionManager to build a new connection, and then directly yields that connection to the caller. I think it would make sense to use for this (as discussed in #71 as well).

bbaldino commented 1 year ago

@djc might you be open to supporting a pubsub connection pool? The changes to do so seem pretty minimal (still need to figure out what is_valid should look like there).

My usecase for it is that we're looking to use an adhoc pubsub channel to send back a response from a request received over a stream. Using a stream for the response is overkill because we want this to be ephemeral.

djc commented 1 year ago

@bbaldino I'll consider it, please submit a PR.

bbaldino commented 1 year ago

Thanks @djc. Opened https://github.com/djc/bb8/pull/159