1
0
mirror of https://github.com/pocoproject/poco.git synced 2025-04-02 09:49:48 +02:00

Add smove

This commit is contained in:
fbraem 2015-11-15 23:20:32 +01:00
parent 6dc3ac79c1
commit 7c45bf4993
4 changed files with 92 additions and 1 deletions
Redis
include/Poco/Redis
src
testsuite/src

@ -154,6 +154,9 @@ public:
static Command smembers(const std::string& set);
/// Returns a SMEMBERS command
static Command smove(const std::string& source, const std::string& destination, const std::string& member);
/// Returns a SMOVE command
static Command sunion(const std::string& set1, const std::string& set2);
/// Returns a SUNION command

@ -399,6 +399,15 @@ Command Command::smembers(const std::string& set)
return cmd;
}
Command Command::smove(const std::string& source, const std::string& destination, const std::string& member)
{
Command cmd("SMOVE");
cmd << source << destination << member;
return cmd;
}
Command Command::sunion(const std::string& set1, const std::string& set2)
{
Command cmd("SUNION");

@ -1473,7 +1473,6 @@ void RedisTest::testSInterStore()
}
}
void RedisTest::testSIsmember()
{
if (!_connected)
@ -1562,6 +1561,84 @@ void RedisTest::testSMembers()
}
}
void RedisTest::testSMove()
{
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("myotherset", "three");
try
{
Poco::Int64 result = _redis.execute<Poco::Int64>(sadd);
assert(result == 1);
}
catch(RedisException &e)
{
fail(e.message());
}
Command smove = Command::smove("myset", "myotherset", "two");
try
{
Poco::Int64 result = _redis.execute<Poco::Int64>(smove);
assert(result == 1);
}
catch(RedisException &e)
{
fail(e.message());
}
Command smembers = Command::smembers("myset");
try
{
Array result = _redis.execute<Array>(smembers);
assert(result.size() == 1);
assert(result.get<BulkString>(0).value().compare("one") == 0);
}
catch(RedisException &e)
{
fail(e.message());
}
smembers = Command::smembers("myotherset");
try
{
Array result = _redis.execute<Array>(smembers);
assert(result.size() == 2);
}
catch(RedisException &e)
{
fail(e.message());
}
}
void RedisTest::testSUnion()
{
if (!_connected)
@ -2080,6 +2157,7 @@ CppUnit::Test* RedisTest::suite()
CppUnit_addTest(pSuite, RedisTest, testSInterStore);
CppUnit_addTest(pSuite, RedisTest, testSIsmember);
CppUnit_addTest(pSuite, RedisTest, testSMembers);
CppUnit_addTest(pSuite, RedisTest, testSMove);
CppUnit_addTest(pSuite, RedisTest, testStrlen);
CppUnit_addTest(pSuite, RedisTest, testSUnion);
CppUnit_addTest(pSuite, RedisTest, testSUnionStore);

@ -60,6 +60,7 @@ public:
void testSInterStore();
void testSIsmember();
void testSMembers();
void testSMove();
void testSUnion();
void testSUnionStore();
void testStrlen();