diff --git a/common/sonicv2connector.h b/common/sonicv2connector.h index 541b5835f..d700d926f 100644 --- a/common/sonicv2connector.h +++ b/common/sonicv2connector.h @@ -2,6 +2,7 @@ #include #include +#include #include "dbinterface.h" @@ -91,6 +92,12 @@ class SonicV2Connector_Native def keys(self, *args, **kwargs): return list(super(SonicV2Connector, self).keys(*args, **kwargs)) + + def set(self, db_name, _hash, key, value, blocking=False): + if isinstance(value, str): + return super(SonicV2Connector, self).set(db_name, _hash, key, value, blocking) + + return super(SonicV2Connector, self).set(db_name, _hash, key, str(value), blocking) %} #endif } diff --git a/tests/test_redis_ut.py b/tests/test_redis_ut.py index 3a7363fd1..344a87ef1 100644 --- a/tests/test_redis_ut.py +++ b/tests/test_redis_ut.py @@ -687,3 +687,12 @@ def test_SonicDBConfigGetInstanceList(): assert instanceList['redis'].unixSocketPath == '/var/run/redis/redis.sock' assert instanceList['redis'].hostname == '127.0.0.1' assert instanceList['redis'].port == 6379 + + +def test_SonicV2Connector(): + db = SonicV2Connector(use_unix_socket_path=True) + db.connect("TEST_DB") + + db.set("TEST_DB", "test_key", "field1", 1) + value = db.get("TEST_DB", "test_key", "field1") + assert value == "1"