Ejemplo n.º 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 );
}
Ejemplo n.º 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);
}
Ejemplo n.º 4
0
SInt64 RedisClient::keys( const std::string &pattern , VecString &values )
{
	BuildCommand cmd("KEYS");
	cmd << pattern;

	_getArry(cmd, values);
	return values.size();
}
Ejemplo n.º 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;
}
Ejemplo n.º 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();
}
Ejemplo n.º 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;
}
Ejemplo n.º 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();
}
Ejemplo n.º 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 ) );
}
Ejemplo n.º 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);
 }
Ejemplo n.º 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 ) );
}
Ejemplo n.º 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 );
}
Ejemplo n.º 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;
}
Ejemplo n.º 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 );
 }
Ejemplo n.º 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 );
 }
Ejemplo n.º 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 );
	}
 }
Ejemplo n.º 18
0
uint64_t CRedisClient::smembers( const string &key, CRedisClient::VecString &members )
{
    Command cmd( "SMEMBERS" );
    cmd << key;
    return ( _getArry( cmd, members ) );
}