Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't create Pub/Sub with Redis #252

Closed
samchouse opened this issue May 23, 2023 · 3 comments
Closed

Can't create Pub/Sub with Redis #252

samchouse opened this issue May 23, 2023 · 3 comments
Labels
A-redis Area: Redis / deadpool-redis S-duplicate Status: This issue or pull request already exists

Comments

@samchouse
Copy link

Why can't I make this into a Pub/Sub channel?

let mut conn = redis_pool.get().await.unwrap();
conn.into_pubsub().subscribe("verification").await.unwrap();
error[E0507]: cannot move out of dereference of `deadpool_redis::Connection`
   --> crates/app/src/handlers/auth/mod.rs:111:5
    |
111 |     conn.into_pubsub().subscribe("verification").await.unwrap();
    |     ^^^^^-------------
    |     |    |
    |     |    value moved due to this method call
    |     move occurs because value has type `deadpool_redis::redis::aio::Connection<std::pin::Pin<std::boxed::Box<dyn deadpool_redis::redis::aio::AsyncStream + std::marker::Send + std::marker::Sync>>>`, which does not implement the `Copy` trait
    |
note: `deadpool_redis::redis::aio::Connection::<C>::into_pubsub` takes ownership of the receiver `self`, which moves value
   --> /home/xenfo/.cargo/registry/src/index.crates.io-6f17d22bba15001f/redis-0.23.0/src/aio.rs:295:24
    |
295 |     pub fn into_pubsub(self) -> PubSub<C> {
    |                        ^^^^
@samchouse
Copy link
Author

The solution is to do this: let mut pubsub = Connection::take(conn).into_pubsub();, though is it possible to do this enough to use up the whole pool or does it replenish itself as needed?

@bikeshedder
Copy link
Owner

Object::take (or Connection which is a type-alias) removes the object from the pool. Making space to create new objects. It does consume the connection from the pool but doesn't reduce the max_size of the pool.

This is related to #226

@bikeshedder bikeshedder added S-duplicate Status: This issue or pull request already exists A-redis Area: Redis / deadpool-redis labels May 24, 2023
@bikeshedder
Copy link
Owner

I'm closing this in favor of #226 which goes into more depth on how to solve this issue for deadpool-redis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-redis Area: Redis / deadpool-redis S-duplicate Status: This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants