Skip to content

Commit

Permalink
Improve Redis connection logging
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdsellers committed Mar 18, 2024
1 parent b26adef commit 4283184
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 5 additions & 3 deletions nautilus_core/common/src/redis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ pub fn handle_messages_with_redis(
instance_id: UUID4,
config: HashMap<String, Value>,
) -> anyhow::Result<()> {
let empty = Value::Object(serde_json::Map::new());
let database_config = config.get("database").unwrap_or(&empty);
let database_config = config
.get("database")
.ok_or(anyhow::anyhow!("No database config"))?;
debug!("Creating msgbus redis connection");
let mut conn = create_redis_connection(&database_config.clone())?;

let stream_name = get_stream_name(trader_id, instance_id, &config);
Expand Down Expand Up @@ -179,7 +181,7 @@ pub fn get_redis_url(database_config: &serde_json::Value) -> String {

pub fn create_redis_connection(database_config: &serde_json::Value) -> RedisResult<Connection> {
let redis_url = get_redis_url(database_config);
debug!("Connecting to redis_url {redis_url}");
debug!("Connecting to {redis_url}");
let default_timeout = 20;
let timeout = get_timeout_duration(database_config, default_timeout);
let client = redis::Client::open(redis_url)?;
Expand Down
8 changes: 6 additions & 2 deletions nautilus_core/infrastructure/src/redis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use nautilus_core::uuid::UUID4;
use nautilus_model::identifiers::trader_id::TraderId;
use redis::{Commands, Connection, Pipeline};
use serde_json::{json, Value};
use tracing::debug;

// Error constants
const CHANNEL_TX_FAILED: &str = "Failed to send to channel";
Expand Down Expand Up @@ -82,8 +83,10 @@ impl CacheDatabase for RedisCacheDatabase {
instance_id: UUID4,
config: HashMap<String, serde_json::Value>,
) -> anyhow::Result<RedisCacheDatabase> {
let empty = Value::Object(serde_json::Map::new());
let database_config = config.get("database").unwrap_or(&empty);
let database_config = config
.get("database")
.ok_or(anyhow::anyhow!("No database config"))?;
debug!("Creating cache read redis connection");
let conn = create_redis_connection(&database_config.clone())?;

let (tx, rx) = channel::<DatabaseCommand>();
Expand Down Expand Up @@ -169,6 +172,7 @@ impl CacheDatabase for RedisCacheDatabase {
) {
let empty = Value::Object(serde_json::Map::new());
let database_config = config.get("database").unwrap_or(&empty);
debug!("Creating cache write redis connection");
let mut conn = create_redis_connection(&database_config.clone()).unwrap();

// Buffering
Expand Down

0 comments on commit 4283184

Please sign in to comment.