mirror of
https://github.com/pocoproject/poco.git
synced 2025-01-31 06:35:03 +01:00
add srem
This commit is contained in:
parent
7c45bf4993
commit
7732d756ad
@ -157,6 +157,12 @@ public:
|
||||
static Command smove(const std::string& source, const std::string& destination, const std::string& member);
|
||||
/// Returns a SMOVE command
|
||||
|
||||
static Command srem(const std::string& set, const std::string& member);
|
||||
/// Returns a SREM command
|
||||
|
||||
static Command srem(const std::string& set, const std::vector<std::string>& member);
|
||||
/// Returns a SREM command
|
||||
|
||||
static Command sunion(const std::string& set1, const std::string& set2);
|
||||
/// Returns a SUNION command
|
||||
|
||||
|
@ -408,6 +408,28 @@ Command Command::smove(const std::string& source, const std::string& destination
|
||||
return cmd;
|
||||
}
|
||||
|
||||
Command Command::srem(const std::string& set1, const std::string& member)
|
||||
{
|
||||
Command cmd("SREM");
|
||||
|
||||
cmd << set1 << member;
|
||||
|
||||
return cmd;
|
||||
}
|
||||
|
||||
Command Command::srem(const std::string& set, const std::vector<std::string>& members)
|
||||
{
|
||||
Command cmd("SREM");
|
||||
|
||||
cmd << set;
|
||||
for(std::vector<std::string>::const_iterator it = members.begin(); it != members.end(); ++it)
|
||||
{
|
||||
cmd << *it;
|
||||
}
|
||||
|
||||
return cmd;
|
||||
}
|
||||
|
||||
Command Command::sunion(const std::string& set1, const std::string& set2)
|
||||
{
|
||||
Command cmd("SUNION");
|
||||
|
@ -1639,6 +1639,119 @@ void RedisTest::testSMove()
|
||||
}
|
||||
}
|
||||
|
||||
void RedisTest::testStrlen()
|
||||
{
|
||||
if (!_connected)
|
||||
{
|
||||
std::cout << "Not connected, test skipped." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
Array command;
|
||||
command.add("SET").add("mykey").add("Hello World");
|
||||
|
||||
// A set responds with a simple OK string
|
||||
try
|
||||
{
|
||||
std::string result = _redis.execute<std::string>(command);
|
||||
assert(result.compare("OK") == 0);
|
||||
}
|
||||
catch(RedisException &e)
|
||||
{
|
||||
fail(e.message());
|
||||
}
|
||||
|
||||
command.clear();
|
||||
command.add("STRLEN")
|
||||
.add("mykey");
|
||||
|
||||
try
|
||||
{
|
||||
Poco::Int64 result = _redis.execute<Poco::Int64>(command);
|
||||
|
||||
assert(result == 11);
|
||||
}
|
||||
catch(RedisException &e)
|
||||
{
|
||||
fail(e.message());
|
||||
}
|
||||
}
|
||||
|
||||
void RedisTest::testSRem()
|
||||
{
|
||||
if (!_connected)
|
||||
{
|
||||
std::cout << "Not connected, test skipped." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
delKey("myset");
|
||||
|
||||
Command sadd = Command::sadd("myset", "one");
|
||||
try
|
||||
{
|
||||
Poco::Int64 result = _redis.execute<Poco::Int64>(sadd);
|
||||
assert(result == 1);
|
||||
}
|
||||
catch(RedisException &e)
|
||||
{
|
||||
fail(e.message());
|
||||
}
|
||||
sadd = Command::sadd("myset", "two");
|
||||
try
|
||||
{
|
||||
Poco::Int64 result = _redis.execute<Poco::Int64>(sadd);
|
||||
assert(result == 1);
|
||||
}
|
||||
catch(RedisException &e)
|
||||
{
|
||||
fail(e.message());
|
||||
}
|
||||
sadd = Command::sadd("myset", "three");
|
||||
try
|
||||
{
|
||||
Poco::Int64 result = _redis.execute<Poco::Int64>(sadd);
|
||||
assert(result == 1);
|
||||
}
|
||||
catch(RedisException &e)
|
||||
{
|
||||
fail(e.message());
|
||||
}
|
||||
|
||||
Command srem = Command::srem("myset", "one");
|
||||
try
|
||||
{
|
||||
Poco::Int64 result = _redis.execute<Poco::Int64>(srem);
|
||||
assert(result == 1);
|
||||
}
|
||||
catch(RedisException &e)
|
||||
{
|
||||
fail(e.message());
|
||||
}
|
||||
|
||||
srem = Command::srem("myset", "four");
|
||||
try
|
||||
{
|
||||
Poco::Int64 result = _redis.execute<Poco::Int64>(srem);
|
||||
assert(result == 0);
|
||||
}
|
||||
catch(RedisException &e)
|
||||
{
|
||||
fail(e.message());
|
||||
}
|
||||
|
||||
Command smembers = Command::smembers("myset");
|
||||
try
|
||||
{
|
||||
Array result = _redis.execute<Array>(smembers);
|
||||
assert(result.size() == 2);
|
||||
}
|
||||
catch(RedisException &e)
|
||||
{
|
||||
fail(e.message());
|
||||
}
|
||||
}
|
||||
|
||||
void RedisTest::testSUnion()
|
||||
{
|
||||
if (!_connected)
|
||||
@ -1692,44 +1805,6 @@ void RedisTest::testSUnion()
|
||||
}
|
||||
}
|
||||
|
||||
void RedisTest::testStrlen()
|
||||
{
|
||||
if (!_connected)
|
||||
{
|
||||
std::cout << "Not connected, test skipped." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
Array command;
|
||||
command.add("SET").add("mykey").add("Hello World");
|
||||
|
||||
// A set responds with a simple OK string
|
||||
try
|
||||
{
|
||||
std::string result = _redis.execute<std::string>(command);
|
||||
assert(result.compare("OK") == 0);
|
||||
}
|
||||
catch(RedisException &e)
|
||||
{
|
||||
fail(e.message());
|
||||
}
|
||||
|
||||
command.clear();
|
||||
command.add("STRLEN")
|
||||
.add("mykey");
|
||||
|
||||
try
|
||||
{
|
||||
Poco::Int64 result = _redis.execute<Poco::Int64>(command);
|
||||
|
||||
assert(result == 11);
|
||||
}
|
||||
catch(RedisException &e)
|
||||
{
|
||||
fail(e.message());
|
||||
}
|
||||
}
|
||||
|
||||
void RedisTest::testSUnionStore()
|
||||
{
|
||||
if (!_connected)
|
||||
@ -2158,6 +2233,7 @@ CppUnit::Test* RedisTest::suite()
|
||||
CppUnit_addTest(pSuite, RedisTest, testSIsmember);
|
||||
CppUnit_addTest(pSuite, RedisTest, testSMembers);
|
||||
CppUnit_addTest(pSuite, RedisTest, testSMove);
|
||||
CppUnit_addTest(pSuite, RedisTest, testSRem);
|
||||
CppUnit_addTest(pSuite, RedisTest, testStrlen);
|
||||
CppUnit_addTest(pSuite, RedisTest, testSUnion);
|
||||
CppUnit_addTest(pSuite, RedisTest, testSUnionStore);
|
||||
|
@ -61,6 +61,7 @@ public:
|
||||
void testSIsmember();
|
||||
void testSMembers();
|
||||
void testSMove();
|
||||
void testSRem();
|
||||
void testSUnion();
|
||||
void testSUnionStore();
|
||||
void testStrlen();
|
||||
|
Loading…
x
Reference in New Issue
Block a user