use std::{env, time::Duration};
use crate::{
common::RateType,
redis::{RedisKey, common::RedisKeyGenerator},
};
use super::runtime;
pub fn redis_url() -> String {
env::var("REDIS_URL").unwrap_or_else(|_| {
panic!(
"REDIS_URL env var must be set for Redis-backed tests \
(e.g. REDIS_URL=redis://127.0.0.1:16379/)"
)
})
}
pub async fn connection_manager() -> redis::aio::ConnectionManager {
redis::Client::open(redis_url())
.unwrap()
.get_connection_manager()
.await
.unwrap()
}
pub fn unique_prefix() -> RedisKey {
let n: u64 = rand::random();
RedisKey::try_from(format!("trypema_test_{n}")).unwrap()
}
pub fn key(s: &str) -> RedisKey {
RedisKey::try_from(s.to_string()).unwrap()
}
pub fn key_gen(prefix: &RedisKey, rate_type: RateType) -> RedisKeyGenerator {
RedisKeyGenerator::new(prefix.clone(), rate_type)
}
pub async fn wait_for_hybrid_sync(sync_interval: u64) {
runtime::async_sleep(Duration::from_millis(sync_interval * 2 + 50)).await;
}