C++ Redis mset??????????????????
???????????? ???????[ 2015/2/12 11:46:10 ] ????????C++ ??? ???
?????????????????mset????????????????????????????????????????????????
????redisCommandArgv?????? ????
???????????????????hiredis??????????????????к?????????????е?????????????????
?????????????????????????
????void *redisCommandArgv(redisContext *c?? int argc?? const char **argv?? const size_t *argvlen);
??????????????????????????????char ** argv???????漰??char **??const char **??????????????????
????????????????????????????
void mset1( redisContext *c?? const vector<string> &vtKey?? const vector<string> & vtVal )
{
if(vtKey.size() != vtVal.size())
{
throw runtime_error( "Redis error" );
}
char ** argv = new char*[vtKey.size() + vtVal.size() + 1 ];
size_t * argvlen = new size_t[vtKey.size() + vtVal.size() + 1 ];
int j = 0;
argv[j] = new char[5];
memcpy(argv[j]??"MSET"??4);
argvlen[j] = 4;
++j;
for(int i = 0 ; i < vtKey.size();i++)
{
argvlen[j] = vtKey[i].length();
argv[j] = new char[argvlen[j]];
memset((void*)argv[j]??0??argvlen[j] );
memcpy((void*)argv[j]??vtKey[i].data()??vtKey[i].length());
j++;
argvlen[j] = vtVal[i].length();
argv[j] = new char[argvlen[j]];
memset((void*)argv[j]??0??argvlen[j]);
memcpy((void*)argv[j]??vtVal[i].data()??vtVal[i].length());
j++;
}
//if not use const_cast<const char**> ??compile error
//for why assign from char** to const char** error?? see my blog ...
void *r = redisCommandArgv(c?? vtKey.size() + vtVal.size() + 1?? const_cast<const char**>(argv)?? argvlen );
if ( !r )
throw runtime_error( "Redis error" );
freeReplyObject( r );
for(int i = 0;i < vtKey.size();i++)
{
delete [] argv[i];
argv[i] = NULL;
}
delete []argv;
delete []argvlen;
argv = NULL;
}
????redisCommandArgv???????Vector????
???????????redisCommandArgv???????vector?????????const char **????????????ο?????1????????
void mset2( redisContext *c?? const vector<string> &vtKey?? const vector<string> & vtVal)
{
if(vtKey.size() != vtVal.size())
{
throw runtime_error( "Redis error" );
}
vector<const char *> argv( vtKey.size() + vtVal.size() + 1 );
vector<size_t> argvlen( vtKey.size() + vtVal.size() + 1 );
int j = 0;
static char msetcmd[] = "MSET";
argv[j] = msetcmd;
argvlen[j] = sizeof(msetcmd)-1;
++j;
for(int i = 0;i< vtKey.size();++i)
{
argvlen[j] = vtKey[i].length();
argv[j] = new char[argvlen[j]];
memset((void*)argv[j]??0??argvlen[j] );
memcpy((void*)argv[j]??vtKey[i].data()??vtKey[i].length());
j++;
argvlen[j] = vtVal[i].length();
argv[j] = new char[argvlen[j]];
memset((void*)argv[j]??0??argvlen[j]);
memcpy((void*)argv[j]??vtVal[i].data()??vtVal[i].length());
j++;
}
void *r = redisCommandArgv(c?? argv.size()?? &(argv[0])?? &(argvlen[0]) );
if ( !r )
throw runtime_error( "Redis error" );
freeReplyObject( r );
}
???????????????????????????
??????????У??
??????????к???????redis-cli???????
??????????????????????????????????????
????/opt/app/colin$./redis-cli get D
????"AB"
?????????????????????????????????0?????巽??????
????/opt/app/colin$./redis-cli get D
????"ABx00DE"
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
??C++????????????C++ lvalue??rvalueC++11????????C++???????????????C++?е?????????????????C++?????????C++???Windows????λ??C/C++???????????????????JAVA??C??C++??????????c++??python???????????????????????????????C++???????C++?е????????C++????????????????C++ ???????????????C++?????????????????????C++????????????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????