Пример #1
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 );
}
Пример #2
0
uint64_t CRedisClient::srandmember(const string &key, int count, CRedisClient::VecString &members)
{
    Command cmd( "SRANDMEMBER" );
    cmd << key << count ;

    return ( _getArry( cmd, members ) );
}
uint64_t CRedisClient::configGet(const string& parameter,CRedisClient::VecString& reply)
{
    Command cmd( "CONFIG" );
    cmd<<"GET";
    cmd<<parameter;
    return   _getArry(cmd,reply);
}
Пример #4
0
SInt64 RedisClient::keys( const std::string &pattern , VecString &values )
{
	BuildCommand cmd("KEYS");
	cmd << pattern;

	_getArry(cmd, values);
	return values.size();
}
Пример #5
0
uint64_t CRedisClient::hkeys(const string &key, CRedisClient::VecString &values)
{
    Command cmd( "HKEYS" );
    cmd << key;

    uint64_t num = 0;
    _getArry( cmd, values, num );
    return num;
}
Пример #6
0
uint64_t CRedisClient::hgetall(const string &key, CRedisClient::MapString &pairs)
{
    Command cmd( "HGETALL" );
    cmd << key;

    uint64_t num = 0;
    _getArry( cmd, pairs, num );
    return num;
}
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();
}
Пример #8
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;
}
Пример #9
0
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();
}
Пример #10
0
uint64_t CRedisClient::sinter(const CRedisClient::VecString &keys, VecString &values)
{
    Command cmd( "SINTER" );
    VecString::const_iterator it = keys.begin();
    VecString::const_iterator end = keys.end();
    for ( ; it != end; ++it )
    {
        cmd << *it;
    }

    return ( _getArry( cmd, values ) );
}
Пример #11
0
 void CRedisClient::subscribeStart(const VecString &channel, int timeout)
 {
     Command cmd( "SUBSCRIBE" );
     VecString::const_iterator it = channel.begin();
     for ( ; it != channel.end(); ++it )
     {
         cmd << *it ;
     }
     Poco::Timespan t(timeout, 0);
     _socket.setReceiveTimeout(t);
     CResult result;
     _getArry(cmd, result);
 }
Пример #12
0
uint64_t CRedisClient::sunion(const CRedisClient::VecString &keys , VecString &members)
{
    Command cmd( "SUNION" );

    VecString::const_iterator it = keys.begin();
    VecString::const_iterator end = keys.end();
    for ( ; it != end; ++it )
    {
        cmd << *it;
    }

    return ( _getArry( cmd, members ) );
}
Пример #13
0
void CRedisClient::hmget(const string &key, const CRedisClient::VecString &fields, CResult &result)
{
    Command cmd( "HMGET" );
    cmd << key;

    VecString::const_iterator it = fields.begin();
    VecString::const_iterator end = fields.end();
    for ( ; it != end; ++it )
    {
        cmd << *it;
    }

    _getArry( cmd , result );
}
Пример #14
0
bool RedisClient::sort( const string& key , VecString& values , const bool& desc )
{
	BuildCommand cmd("SORT");
	cmd << key;

	if ( desc )
		cmd << "DESC";

	if ( _getArry(cmd, values) )
	{
		return values.size();
	}
	return false;
}
Пример #15
0
 uint64_t CRedisClient::psubnumsub( CRedisClient::MapString& value, const VecString& channel )
 {
	Command cmd( "PUBSUB" );
	cmd << "NUMSUB";
	if ( channel.size() != 0 )
	{
		VecString::const_iterator it = channel.begin();
		for ( ; it != channel.end(); ++it )
		{
			cmd << *it ;
		}
	}

	return _getArry( cmd, value );
 }
Пример #16
0
 uint64_t CRedisClient::psubchannels( VecString& value, const VecString& pattern )
 {
	Command cmd( "PUBSUB" );
	cmd << "CHANNELS";

	if ( pattern.size() != 0 )
	{
		VecString::const_iterator it = pattern.begin();
		for ( ; it != pattern.end(); ++it )
		{
			cmd << *it ;
		}
	}

	return _getArry( cmd, value );
 }
Пример #17
0
 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 );
	}
 }
Пример #18
0
uint64_t CRedisClient::smembers( const string &key, CRedisClient::VecString &members )
{
    Command cmd( "SMEMBERS" );
    cmd << key;
    return ( _getArry( cmd, members ) );
}