string CRedisClient::subscribe() { CResult result; _getReply(result); auto t = result.getArry().rbegin(); return *t; }
bool CRedisClient::hscan(const string &key, int64_t cursor, MapString &values, const string &match, uint64_t count ) { static uint64_t lastCur = 0; uint64_t realCur = 0; CResult result; if ( cursor >= 0 ) { realCur = cursor; }else { realCur = lastCur; } Command cmd( "HSCAN" ); cmd << key << realCur; if ( "" != match ) { cmd << "MATCH" << match; } if ( 0 != count ) { cmd << "COUNT" << count; } _getArry( cmd, result ); CResult::ListCResult::const_iterator it = result.getArry().begin(); lastCur = _valueFromString<uint64_t>( it->getString() ); ++it; _getStringMapFromArry( it->getArry(), values ); return ( lastCur == 0 ? false : true ); }
uint64_t CRedisClient::hgetall(const string &key, CRedisClient::MapString &values) { CResult result; hgetall( key, result ); ReplyType type = result.getType(); if ( REDIS_REPLY_ERROR == type ) { throw ReplyErr( result.getErrorString() ); }else if ( REDIS_REPLY_ARRAY != type ) { throw ProtocolErr( "HGETALL: data recv is not arry" ); } CResult::ListCResult::const_iterator it = result.getArry().begin(); CResult::ListCResult::const_iterator it2 = it; CResult::ListCResult::const_iterator end = result.getArry().end(); for ( ; it != end; ++it ) { it2 = it++; // the next element is value. values.insert( MapString::value_type( *it2, *it ) ); } return values.size(); }
void CRedisClient::hmget(const string &key, const CRedisClient::VecString &fields, CResult &result) { _socket.clearBuffer(); Command cmd( "HMGET" ); cmd << key; VecString::const_iterator it = fields.begin(); VecString::const_iterator end = fields.end(); for ( ; it != end; ++it ) { cmd << *it; } _sendCommand( cmd ); _getReply( result ); ReplyType type = result.getType(); if ( REDIS_REPLY_ERROR == type ) { throw ReplyErr( result.getErrorString() ); }else if ( REDIS_REPLY_ARRAY != type ) { throw ProtocolErr( "HMGET: data recved is not arry" ); } }
bool RedisClient::migrate( const string& key ,const string& host , const uint16_t& port , const uint16_t& db , const uint16_t& timeout ) { CResult result; BuildCommand cmd("MIGRATE"); cmd << host << port << key << db << timeout; SharedPtr<RedisConnection> connObj = GetRedisConnection(); if(connObj->SendCommand(cmd)) _getReply(result,connObj.get()); else{ LOG_ERROR("Send MIGRATE Command Error,cmd:%s",cmd.getCommand().c_str()); return false; } ReplyType type = result.getType(); if ( REDIS_REPLY_STATUS == type ) { //"+NOKEY" may returned if ( result.compare(0,2,"OK")==0 || result.compare(0,2,"ok")==0 ) return true; } return false; }
int __cdecl wmain ( IN int argc, IN wchar_t* args[] ) { time_t start = time( NULL ); CModelData modelData; if( !ParseArgs( argc, args, modelData ) ) { return( ErrorCode_BadOption ); } if( !modelData.ReadModel( wstring( args[ 1 ] ))) { return( ErrorCode_BadModel ); } if( !modelData.ReadRowSeedFile( modelData.RowSeedsFile )) { return( ErrorCode_BadRowSeedFile ); } GcdRunner gcdRunner( modelData ); ErrorCode err = gcdRunner.Generate(); if( err != ErrorCode_Success ) { return err; } time_t end = time( NULL ); // if r has been provided then print out the seed // TODO: change to not use SWITCH_RANDOMIZE const if( modelData.ProvidedArguments.find( SWITCH_RANDOMIZE ) != modelData.ProvidedArguments.end() ) { wcerr << L"Used seed: " << static_cast<int>( modelData.RandSeed ) << endl; } CResult result = gcdRunner.GetResult(); if( modelData.Statistics ) { modelData.PrintStatistics(); result.PrintStatistics(); PrintStatisticsCaption( wstring( L"Generation time" )); printTimeDifference( start, end ); } else { result.PrintConstraintWarnings(); result.PrintOutput( modelData ); } return( ErrorCode_Success ); }
void Segmentor::getGoldActions(const vector<Instance>& vecInsts, vector<vector<CAction> >& vecActions) { vecActions.clear(); static Metric segEval, posEval; static CStateItem state[m_classifier.MAX_SENTENCE_SIZE]; static CResult output; static CAction answer; segEval.reset(); posEval.reset(); static int numInstance, actionNum; vecActions.resize(vecInsts.size()); for (numInstance = 0; numInstance < vecInsts.size(); numInstance++) { const Instance &instance = vecInsts[numInstance]; actionNum = 0; state[actionNum].initSentence(&instance.chars, &instance.candidateLabels); state[actionNum].clear(); while (!state[actionNum].IsTerminated()) { state[actionNum].getGoldAction(instance, m_classifier.fe._postagAlphabet, answer); vecActions[numInstance].push_back(answer); state[actionNum].move(state + actionNum + 1, answer, m_classifier.fe._postagAlphabet); actionNum++; } if (actionNum - 1 != instance.charsize()) { std::cout << "action number is not correct, please check" << std::endl; } state[actionNum].getSegPosResults(output); instance.evaluate(output, segEval, posEval); if (!segEval.bIdentical() || !posEval.bIdentical()) { std::cout << "error state conversion!" << std::endl; std::cout << "output instance:" << std::endl; for (int tmpK = 0; tmpK < instance.words.size(); tmpK++) { std::cout << instance.words[tmpK] << "_" << instance.postags[tmpK] << " "; } std::cout << std::endl; std::cout << "predicated instance:" << std::endl; for (int tmpK = 0; tmpK < output.size(); tmpK++) { std::cout << output.words[tmpK] << "_" << output.postags[tmpK] << " "; } std::cout << std::endl; exit(0); } if ((numInstance + 1) % m_options.verboseIter == 0) { cout << numInstance + 1 << " "; if ((numInstance + 1) % (40 * m_options.verboseIter) == 0) cout << std::endl; cout.flush(); } if (m_options.maxInstance > 0 && numInstance == m_options.maxInstance) break; } }
void CRedisClient::time(string& currentseconds,string& microseconds) { CResult result; Command cmd( "TIME" ); _getArry(cmd,result); CResult::ListCResult::const_iterator it = result.getArry().begin(); currentseconds=it->getString(); ++it; microseconds=it->getString(); }
int RedisClient::scan( VecString& values , const int& index , const string& pattern , const int& count ) { BuildCommand cmd("SCAN"); string val; SInt64 nextNo; CResult arry; cmd << index; if ( !pattern.empty() ) { LOG_DEBUG("PATTERN:%s", pattern.c_str()); cmd << "MATCH" << pattern; } if ( count > 0 && count != 10 ) { LOG_DEBUG("PATTERN:%s", pattern.c_str()); cmd << "COUNT" << count; } if ( !_getArry(cmd, arry) ) return -1; CResult::ListCResult arrList = arry.getArry(); if ( arrList.size() != 2 ) return -2; CResult::ListCResult::const_iterator it = arrList.begin(); val = it->getString(); //throw TypeErr std::istringstream istr(val); istr >> nextNo; if ( istr.fail() ) { LOG_ERROR("%s: data received is unexpected",val.c_str()); } LOG_DEBUG("nextNo:%ld", nextNo); ++it; CResult::ListCResult::const_iterator itKeybgein = it->getArry().begin(); CResult::ListCResult::const_iterator itKeyend = it->getArry().end(); values.clear(); while ( itKeybgein != itKeyend ) { val = itKeybgein->getString(); values.push_back(val); itKeybgein++; } return nextNo; }
bool RedisClient::scriptExists( const string& script ) { BuildCommand cmd("SCRIPT"); cmd << "EXISTS" << script; CResult rst; _getArry(cmd, rst); CResult::ListCResult lst = rst.getArry(); CResult::ListCResult::const_iterator it = lst.begin(); return it->getInt(); }
void CConsole::ConUserCommandStatus(IResult *pResult, void *pUser) { CConsole* pConsole = static_cast<CConsole *>(pUser); CResult Result; Result.m_pCommand = "access_status"; char aBuf[4]; str_format(aBuf, sizeof(aBuf), "%d", IConsole::ACCESS_LEVEL_USER); Result.AddArgument(aBuf); pConsole->ConCommandStatus(&Result, pConsole); }
//***************************************************************************** // クリエイト //***************************************************************************** CResult* CResult::Create(MODE_PHASE mode, LPDIRECT3DDEVICE9* pDevice) { CResult* pTitle = NULL; // 作成 pTitle = new CResult; // 初期化 pTitle->Init(mode, pDevice); return pTitle; }
void CRedisClient::hmset(const string &key, const CRedisClient::MapString &pairs) { CResult result; hmset( key, pairs ,result ); ReplyType type = result.getType(); if ( REDIS_REPLY_ERROR == type ) { throw ReplyErr( result.getErrorString() ); }else if ( REDIS_REPLY_STATUS != type ) { throw ProtocolErr( "HMSET: data recved is not status" ); } }
uint64_t CRedisClient::hlen(const string &key) { CResult result; hlen( key, result ); ReplyType type = result.getType(); if ( REDIS_REPLY_ERROR == type ) { throw ReplyErr( result.getErrorString() ); }else if ( REDIS_REPLY_INTEGERER != type ) { throw ProtocolErr( "HLEN: data recved is not intergerer" ); } return result.getInt(); }
bool CRedisClient::hsetnx(const string &key, const string &field, const string &value) { CResult result; hsetnx( key, field, value,result ); ReplyType type = result.getType(); if ( REDIS_REPLY_ERROR == type ) { throw ReplyErr( result.getErrorString() ); }else if ( REDIS_REPLY_INTEGERER != type ) { throw ProtocolErr( "HSETNX: data recved is not intergerer" ); } return ( result.getInt()==1?true:false ); }
uint64_t CRedisClient::hincrby(const string &key, const string &field, uint64_t increment) { CResult result; hincrby( key, field, increment,result ); ReplyType type = result.getType(); if ( REDIS_REPLY_ERROR == type ) { throw ReplyErr( result.getErrorString() ); }else if ( REDIS_REPLY_INTEGERER != type ) { throw ProtocolErr( "HINCRBY: data recved is not intgerer" ); } return result.getInt(); }
float CRedisClient::hincrbyfloat(const string &key, const string &field, float increment) { CResult result; hincrbyfloat( key, field, increment,result ); ReplyType type = result.getType(); if ( REDIS_REPLY_ERROR == type ) { throw ReplyErr( result.getErrorString() ); }else if ( REDIS_REPLY_STRING != type ) { throw ProtocolErr( "HINCRBYFLOAT: data recved is not string" ); } return _valueFromString<float>( result.getString() ); }
bool CRedisClient::hexists(const string &key, const string &field) { CResult result; hexists( key, field, result ); ReplyType type = result.getType(); if ( REDIS_REPLY_ERROR == type ) { throw ReplyErr( result.getErrorString() ); }else if ( REDIS_REPLY_INTEGERER != type ) { throw ProtocolErr( "HEXISTS: data recv is not intgerer" ); } return result.getInt(); }
uint64_t CRedisClient::hdel( const string &key, const CRedisClient::VecString &fields ) { CResult result; hdel( key, fields, result ); ReplyType type = result.getType(); if ( REDIS_REPLY_ERROR == type ) { throw ReplyErr( result.getErrorString() ); }else if ( REDIS_REPLY_INTEGERER != type ) { throw ProtocolErr( "HDEL: data recv is not intgerer" ); } return result.getInt(); }
uint64_t CRedisClient::hkeys(const string &key, CRedisClient::VecString &values) { CResult result; hkeys( key, result ); ReplyType type = result.getType(); if ( REDIS_REPLY_ERROR == type ) { throw ReplyErr( result.getErrorString() ); }else if ( REDIS_REPLY_ARRAY != type ) { throw ProtocolErr("HKEYS: data recved is not arry"); } _getValueFromArry( result.getArry(), values ); return values.size(); }
void CRedisClient::psubscribe( const VecString& pattern, CResult& result) { Command cmd( "PSUBSCRIBE" ); VecString::const_iterator it = pattern.begin(); for ( ; it != pattern.end(); ++it ) { cmd << *it; } _socket.setReceiveTimeout(0); result.clear(); _getArry( cmd, result ); while(true) { result.clear(); _getReply( result ); } }
uint8_t CRedisClient::hset(const std::string &key, const std::string &field, const std::string &value) { CResult result; hset( key, field, value, result ); ReplyType type = result.getType(); if ( type == REDIS_REPLY_ERROR ) { throw ReplyErr( result.getErrorString() ); } if ( type != REDIS_REPLY_INTEGERER ) { throw ProtocolErr( "HSET: data recved is not integerer" ); } return result.getInt(); }
bool CRedisClient::setXX(const std::string &key, const std::string &value) { CResult result; _set( key, value, result,"XX" ); if ( result.getType() == REDIS_REPLY_ERROR ) { throw ReplyErr( result.getErrorString() ); } else if ( result.getType() == REDIS_REPLY_NIL ) { return false; }else if ( result.getType() == REDIS_REPLY_STATUS ) { return true; }else { throw ProtocolErr( "SET: data recved is not status" ); } }
bool TestDspCmdDirGetVmList::getResultVmList(QList<QDomDocument>& listResult, CResult& _result) { QString errorMsg; int errorLine, errorColumn; listResult.clear(); for (int i = 0; i < _result.GetParamsCount(); i++) { listResult.push_back(QDomDocument()); if (!listResult[i].setContent(_result.GetParamToken(i), false, &errorMsg, &errorLine, &errorColumn )) { WRITE_TRACE(DBG_FATAL, "error in result: [idx=%d], errorMsg=%s, line=%d, column=%d", i , errorMsg.toUtf8().data(), errorLine, errorColumn); WRITE_TRACE(DBG_FATAL, "[%s]\n", _result.GetParamToken(i).toUtf8().data()); listResult.clear(); return false; } } return true; }
uint64_t CRedisClient::hvals(const string &key, CRedisClient::VecString &values) { CResult result; hvals( key, result ); ReplyType type = result.getType(); if ( REDIS_REPLY_ERROR == type ) { throw ReplyErr( result.getErrorString() ); }else if ( REDIS_REPLY_ARRAY != type ) { throw ProtocolErr( "HVALS: data recved is not arry"); } CResult::ListCResult::const_iterator it = result.getArry().begin(); CResult::ListCResult::const_iterator end = result.getArry().end(); for ( ; it != end; ++it ) { values.push_back( static_cast<string>(*it) ); } return values.size(); }
bool CRedisClient::get( const std::string &key, std::string &value ) { value.clear(); CResult result; get( key, result ); ReplyType type = result.getType(); if ( type == REDIS_REPLY_ERROR ) { throw ReplyErr( result.getErrorString() ); }else if ( type == REDIS_REPLY_NIL ) { return false; }else if ( type == REDIS_REPLY_STRING ) { value = result.getString(); return true; }else { throw ProtocolErr( "GET: data recved is not string" ); } }
void CRedisClient::_set(const std::string &key,const std::string &value) { CResult result; _set( key, value, result ); if ( result.getType() == REDIS_REPLY_ERROR ) { throw ReplyErr( result.getErrorString() ); }else if ( result.getType() == REDIS_REPLY_STATUS ) { if ( result.getStatus() == "OK" ) { return; }else { throw ProtocolErr( "SET: data recved is not OK" ); } }else { throw ProtocolErr( "SET: data recved is not status" ); } }
std::string CResult::display( const CResult &ele, int indent ) { ReplyType e = ele.getType( ); string type =CResult::getTypeString( e ); std::stringstream out; if ( REDIS_REPLY_ARRAY == e ) { CResult::ListCResult::const_iterator it = ele.getArry().begin() ; indent += 3; out <<"{\n"; for ( int i = 0; i < indent; i++ ) out << " "; indent += 3; out << "type:" << type <<", value:[" << std::endl; for ( ; it!=ele.getArry().end(); it++ ) { for ( int i = 0; i < indent; i++ ) out << " "; out << display( *it, indent ) << std::endl; } for ( int i = 0; i < indent-3; i++ ) out << " "; out << "]\n"; for ( int i = 0; i < indent-6; i++ ) out << " "; out << "};"; }else { out << "{type: " << type << " ,value: " << std::string( ele ) << "};"; } return out.str() ; }
bool CRedisClient::hscan(const string &key, int64_t cursor, VecString& values,const string &match, uint64_t count ) { static uint64_t lastCur = 0; uint64_t realCur = 0; CResult result; if ( cursor >= 0 ) { realCur = cursor; }else { realCur = lastCur; } hscan( key, realCur, match, count, result ); ReplyType type = result.getType() ; if ( REDIS_REPLY_ERROR == type ) { throw ReplyErr( result.getErrorString() ); }else if ( REDIS_REPLY_ARRAY != type ) { throw ProtocolErr( "HSCAN: data recved is not arry" ); } CResult::ListCResult::const_iterator it = result.getArry().begin(); if ( REDIS_REPLY_STRING != it->getType() ) { throw ProtocolErr( "HSCAN: first ele is not string" ); } lastCur = _valueFromString<uint64_t>( it->getString() ); ++it; _getValueFromArry( it->getArry(), values ); return ( lastCur == 0 ? false : true ); }
bool CRedisClient::setEX(const std::string &key, const std::string &value, long time, SET_OPTION opt ) { string suffix; if ( DEFAULT == opt ) { suffix.clear(); } else if ( NX == opt ) { suffix = "NX"; }else if ( XX == opt ) { suffix = "XX"; }else { return false; } CResult result; _set( key, value, result,"EX", time,suffix ); if ( result.getType() == REDIS_REPLY_ERROR ) { throw ReplyErr( result.getErrorString() ); } else if ( result.getType() == REDIS_REPLY_STATUS ) { return true; }else if ( result.getType() == REDIS_REPLY_NIL ) { return false; }else { throw ProtocolErr( "SET: data recved is not status" ); } }