Skip to content

Commit c2ccaa3

Browse files
fix getting hash from redis db (#465)
1 parent be160cf commit c2ccaa3

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

common/configdb.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,11 @@ map<string, map<string, string>> ConfigDBConnector_Native::get_table(string tabl
180180
auto const& entry = client.hgetall<map<string, string>>(key);
181181
size_t pos = key.find(TABLE_NAME_SEPARATOR);
182182
string row;
183-
if (pos != string::npos)
183+
if (pos == string::npos)
184184
{
185-
row = key.substr(pos + 1);
185+
continue;
186186
}
187+
row = key.substr(pos + 1);
187188
data[row] = entry;
188189
}
189190
return data;
@@ -248,12 +249,11 @@ map<string, map<string, map<string, string>>> ConfigDBConnector_Native::get_conf
248249
for (string key: keys)
249250
{
250251
size_t pos = key.find(TABLE_NAME_SEPARATOR);
251-
string table_name = key.substr(0, pos);
252-
string row;
253-
if (pos != string::npos)
254-
{
255-
row = key.substr(pos + 1);
252+
if (pos == string::npos) {
253+
continue;
256254
}
255+
string table_name = key.substr(0, pos);
256+
string row = key.substr(pos + 1);
257257
auto const& entry = client.hgetall<map<string, string>>(key);
258258

259259
if (!entry.empty())
@@ -411,10 +411,11 @@ int ConfigDBPipeConnector_Native::_get_config(DBConnector& client, RedisTransact
411411
size_t pos = key.find(TABLE_NAME_SEPARATOR);
412412
string table_name = key.substr(0, pos);
413413
string row;
414-
if (pos != string::npos)
414+
if (pos == string::npos)
415415
{
416-
row = key.substr(pos + 1);
416+
continue;
417417
}
418+
row = key.substr(pos + 1);
418419

419420
auto reply = pipe.dequeueReply();
420421
RedisReply r(reply);

tests/test_redis_ut.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,25 @@ def test_ConfigDBConnector():
263263
allconfig = config_db.get_config()
264264
assert len(allconfig) == 0
265265

266+
def test_ConfigDBConnectorSeparator():
267+
db = swsscommon.DBConnector("APPL_DB", 0, True)
268+
config_db = ConfigDBConnector()
269+
config_db.db_connect("APPL_DB", False, False)
270+
config_db.get_redis_client(config_db.APPL_DB).flushdb()
271+
config_db.set_entry("TEST_PORT", "Ethernet222", {"alias": "etp2x"})
272+
db.set("ItemWithoutSeparator", "item11")
273+
allconfig = config_db.get_config()
274+
assert "TEST_PORT" in allconfig
275+
assert "ItemWithoutSeparator" not in allconfig
276+
277+
alltable = config_db.get_table("*")
278+
assert "Ethernet222" in alltable
279+
280+
config_db.delete_table("TEST_PORT")
281+
db.delete("ItemWithoutSeparator")
282+
allconfig = config_db.get_config()
283+
assert len(allconfig) == 0
284+
266285
def test_ConfigDBPipeConnector():
267286
config_db = ConfigDBPipeConnector()
268287
config_db.connect(wait_for_init=False)

0 commit comments

Comments
 (0)