()
| 111 | } |
| 112 | |
| 113 | pub async fn setup() -> Result<()> { |
| 114 | let conf = config::get(); |
| 115 | |
| 116 | #[cfg(feature = "postgres")] |
| 117 | { |
| 118 | postgres::setup(&conf.postgresql)?; |
| 119 | } |
| 120 | #[cfg(feature = "sqlite")] |
| 121 | { |
| 122 | sqlite::setup(&conf.sqlite)?; |
| 123 | } |
| 124 | run_db_migrations().await?; |
| 125 | |
| 126 | info!("Setting up Redis client"); |
| 127 | if conf.redis.cluster { |
| 128 | let pool = deadpool_redis::cluster::Config::from_urls(conf.redis.servers.clone()) |
| 129 | .builder()? |
| 130 | .max_size(conf.redis.max_open_connections as usize) |
| 131 | .build()?; |
| 132 | set_async_redis_pool(AsyncRedisPool::ClusterClient(pool)).await; |
| 133 | } else { |
| 134 | let pool = deadpool_redis::Config::from_url(conf.redis.servers[0].clone()) |
| 135 | .builder()? |
| 136 | .max_size(conf.redis.max_open_connections as usize) |
| 137 | .build()?; |
| 138 | set_async_redis_pool(AsyncRedisPool::Client(pool)).await; |
| 139 | } |
| 140 | |
| 141 | if !conf.redis.key_prefix.is_empty() { |
| 142 | info!(prefix = %conf.redis.key_prefix, "Setting Redis prefix"); |
| 143 | REDIS_PREFIX |
| 144 | .write() |
| 145 | .unwrap() |
| 146 | .clone_from(&conf.redis.key_prefix); |
| 147 | } |
| 148 | |
| 149 | Ok(()) |
| 150 | } |
| 151 | |
| 152 | async fn get_async_redis_pool() -> Result<AsyncRedisPool> { |
| 153 | let pool_r = ASYNC_REDIS_POOL.read().await; |
nothing calls this directly
no test coverage detected