Example #1
0
void TestBrpop( void )
{
	try
	{
		CRedisClient redis;
		redis.setTimeout(0,0);
		redis.connect("127.0.0.1", 6379);

		string key = "key";
		string key2 = "key2";
		CRedisClient::VecString keyValue;
		keyValue.push_back("a");
		keyValue.push_back("b");
		keyValue.push_back("c");
		CRedisClient::VecString key2Value;
		key2Value.push_back("1");
		key2Value.push_back("2");
		key2Value.push_back("3");

        redis.rpush(key, keyValue);
        redis.rpush(key2, key2Value);

		CRedisClient::VecString keys;
		keys.push_back("key");
		keys.push_back("key2");

		CRedisClient::MapString value;
		uint64_t timeout = 3;
        if ( !redis.brpop(keys, timeout, value) )
        {
            std::cout << "brpop falied" << std::endl;
            return;
        }

		CRedisClient::MapString::const_iterator it = value.begin();
		CRedisClient::MapString::const_iterator end = value.end();
		while ( it != end )
		{
			cout << it->first << endl;
			cout << it->second << endl;
			++it;
		}
	} catch( RdException& e )
	{
		std::cout << "Redis exception:" << e.what() << std::endl;
	} catch( Poco::Exception& e )
	{
		std::cout << "Poco_exception:" << e.what() << std::endl;
	}
}
Example #2
0
void TestRpush( void )
{
	try
	{

		CRedisClient redis;
		redis.connect("127.0.0.1", 6379);
		string mykey = "key";

		CRedisClient::VecString value;
		value.push_back("e");
		value.push_back("g");
		value.push_back("j");
		int count = redis.rpush(mykey, value);
		std::cout << count << std::endl;
	} catch( RdException& e )
	{
		std::cout << "Redis exception:" << e.what() << std::endl;
	} catch( Poco::Exception& e )
	{
		std::cout << "Poco_exception:" << e.what() << std::endl;
	}
}