本文整理汇总了C++中credisclient::VecString::push_back方法的典型用法代码示例。如果您正苦于以下问题:C++ VecString::push_back方法的具体用法?C++ VecString::push_back怎么用?C++ VecString::push_back使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类credisclient::VecString
的用法示例。
在下文中一共展示了VecString::push_back方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TestPfmerge
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;
}
}
示例2: TestBrpop
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;
}
}
示例3: TestPfadd
void TestPfadd( 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 key("key1");
uint64_t count = redis.pfadd(key, element);
cout << count << endl;
} catch( RdException& e )
{
std::cout << "Redis exception:" << e.what() << std::endl;
} catch( Poco::Exception& e )
{
std::cout << "Poco_exception:" << e.what() << std::endl;
}
}
示例4: TestRpush
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;
}
}
示例5: stringToVecString
uint64_t CRedisClient::stringToVecString(string& str, CRedisClient::VecString& vec)
{
uint64_t i=0;
uint64_t len=str.length();
uint64_t posStart=0;
while(i<len)
{
if (str[i]=='\n')
{
vec.push_back(str.substr(posStart,i-posStart));
posStart=i+1;
}
++i;
}
return vec.size();
}
示例6: hvals
uint64_t CRedisClient::hvals(const string &key, CRedisClient::VecString &values)
{
CResult result;
hvals( key, result );
ReplyType type = result.getType();
if ( REDIS_REPLY_ERROR == type )
{
throw ReplyErr( result.getErrorString() );
}else if ( REDIS_REPLY_ARRAY != type )
{
throw ProtocolErr( "HVALS: data recved is not arry");
}
CResult::ListCResult::const_iterator it = result.getArry().begin();
CResult::ListCResult::const_iterator end = result.getArry().end();
for ( ; it != end; ++it )
{
values.push_back( static_cast<string>(*it) );
}
return values.size();
}
示例7: TestSet
///////////////////////////////////////////// test set //////////////////////////////////////////
void TestSet( void )
{
try
{
CRedisClient redis;
redis.connect( "127.0.0.1", 6379 );
//--------------------------test sadd-------------------------------
CRedisClient::VecString members;
members.push_back( "yuhaiyang" );
members.push_back( "zhouli" );
members.push_back( "严兴俊" );
uint64_t saddNum = redis.sadd( "testSet", members );
std::cout << "saddNum: " << saddNum << std::endl;
//-------------------------test scard--------------------------------
uint64_t scardNum = redis.scard( "testSet" );
std::cout << "scardNum:" << scardNum << std::endl;
//-------------------------test sdiff----------------------------------
std::cout << "=====================================sdiffData==========================" << std::endl;
CRedisClient::VecString keys;
keys.push_back("testSet");
keys.push_back("testSet2");
CRedisClient::VecString sdiffValues;
uint64_t sdiffNum = redis.sdiff( keys, sdiffValues );
std::cout << "sdiffNum: " << sdiffNum << std::endl;
//-------------------------test sdiffstore----------------------------
CRedisClient::VecString sdiffstorekeys;
sdiffstorekeys.push_back("testSet");
sdiffstorekeys.push_back("testSet2");
uint64_t sdiffstoreNum = redis.sdiffstore( "diffSetKey",sdiffstorekeys );
std::cout << "===========================sdiffNum=================================" << std::endl;
std::cout << "sdiffstoreNum: " << sdiffstoreNum << std::endl;
//---------------------------test sinter--------------------------------
CRedisClient::VecString sinterValues;
CRedisClient::VecString sinterKeys;
sinterKeys.push_back( "testSet" );
sinterKeys.push_back( "testSet2" );
uint64_t sinterNum = redis.sinter( sinterKeys, sinterValues );
std::cout << "===========================sinterNum================================" << std::endl;
std::cout << "sinterNum: " << sinterNum << std::endl;
CRedisClient::VecString::const_iterator sinterIt = sinterValues.begin();
CRedisClient::VecString::const_iterator sinterEnd = sinterValues.end();
for ( ; sinterIt != sinterEnd; ++sinterIt )
{
std::cout << "sinterIt: " << *sinterIt << std::endl;
}
//-----------------------------test sinterstore---------------------------
CRedisClient::VecString sinterstoreKeys;
sinterstoreKeys.push_back( "testSet" );
sinterstoreKeys.push_back( "testSet2" );
uint64_t sinterstoreNum = redis.sinterstore( "interSetKey", sinterstoreKeys );
std::cout << "sinterstoreNum: " << sinterstoreNum << std::endl;
//----------------------------test sismember----------------------------
bool ret = redis.sismember( "testSet", "yuhaiyang2" );
if ( ret )
{
std::cout << "存在" << std::endl;
}else
{
std::cout << "不存在" << std::endl;
}
CRedisClient::VecString membersMembers;
uint64_t smembersNum = redis.smembers( "testSet", membersMembers );
std::cout << "smembersNum" << smembersNum << std::endl;
PrintVector( "members", membersMembers );
//-----------------------------test smove-------------------------------------
bool smoveRet = redis.smove( "testSet2", "testSet","duzong");
if ( smoveRet )
{
std::cout << "smove ok" << std::endl;
}else
{
std::cout << "smove failed" << std::endl;
}
//-----------------------------test spop--------------------------------------
string spopMember;
bool spopRet = redis.spop( "testSet3", spopMember );
if ( spopRet )
{
std::cout << "spop ok" << std::endl;
std::cout << "spop data:" << spopMember << std::endl;
}else
{
std::cout << "spop faliled" << std::endl;
}
//-----------------------------test srandmember-----------------------------
string srandmember;
bool srandRet = redis.srandmember( "testSet3", srandmember );
if ( srandRet )
{
std::cout << "srandmember ok" <<std::endl;
std::cout << "srandmember data:" << srandmember << std::endl;
}else
{
//.........这里部分代码省略.........
示例8: TestHash
void TestHash( void )
{
try
{
CRedisClient redis;
redis.connect( "127.0.0.1", 6379 );
//-------------------------test hset hget---------------------------------
string value;
int32_t hashRet = redis.hset( "testHash", "name5", "{ \n\"value\" : \"yuhaiyang\"\r\n}\n" );
std::cout << "hashRet: " << hashRet << std::endl;
bool ret = redis.hget( "testHash", "name5" ,value );
std::cout << "ret: " << ret << std::endl;
std::cout << "value:" << value << std::endl;
//------------------------test hdel------------------------------------------
CRedisClient::VecString fields;
fields.push_back( "name4" );
fields.push_back( "name5" );
uint64_t delNum = redis.hdel( "member", fields );
std::cout << "delNum: " << delNum << std::endl;
//------------------------test hexists---------------------------------------
string field = "name4";
bool isExists = redis.hexists( "testHash", field );
if ( isExists )
std::cout << "testHash key exists field:" << field << std::endl;
else
std::cout << "testHash key not exists field:" << field << std::endl;
//-----------------------test hgetall-------------------------------------------
CRedisClient::MapString allValue;
uint64_t allNum = redis.hgetall( "testHash", allValue );
std::cout << "allNum: " << allNum <<std::endl;
CRedisClient::MapString::const_iterator it = allValue.begin();
for ( ; it != allValue.end(); it++ )
{
std::cout << it->first << ":" << it->second << std::endl;
}
//------------------------test incrby-------------------------------------------
uint64_t incrybyNum = redis.hincrby( "testHash", "num2", 20 );
std::cout << "incrybyNum: " << incrybyNum << std::endl;
//------------------------test incrbyfloat-------------------------------------
float floatNum = redis.hincrbyfloat( "testHash", "float", 10.1e2 );
std::cout << "floatNum: " << floatNum << std::endl;
//------------------------test hkeys-------------------------------------------
CRedisClient::VecString hkeysValue;
uint64_t hkeysNum = redis.hkeys( "testHash", hkeysValue );
std::cout << "hkeysNum: " << hkeysNum << std::endl;
CRedisClient::VecString::const_iterator hkeysit = hkeysValue.begin();
for ( ; hkeysit != hkeysValue.end(); hkeysit++ )
{
std::cout << *hkeysit << std::endl;
}
//------------------------test hlen-----------------------------------------------
// uint64_t fieldNum = redis.hlen( "testHash" );
// std::cout << "fieldNum: " << fieldNum << std::endl;
// //------------------------test hmget---------------------------------------------
// CResult result;
// CRedisClient::VecString hmgeFields;
// hmgeFields.push_back("name4");
// hmgeFields.push_back("yuhaiyang");
// hmgeFields.push_back("num");
// redis.hmget( "testHash", hmgeFields,result );
// std::cout << "hmget:" << std::endl;
// std::cout << result << 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;
}
}