StrMap RedisClient::HMGet(const std::string& key, const StrVec& vec){ StrMap map; if( key.empty() || vec.empty()) { return map; } std::stringstream sm; sm << "HMGET " << key; for(auto & i : vec) { sm << " " << i; } redisReply *redis_reply = RedoCommand(sm.str(),REDIS_REPLY_ARRAY); if( redis_reply ) { for (size_t i=0; i<redis_reply->elements; ++i) { auto reply = redis_reply->element[i]; if (reply->type == REDIS_REPLY_STRING) { map[vec[i]] = redis_reply->element[i]->str; } else if (reply->type == REDIS_REPLY_NIL) { LOGW("HMGet element" << vec[i] <<" is REDIS_REPLY_NIL! command="); map[vec[i]] =""; } } } freeReplyObject_Safe(redis_reply); return map; }
void Console::update() { StrVec tmpLog = Logger::getLog(); Logger::clearLog(); if(!tmpLog.empty() && tmpLog.at(0) != "") { for(unsigned int i = 0; i < tmpLog.size(); i++) { while(tmpLog.at(i).find("\n") != std::string::npos) tmpLog.at(i).erase(tmpLog.at(i).find("\n"), 1); addString(tmpLog.at(i)); } } }
Option(int argc, const char *const argv[]) { cybozu::Option opt; std::string charSetFile; std::string dicFile; bool debug; opt.appendOpt(&charSetFile, "", "cf", "char set file"); opt.appendOpt(&threadNum, 4, "t", "thread num"); opt.appendOpt(&dicFile, "", "d", "dictionary file"); opt.appendOpt(&passLen, 0, "l", "length of pass"); opt.appendBoolOpt(&debug, "v", "verbose message"); opt.appendHelp("h"); opt.appendParam(&encFile, "encrypted file"); if (!opt.parse(argc, argv)) { opt.usage(); exit(1); } if (debug) ms::setDebug(1); if (charSetFile.empty()) { charSet = "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789-_"; } else { std::ifstream ifs(charSetFile.c_str(), std::ios::binary); if (!std::getline(ifs, charSet)) { fprintf(stderr, "can't read char set file [%s]\n", charSetFile.c_str()); exit(1); } trim(charSet); } if (!dicFile.empty()) { std::ifstream ifs(dicFile.c_str(), std::ios::binary); std::string line; while (std::getline(ifs, line)) { trim(line); toUtf8(line); passSet.push_back(line); } if (passSet.empty()) { fprintf(stderr, "can't read dicFile [%s]\n", dicFile.c_str()); exit(1); } std::sort(passSet.begin(), passSet.end(), &lessByLength); } if (ms::isDebug()) { opt.put(); } }
void RedisClient::HDel(const std::string & hask_name, const StrVec & keys){ if( keys.empty() ) { LOGE("HDEL warning : keys is empty vector"); return ; } std::stringstream sm; sm << "HDEL "<< hask_name ; bool avaliad_param = false ; for( const auto & key : keys ) { if(key.empty()) continue; sm<<" "<<key; avaliad_param = true ; } if( !avaliad_param ) { LOGE("HDEL warning :all key are empty string .keys has " <<keys.size()); return ; } redisReply *redis_reply = RedoCommand(sm.str(),REDIS_REPLY_INTEGER); freeReplyObject_Safe(redis_reply); }
int RedisClient::SAdd(const std::string& key, const StrVec& value){ int result = 0; if(key.empty() || value.empty()) return result; std::stringstream sm; sm << "SADD " << key ; bool valid_param = false; for(auto & a : value) { if(a.empty()) continue; valid_param = true; sm<<" "<<a; } if(!valid_param){ LOGW("SAdd got zero valid param for set : "<<key); return 0; } redisReply *redis_reply = RedoCommand(sm.str(),REDIS_REPLY_INTEGER); if ( redis_reply ) { result = redis_reply->integer; } freeReplyObject_Safe(redis_reply); return result; }