@@ -32,13 +32,13 @@ string RedisMongoDB::MONGODB_FIELD_NAME[MONGODB_FIELD::size];
3232uint RedisMongoDB::MONGODB_CHUNK_SIZE;
3333mongocxx::instance RedisMongoDB::MONGODB_INSTANCE;
3434
35- RedisMongoDB::RedisMongoDB (const string& context, bool skip_redis) {
35+ RedisMongoDB::RedisMongoDB (const string& context, bool skip_redis, const JsonConfig& config ) {
3636 initialize_statics (context, skip_redis);
37- mongodb_setup ();
37+ mongodb_setup (config );
3838 load_pattern_index_schema ();
3939 bool disable_cache = true ;
4040 this ->atomdb_cache = disable_cache ? nullptr : AtomDBCacheSingleton::get_instance ();
41- redis_setup ();
41+ redis_setup (config );
4242 this ->patterns_next_score .store (get_next_score (REDIS_PATTERNS_PREFIX + " :next_score" ));
4343 this ->incoming_set_next_score .store (get_next_score (REDIS_INCOMING_PREFIX + " :next_score" ));
4444}
@@ -50,17 +50,28 @@ RedisMongoDB::~RedisMongoDB() {
5050
5151bool RedisMongoDB::allow_nested_indexing () { return false ; }
5252
53- void RedisMongoDB::redis_setup () {
53+ void RedisMongoDB::redis_setup (const JsonConfig& config ) {
5454 if (SKIP_REDIS) return ;
5555
5656 string host = Utils::get_environment (" DAS_REDIS_HOSTNAME" );
5757 string port = Utils::get_environment (" DAS_REDIS_PORT" );
58- string address = host + " :" + port;
59- string cluster = Utils::get_environment (" DAS_USE_REDIS_CLUSTER" );
58+
59+ string address = config.at_path (" redis.endpoint" ).get_or <string>(" " );
60+
61+ if (!address.empty ()) {
62+ auto tokens = Utils::split (address, ' :' );
63+ host = tokens[0 ];
64+ port = tokens[1 ];
65+ } else {
66+ address = host + " :" + port;
67+ }
68+
69+ string cluster =
70+ config.at_path (" redis.cluster" ).get_or <string>(Utils::get_environment (" DAS_USE_REDIS_CLUSTER" ));
6071 std::transform (cluster.begin (), cluster.end (), cluster.begin (), ::toupper);
6172 this ->cluster_flag = (cluster == " TRUE" );
6273
63- if (host == " " || port == " " ) {
74+ if (address == " " || address == " : " ) {
6475 Utils::error (
6576 " You need to set Redis access info as environment variables: DAS_REDIS_HOSTNAME, "
6677 " DAS_REDIS_PORT and DAS_USE_REDIS_CLUSTER" );
@@ -70,25 +81,29 @@ void RedisMongoDB::redis_setup() {
7081 << address);
7182}
7283
73- void RedisMongoDB::mongodb_setup () {
84+ void RedisMongoDB::mongodb_setup (const JsonConfig& config ) {
7485 string host = Utils::get_environment (" DAS_MONGODB_HOSTNAME" );
7586 string port = Utils::get_environment (" DAS_MONGODB_PORT" );
76- string user = Utils::get_environment (" DAS_MONGODB_USERNAME" );
77- string password = Utils::get_environment (" DAS_MONGODB_PASSWORD" );
87+ string address = config.at_path (" mongodb.endpoint" ).get_or <string>(host + " :" + port);
88+ string user = config.at_path (" mongodb.username" )
89+ .get_or <string>(Utils::get_environment (" DAS_MONGODB_USERNAME" ));
90+ string password = config.at_path (" mongodb.password" )
91+ .get_or <string>(Utils::get_environment (" DAS_MONGODB_PASSWORD" ));
7892 try {
79- uint chunk_size = Utils::string_to_int (Utils::get_environment (" DAS_MONGODB_CHUNK_SIZE" ));
93+ uint chunk_size =
94+ config.at_path (" mongodb.chunk_size" )
95+ .get_or <uint>(Utils::string_to_int (Utils::get_environment (" DAS_MONGODB_CHUNK_SIZE" )));
8096 if (chunk_size > 0 ) {
8197 MONGODB_CHUNK_SIZE = chunk_size;
8298 }
8399 } catch (const std::exception& e) {
84100 LOG_INFO (" Using default MongoDB chunk size: " + to_string (MONGODB_CHUNK_SIZE));
85101 }
86- if (host == " " || port == " " || user == " " || password == " " ) {
102+ if (address == " " || address == " : " || user == " " || password == " " ) {
87103 Utils::error (
88104 string (" You need to set MongoDB access info as environment variables: " ) +
89105 " DAS_MONGODB_HOSTNAME, DAS_MONGODB_PORT, DAS_MONGODB_USERNAME and DAS_MONGODB_PASSWORD" );
90106 }
91- string address = host + " :" + port;
92107 string url = " mongodb://" + user + " :" + password + " @" + address;
93108
94109 try {
0 commit comments