| | |
| | | // m_nImgListLen=appConfig.getIntProperty("redis_buf_len"); |
| | | std::string ip=appConfig.getStringProperty("redis_ip"); |
| | | |
| | | int port=6379; |
| | | int port=appConfig.getIntProperty("redis_port"); |
| | | m_redis = redisConnectWithTimeout(ip.c_str(), port, timeout);//建立连接 |
| | | if (m_redis->err) { |
| | | |
| | | DBG("RedisTool : Connection error: %s"<< m_redis->errstr); |
| | | DBG("RedisTool : Connection error: %s"<< m_redis->errstr); |
| | | redisFree(m_redis); |
| | | m_redis= nullptr; |
| | | } |
| | | else |
| | | { |
| | |
| | | return true; |
| | | } |
| | | |
| | | bool HiredisTool::setKeyImage(const std::string &file_name, const cv::Mat &img) |
| | | { |
| | | |
| | | |
| | | std::vector<uchar> buf; |
| | | Json::Value json; |
| | | |
| | | CvUtil::cvMat2Buffer(img,buf); |
| | | // json["time"]=info.time; |
| | | json["img"]=std::string(buf.begin(),buf.end()); |
| | | // buf.clear(); |
| | | // std::string strBuf=std::string(buf.begin(),buf.end()); |
| | | if(!setKeyValue(file_name,json.toStyledString())); |
| | | { |
| | | |
| | | return false; |
| | | } |
| | | |
| | | //DBG(json.toStyledString()); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | |
| | | void HiredisTool::getImage(const std::string& file_name, cv::Mat& img) |
| | | { |
| | | |
| | |
| | | |
| | | imgTep.copyTo(img); |
| | | // return img; |
| | | |
| | | } |
| | | |
| | | |
| | | void HiredisTool::getKeyImage(const std::string &imageName, cv::Mat &img) |
| | | { |
| | | |
| | | std::string content; |
| | | cv::Mat imgTep; |
| | | |
| | | getKeyValue(imageName,content); |
| | | |
| | | Json::Reader reader; |
| | | Json::Value value; |
| | | |
| | | if(!reader.parse(content,value)) |
| | | { |
| | | return ; |
| | | } |
| | | |
| | | std::string str=value["img"].asString(); |
| | | std::vector<uchar> data; |
| | | |
| | | data.resize(str.size()); |
| | | |
| | | data.assign(str.begin(),str.end()); |
| | | |
| | | CvUtil::buffer2CvMat(data,imgTep); |
| | | |
| | | imgTep.copyTo(img); |
| | | // return img; |
| | | } |
| | | |
| | | |
| | | //bool HiredisTool::setCameraState(const std::string& cam_id,const int& type) |
| | | //{ |
| | | // DBG("type="<<type); |
| | |
| | | return false; |
| | | } |
| | | |
| | | freeReplyObject(reply); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | bool HiredisTool::setKeyValue(const std::string &key, const std::string &value) |
| | | { |
| | | if(!checkParam()) |
| | | { |
| | | return false; |
| | | } |
| | | redisReply *reply; |
| | | |
| | | reply = (redisReply*)redisCommand(m_redis,"set %s %s", key.c_str(),value.c_str()); |
| | | if(!checkResult(reply)) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | freeReplyObject(reply); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | bool HiredisTool::getKeyValue(const std::string &key, std::string &value) |
| | | { |
| | | if(!checkParam()) |
| | | { |
| | | return false; |
| | | } |
| | | redisReply *reply; |
| | | //1.find all filename |
| | | reply = (redisReply*)redisCommand(m_redis,"get %s ", key.c_str()); |
| | | |
| | | if(!checkResult(reply)) |
| | | { |
| | | return false; |
| | | } |
| | | if(reply->type == REDIS_REPLY_STRING) |
| | | { |
| | | value=reply->str; |
| | | } |
| | | freeReplyObject(reply); |
| | | |
| | | return true; |
| | |
| | | { |
| | | if(m_redis == nullptr || m_redis->err) |
| | | { |
| | | if(m_redis) |
| | | { |
| | | redisFree(m_redis); |
| | | m_redis= nullptr; |
| | | } |
| | | DBG("Redis init Error !!!"); |
| | | init(); |
| | | return false; |