Пример #1
0
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;
}
//-----------------------------string method--------------------------------------
void CRedisClient::_set(const string &key, const string &value, CResult &result, const string& suffix , long time,const string suffix2 )
{
    _socket.clearBuffer();

    Command cmd( "SET" );
    cmd << key << value;

    if ( suffix != "" )
    {
        cmd << suffix;
    }

    if ( time != 0 )
    {
        std::stringstream ss;
        ss << time ;
        cmd << ss.str();
    }
    if ( suffix2 != "" )
    {
        cmd << suffix2;
    }
    _sendCommand( cmd );
    _getReply( result );
}
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" );
    }
}
Пример #4
0
 string CRedisClient::subscribe()
 {
     CResult result;
     _getReply(result);
     auto t = result.getArry().rbegin();
     return *t;
 }
void CRedisClient::hvals(const string &key, CResult &result)
{
    _socket.clearBuffer();
    Command cmd( "HVALS" );
    cmd << key ;
    _sendCommand( cmd );
    _getReply( result );
}
void CRedisClient::hincrbyfloat(const string &key, const string &field, float increment, CResult &result)
{
    _socket.clearBuffer();
    Command cmd( "HINCRBYFLOAT" );
    cmd << key << field << increment;
    _sendCommand( cmd );
    _getReply( result );
}
void CRedisClient::hexists(const string &key, const string &field, CResult &result)
{
    _socket.clearBuffer();;
    Command cmd( "HEXISTS" );
    cmd << key << field;
    _sendCommand( cmd );
    _getReply( result );
}
void CRedisClient::hsetnx(const string &key, const string &field, const string &value, CResult &result)
{
    _socket.clearBuffer();
    Command cmd( "HSETNX" );
    cmd << key << field << value;

    _sendCommand( cmd );
    _getReply( result );
}
void CRedisClient::get(const std::string &key, CResult& result )
{
    _socket.clearBuffer();

    Command cmd( "GET" );
    cmd << key ;
    _sendCommand( cmd );

    _getReply( result );
}
void CRedisClient::slowlog(const CRedisClient::VecString &subcommand, CResult &reply)
{
    Command cmd( "SLOWLOG" );
    _socket.clearBuffer();
    VecString::const_iterator it = subcommand.begin();
    VecString::const_iterator  end=subcommand.end();
    for ( ; it !=end; ++it )
    {
        cmd << *it;
    }
    _sendCommand(cmd);
    _getReply(reply);
}
void CRedisClient::hdel(const string &key, const CRedisClient::VecString &fields, CResult &result )
{
    _socket.clearBuffer();;
    Command cmd( "HDEL" );
    cmd << key;

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

    _sendCommand( cmd );
    _getReply( result );
}
Пример #12
0
 void CRedisClient::punsubscribe( CResult& result, const VecString& pattern )
 {
	_socket.clearBuffer();

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

    _getReply( result );
 }
Пример #13
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 );
	}
 }
void CRedisClient::hmset(const string &key, const CRedisClient::MapString &pairs, CResult &result)
{
    _socket.clearBuffer();;
    Command cmd( "HMSET" );
    cmd << key;
    MapString::const_iterator it = pairs.begin();
    MapString::const_iterator end = pairs.end();

    for ( ; it !=end ; ++it )
    {
        cmd << it->first;
        cmd << it->second;
    }

    _sendCommand( cmd );
    _getReply( result );
}
void CRedisClient::hscan(const string &key, int64_t cursor, const string &match, uint64_t count, CResult &result)
{
    _socket.clearBuffer();
    Command cmd( "HSCAN" );
    cmd << key << cursor;

    if ( "" != match )
    {
          cmd << "MATH" << match;
    }

    if ( 0 != count )
    {
           cmd << "COUNT" << count;
    }

    _sendCommand( cmd );
    _getReply( result );
}
Пример #16
0
bool RedisClient::eval( CResult& values , const string& script , const VecString& keysVec ,
		const VecString& argsVec )
{
	BuildCommand cmd("EVAL");
	string status;
	int len = keysVec.size();

	cmd << script << len;
	for ( int i = 0 ; i < len ; i++ )
	{
		cmd << keysVec[i];
	}

	len = argsVec.size();
	for ( int i = 0 ; i < len ; i++ )
	{
		cmd << argsVec[i];
	}

	return _getReply(values,cmd);
}