How do i setup Rocket with redis + connection pool? #2253
Replies: 3 comments 8 replies
-
Are you wanting to set up a connection pool for Redis or do you want both a connection pool for Redis and a separate connection pool for a No/SQL database (e.g. Postgres, MongoDB, etc)? For either, using Rocket (I'm assuming you want Redis and a SQL database connection pool) In your Cargo.toml: # ...
[dependencies]
rocket = "0.5.0-rc.2"
rocket_db_pools = { version = "0.1.0-rc.2", features = [ "deadpool_redis", "sqlx_postgres" ] }
# ... Now in your use rocket_db_pools::{Connection, Database, deadpool_redis, sqlx};
use rocket::{launch, get};
#[derive(Database)]
#[database("redis_pool")]
pub RedisPool(deadpool_redis::Pool);
#[derive(Database)]
#[database("postgres_pool")]
pub PostgresPool(sqlx::PgPool);
#[get("/")]
async fn test_route(redis: Connection<RedisPool>, pg: Connection<PostgresPool>) {
// ...
}
#[launch]
fn rocket() -> _ {
rocket::ignite()
.attach(RedisPool::init())
.attach(PostgresPool::init())
} Finally, either in environment variables or in your [default.databases.redis_pool]
url = "..."
[default.databases.postgres_pool]
url = "..." In general, review the |
Beta Was this translation helpful? Give feedback.
-
Hi sir. I have followed your instructions. Everything works 100% ...in development, and in production as a stand alone file. I have one last question. When I take the same build (that works in dev, and in release) and I build it for docker. I get this error when the file is run
i am really stumped on what the issue is because i do have the url configured in my
|
Beta Was this translation helpful? Give feedback.
-
--deleted-- so i found out what the issue was. So the fix in my |
Beta Was this translation helpful? Give feedback.
-
How do i setup Rocket with redis + connection pool?
The documentation wasnt very clear for me, and tutorials online do not work for version
0.5.0-rc.2
Could you provide an example or guide me to what documentation i should look at that gives a redis example? Many of the examples use SQL
Beta Was this translation helpful? Give feedback.
All reactions