Skip to content
Merged
Show file tree
Hide file tree
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.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <stdint.h>
#include <unistd.h>
#include <string>

#include "dbinterface.h"

Expand Down Expand Up @@ -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
}
9 changes: 9 additions & 0 deletions tests/test_redis_ut.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"