void TestSconfigRewrite(){
    CRedisClient redis;
    redis.connect( "127.0.0.1", 6379 );
    cout << "------test configRewrite------" << endl;
    redis.configRewrite();
    TestServerPrint("redis.configRewrite()","ok");
}
void TestPfmerge( void )
{
	try
	{
		CRedisClient redis;
		redis.connect("127.0.0.1", 6379);

		CRedisClient::VecString element;
		element.push_back("a");
		element.push_back("b");
		element.push_back("c");
		string key1("key1");
		redis.pfadd(key1, element);

		CRedisClient::VecString element2;
		element2.push_back("a");
		element2.push_back("d");
		string key2("key2");
		redis.pfadd(key2, element2);

		CRedisClient::VecString keys;
		keys.push_back(key1);
		keys.push_back(key2);
		bool flag = redis.pfmerge("test", keys);
		cout << flag << endl;
	} catch( RdException& e )
	{
		std::cout << "Redis exception:" << e.what() << std::endl;
	} catch( Poco::Exception& e )
	{
		std::cout << "Poco_exception:" << e.what() << std::endl;
	}
}
void TestSconfigSet(){
    CRedisClient redis;
    redis.connect( "127.0.0.1", 6379 );
    cout << "------test configSet------" << endl;
    redis.configSet("slowlog-max-lendsa","1024");
    TestServerPrint("redis.configSet(slowlog-max-len,1024)","ok" );
}
Beispiel #4
0
void TestLindex( void )
{
	try
	{

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

        std::string value;

        if ( !redis.lindex(mykey, 3, value) )
        {
            std::cout << "lindex failed!!" << std::endl;
        }else
        {
            std::cout << value << 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;
	}
}
void TestSsave(){
    CRedisClient redis;
    redis.connect( "127.0.0.1", 6379 );
    cout << "------test save------" << endl;
    redis.save();
    TestServerPrint("redis.save()","ok");
}
void TestLrange( void )
{
	try
	{
		CRedisClient redis;
		redis.connect("127.0.0.1", 6379);
		string mykey = "key";

		CRedisClient::VecString value;
		int64_t start = 0;
		int64_t stop = 33;
		uint64_t count = redis.lrange(mykey, start, stop, value);
		std::cout << count << std::endl;
		CRedisClient::VecString::const_iterator it = value.begin();
		CRedisClient::VecString::const_iterator end = value.end();
		while ( it != end )
		{
			cout << *it << 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;
	}
}
Beispiel #7
0
void TestRpop( void )
{
	try
	{
		CRedisClient redis;
		redis.connect("127.0.0.1", 6379);
		string mykey = "key";

		std::string value;
        if ( !redis.rpop(mykey, value) )
        {
            std::cout << "rpop failed!!" << std::endl;
        }else
        {
            std::cout << "rpop successful!!" << std::endl;
            std::cout << value << 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;
	}
}
void TestSclientKill(){
    CRedisClient redis;
    redis.connect( "127.0.0.1", 6379 );
    cout << "------test clientKill------" << endl;
    //用 clientList 查看 port ip
    redis.clientKill("127.0.0.1",33831);
}
void TestSshutdown(){
    CRedisClient redis;
    redis.connect( "127.0.0.1", 6379 );
    cout << "------test shutdown------" << endl;
    string info;
    TestServerPrint("redis.shutdown()",redis.shutdown( info ));
    std::cout << "info" << info << std::endl;
}
void TestStime(){
    CRedisClient redis;
    redis.connect( "127.0.0.1", 6379 );
    cout << "------test time------" << endl;
    string cur,mic;
    redis.time(cur,mic);
    cout<<"redis.time(cur,mic): "<<"cur="<<cur<<",mic="<<mic<<endl;
}
void TestSclientSetname(){
    CRedisClient redis;
    redis.connect( "127.0.0.1", 6379 );

    cout << "------test clientSetname------" << endl;
    redis.clientSetname("");
    TestServerPrint("redis.clientSetname(qwert)","OK");
}
void *MonitorStop( void *a )
{
    CRedisClient* client = (CRedisClient*)a;
    std::cout << "input Enter to stop monitor!!" << std::endl;
    getchar();
    client->monitorStop();
    return NULL;
}
void TestSclientList(){
    CRedisClient redis;
    redis.connect( "127.0.0.1", 6379 );
    cout << "------test clientList------" << endl;
    VEC vec;
    uint64_t num = redis.clientList(vec);
    std::cout << "clientNum:" << num << std::endl;
    TestServerPrint("redis.clientList(vec)",vec);
}
void TestSconfigGet(){
    CRedisClient redis;
    redis.connect( "127.0.0.1", 6379 );
    cout << "------test configGet------" << endl;
    VEC vec;
    uint64_t num = redis.configGet("sssss",vec);
    std::cout << "config get :" << num << std::endl;
    TestServerPrint("redis.configGet(s*,vec);",vec);
}
void TestSinfo(){
    CRedisClient redis;
    redis.connect( "127.0.0.1", 6379 );
    cout << "------test info------" << endl;
    string str;
    VEC vec;
    redis.info(vec,"serverdsads");
    TestServerPrint("redis.info(vec)",vec);
}
void TestSslowlog(){
    CRedisClient redis;
    redis.connect( "127.0.0.1", 6379 );
    cout << "------test slowlog------" << endl;
    VEC vec;
    vec.push_back("GET");
    CResult res;
    redis.slowlog(vec,res);
    cout<<res<<endl;
}
Beispiel #17
0
void TestBlpop( void )
{
	try
	{
		CRedisClient redis;
		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 = 2;

        if ( !redis.blpop(keys, timeout, value) )
        {
            std::cout << "blpop failed" << std::endl;
        }else
        {
            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;
	}
}
Beispiel #18
0
CRedisClient* CRcdLogClient::MakeRedisClient(std::string& address, int port)
{
	CRedisClient* pClient = new CRedisClient();
	if(pClient)
	{
		if(pClient->OnInit(address, port))
			return pClient;
		else
		{
			WLogError("CRcdLogClient::MakeRedisClient::OnInit error!, address = %s, port=%d\n",
				address.c_str(), port);
		}
		delete pClient;
		pClient = NULL;
	}
	return NULL;
}
Beispiel #19
0
void TestLrem( void )
{
	try
	{
		CRedisClient redis;
		redis.connect("127.0.0.1", 6379);

        uint64_t num = redis.lrem("testList","yuhaiyang");
        std::cout << "num: " << num << 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;
	}
}
Beispiel #20
0
void TestQuit( void )
{
	try
	{
		CRedisClient redis;
		redis.connect("127.0.0.1", 6379);

		bool flag = redis.quit();
		cout << flag << endl;
	} catch( RdException& e )
	{
		std::cout << "Redis exception:" << e.what() << std::endl;
	} catch( Poco::Exception& e )
	{
		std::cout << "Poco_exception:" << e.what() << std::endl;
	}
}
void TestSclientGetname(){
    CRedisClient redis;
    redis.connect( "127.0.0.1", 6379 );
    cout << "------test clientGetname------" << endl;
    string cName;

    if ( redis.clientGetname(cName))
        TestServerPrint("redis.clientGetname()",cName);
    else
        std::cout<<"no clientName"<<std::endl;
    redis.clientSetname("");

    if ( redis.clientGetname(cName))
        TestServerPrint("redis.clientGetname()",cName);
    else
        std::cout<<"no clientName"<<std::endl;
}
Beispiel #22
0
void TestLset( void )
{
	try
	{
		CRedisClient redis;
		redis.connect("127.0.0.1", 6379);
        string mykey = "testList";

        redis.lset(mykey, 10, "haha");
	} catch( RdException& e )
	{
		std::cout << "Redis exception:" << e.what() << std::endl;
	} catch( Poco::Exception& e )
	{
		std::cout << "Poco_exception:" << e.what() << std::endl;
	}
}
Beispiel #23
0
void TestAuth( void )
{
	try
	{
		CRedisClient redis;
		redis.connect("127.0.0.1", 6379);

		string value;
		bool flag = redis.auth("1234");
		cout << flag << endl;
	} catch( RdException& e )
	{
		std::cout << "Redis exception:" << e.what() << std::endl;
	} catch( Poco::Exception& e )
	{
		std::cout << "Poco_exception:" << e.what() << std::endl;
	}
}
Beispiel #24
0
void TestLinsert( void )
{
	try
	{
		CRedisClient redis;
		redis.connect("127.0.0.1", 6379);
        string mykey = "testList";

        int64_t count = redis.linsert(mykey, BEFORE, "zhongwei", "hello");
		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;
	}
}
Beispiel #25
0
void TestRpushx( void )
{
	try
	{
		CRedisClient redis;
		redis.connect("127.0.0.1", 6379);
		string mykey = "key";
		string value = "y";

		int64_t count = redis.rpushx(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;
	}
}
Beispiel #26
0
void TestLset( void )
{
	try
	{
		CRedisClient redis;
		redis.connect("127.0.0.1", 6379);
		string mykey = "key";

		uint64_t index = 1;
		bool flag = redis.lset(mykey, index, "haha");
		std::cout << flag << 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;
	}
}
Beispiel #27
0
void TestEcho( void )
{
	try
	{
		CRedisClient redis;
		redis.connect("127.0.0.1", 6379);

		string value;
		bool flag = redis.echo("hello world", value);
		cout << flag << endl;
		cout << value << endl;
	} catch( RdException& e )
	{
		std::cout << "Redis exception:" << e.what() << std::endl;
	} catch( Poco::Exception& e )
	{
		std::cout << "Poco_exception:" << e.what() << std::endl;
	}
}
Beispiel #28
0
void TestBrpoplpush( void )
{
	try
	{
		CRedisClient redis;
		redis.connect("127.0.0.1", 6379);

		string value;
        bool flag=redis.brpoplpush("source", "dest", 1, value);
		cout<<flag<<endl;
		cout<<value<<endl;
	} catch( RdException& e )
	{
		std::cout << "Redis exception:" << e.what() << std::endl;
	} catch( Poco::Exception& e )
	{
		std::cout << "Poco_exception:" << e.what() << std::endl;
	}
}
Beispiel #29
0
void TestLrem( void )
{
	try
	{
		CRedisClient redis;
		redis.connect("127.0.0.1", 6379);
		string mykey = "key";

		uint64_t num = 3;
		int64_t count = redis.lrem(mykey, num, "hello");
//		int64_t count=redis.linsert(mykey,"after","b","world");
		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;
	}
}
Beispiel #30
0
void TestLtrim( void )
{
	try
	{
		CRedisClient redis;
		redis.connect("127.0.0.1", 6379);
		string mykey = "key";

		uint64_t start = 1;
		uint64_t stop = 2;
		bool flag = redis.ltrim(mykey, start, stop);
		std::cout << flag << 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;
	}
}