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();
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
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 );
}
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 );
}