Skip to content

Add a new API connect_host to SonicV2Connector #1003

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions common/sonicv2connector.cpp
Original file line number Diff line number Diff line change
@@ -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);
2 changes: 2 additions & 0 deletions common/sonicv2connector.h
Original file line number Diff line number Diff line change
@@ -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();
2 changes: 2 additions & 0 deletions tests/test_redis_ut.py
Original file line number Diff line number Diff line change
@@ -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'