关于hiredis中执行HMSET,当被设置的field中包含空格时,使用redisCommand的格式进行传入将会被截断,这是需使用redisCommandArgv来进行操作,一下代码为对redisCommandArgv进行封装的HMSET命令,其他需要设置多个域的命令,只需要修改对应命令标识即可
std::vector<std::string> tVec;
tVec.push_back("HMSET");
tVec.push_back(key);
std::map<std::string, std::string>::const_iterator it = maps.begin();
for (; it != maps.end(); it++)
{
tVec.push_back(it->first);
tVec.push_back(it->second);
}
vector<const char *> argv( tVec.size());
vector<size_t> argvlen( tVec.size() );
unsigned int j = 0;
for ( vector<string>::const_iterator i = tVec.begin(); i != tVec.end(); ++i, ++j )
{
argv[j] = i->c_str();
argvlen[j] = i->length();
}
redisReply *pReply = static_cast<redisReply *>(redisCommandArgv(m_pRedisContext, argv.size(), &(argv[0]), &(argvlen[0])));
if (pReply)
{
int errNum = pReply->type;
if (errNum == REDIS_REPLY_ERROR)
{
freeReplyObject(pReply);
return -1;
}
freeReplyObject(pReply);
return 0;
}
return -1;
需要注意的是,此段代码只在linux中可以正确被运行,windows将出现崩溃,具体原因暂时不确定,初步怀疑是windows的hiredis-win32的版本库导致
最后
以上就是饱满招牌最近收集整理的关于基于hiredis封装HMSET命令的全部内容,更多相关基于hiredis封装HMSET命令内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复