From 778707ce6d06f4d2e548184d077c11ffb17d6309 Mon Sep 17 00:00:00 2001 From: Vivek Kumar Verma Date: Wed, 9 Apr 2025 07:51:55 +0000 Subject: [PATCH 1/2] Add a new API connect_host to SonicV2Connector --- common/sonicv2connector.cpp | 7 +++++++ common/sonicv2connector.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/common/sonicv2connector.cpp b/common/sonicv2connector.cpp index 325e0d9fd..e2082b176 100644 --- a/common/sonicv2connector.cpp +++ b/common/sonicv2connector.cpp @@ -29,6 +29,13 @@ void SonicV2Connector_Native::connect(const std::string& db_name, bool retry_on) m_dbintf.connect(db_id, db_name, retry_on); } +void SonicV2Connector_Native::connect_host(const std::string& db_name, const std::string& host, bool retry_on) +{ + m_dbintf.set_redis_kwargs("", host, get_db_port(db_name)); + int db_id = get_dbid(db_name); + m_dbintf.connect(db_id, db_name, retry_on); +} + void SonicV2Connector_Native::close(const std::string& db_name) { m_dbintf.close(db_name); diff --git a/common/sonicv2connector.h b/common/sonicv2connector.h index 4bd9b675e..9cc8b8c48 100644 --- a/common/sonicv2connector.h +++ b/common/sonicv2connector.h @@ -18,6 +18,8 @@ class SonicV2Connector_Native void connect(const std::string& db_name, bool retry_on = true); + void connect_host(const std::string& db_name, const std::string& host, bool retry_on = true); + void close(const std::string& db_name); void close(); From 7a6b54dd5365bcf821a8005a4a621e0e2410c0c4 Mon Sep 17 00:00:00 2001 From: Vivek Verma <137406113+vivekverma-arista@users.noreply.github.com> Date: Thu, 10 Apr 2025 15:49:51 +0530 Subject: [PATCH 2/2] Update test_redis_ut.py Enhance test_redis_ut.py. --- tests/test_redis_ut.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_redis_ut.py b/tests/test_redis_ut.py index bf395a34f..4f1fd7d08 100644 --- a/tests/test_redis_ut.py +++ b/tests/test_redis_ut.py @@ -360,6 +360,8 @@ def test_DBInterface(): db = SonicV2Connector(use_unix_socket_path=True, namespace='', decode_responses=True) db = SonicV2Connector(use_unix_socket_path=False, decode_responses=True) db = SonicV2Connector(host="127.0.0.1", decode_responses=True) + db = SonicV2Connector() + db.connect_host(db_name="TEST_DB", host='127.0.0.1') except: assert False, 'Unexpected exception raised'