redisContext * pConn = redisConnect(redisIp.c_str(), redisPort);
if (m_cLocal == NULL)
{
return 1;
}redisif(pConn->err)
{
cout << "Connection to redis[" << redisIp << "] error: " << pConn->errstr;
redisFree(pConn);
return 2;
}数据库
string cmd="set foo bar;
redisReply * reply=(redisReply *)redisCommand(pConn, cmd.c_str());
if(reply == NULL)
{
cout << "redis[" << redisIp << "] excute " << cmd << " failed, error is: " << pConn->errstr;
redisFree(pConn);
pConn=NULL;
return 3;
}
freeReplyObject(reply);get
Once an error is returned the context cannot be reused and you should set up a new connection.cmd
上面示例中执行命令时,若是返回了错误,则链接不可用,须要从新创建链接。string
更多文章,欢迎访问个人站点:零一积流。it