Add key-value store setup function
This commit is contained in:
29
src/server/key_val_store.rs
Normal file
29
src/server/key_val_store.rs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
use fred::prelude::*;
|
||||||
|
|
||||||
|
use crate::util::error::{Contextualize, Error, ErrorType};
|
||||||
|
|
||||||
|
const KEY_VAL_POOL_SIZE: usize = 4;
|
||||||
|
|
||||||
|
pub type KeyValPool = Pool;
|
||||||
|
|
||||||
|
pub async fn setup(connection_uri: &str) -> Result<KeyValPool, Error> {
|
||||||
|
let config = Config::from_url(connection_uri)
|
||||||
|
.map_err(|e| ErrorType::KeyValStore(e.to_string()))
|
||||||
|
.err_context("Error creating key-value store config")?;
|
||||||
|
|
||||||
|
let pool = Builder::from_config(config)
|
||||||
|
.build_pool(KEY_VAL_POOL_SIZE)
|
||||||
|
// At time of writing the only error that could occur here is if config is not provided.
|
||||||
|
// Since we're building a pool `from_config`, this shouldn't be possible
|
||||||
|
.map_err(|e| ErrorType::KeyValStore(e.to_string()))
|
||||||
|
.err_context("Error creating pool for key-value store")?;
|
||||||
|
|
||||||
|
tracing::debug!("Establishing connection to key-value store...");
|
||||||
|
|
||||||
|
pool.init()
|
||||||
|
.await
|
||||||
|
.map_err(|e| ErrorType::KeyValStore(e.to_string()))
|
||||||
|
.err_context("Error connecting to key-value store")?;
|
||||||
|
|
||||||
|
Ok(pool)
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod database;
|
pub mod database;
|
||||||
|
pub mod key_val_store;
|
||||||
pub mod main;
|
pub mod main;
|
||||||
|
|
||||||
pub use main::main;
|
pub use main::main;
|
||||||
|
|||||||
Reference in New Issue
Block a user