in sonic-db-cli/sonic-db-cli.cpp [132:181]
int executeCommands(
const string& db_name,
vector<string>& commands,
const string& netns,
bool useUnixSocket)
{
shared_ptr<DBConnector> client = nullptr;
try
{
int db_id = SonicDBConfig::getDbId(db_name, netns);
auto host = SonicDBConfig::getDbHostname(db_name, netns);
if (useUnixSocket && host != "redis_chassis.server")
{
auto db_socket = SonicDBConfig::getDbSock(db_name, netns);
client = make_shared<DBConnector>(db_id, db_socket, 0);
}
else
{
auto port = SonicDBConfig::getDbPort(db_name, netns);
client = make_shared<DBConnector>(db_id, host, port, 0);
}
}
catch (const exception& e)
{
cerr << "Invalid database name input : '" << db_name << "'" << endl;
cerr << e.what() << endl;
return 1;
}
try
{
RedisCommand command;
command.format(commands);
RedisReply reply(client.get(), command);
/*
sonic-db-cli output format mimic the non-tty mode output format from redis-cli
based on our usage in SONiC, None and list type output from python API needs to be modified
with these changes, it is enough for us to mimic redis-cli in SONiC so far since no application uses tty mode redis-cli output
*/
auto commandName = getCommandName(commands);
cout << RedisReply::to_string(reply.getContext(), commandName) << endl;
}
catch (const std::system_error& e)
{
cerr << e.what() << endl;
return 1;
}
return 0;
}