标签:
redisContext * pConn = redisConnect(redisIp.c_str(), redisPort);
if (m_cLocal == NULL)
{
return 1;
}if(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);
Once an error is returned the context cannot be reused and you should set up a new connection.
上面示例中执行命令时,如果返回了错误,则连接不可用,需要重新建立连接。
更多文章,欢迎访问我的站点:零一积流。
[转] Hiredis: redis c client使用注记
标签:
原文地址:http://www.cnblogs.com/rd-log/p/4837791.html