mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-27 11:06:50 +01:00
Add sismember
This commit is contained in:
@@ -148,6 +148,9 @@ public:
|
|||||||
static Command sinterstore(const std::string& set, const std::vector<std::string>& sets);
|
static Command sinterstore(const std::string& set, const std::vector<std::string>& sets);
|
||||||
/// Returns a SINTERSTORE command
|
/// Returns a SINTERSTORE command
|
||||||
|
|
||||||
|
static Command sismember(const std::string& set, const std::string& member);
|
||||||
|
/// Returns a SISMEMBER command
|
||||||
|
|
||||||
static Command smembers(const std::string& set);
|
static Command smembers(const std::string& set);
|
||||||
/// Returns a SMEMBERS command
|
/// Returns a SMEMBERS command
|
||||||
|
|
||||||
|
|||||||
@@ -381,6 +381,15 @@ Command Command::sinterstore(const std::string& set, const std::vector<std::stri
|
|||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Command Command::sismember(const std::string& set, const std::string& member)
|
||||||
|
{
|
||||||
|
Command cmd("SISMEMBER");
|
||||||
|
|
||||||
|
cmd << set << member;
|
||||||
|
|
||||||
|
return cmd;
|
||||||
|
}
|
||||||
|
|
||||||
Command Command::smembers(const std::string& set)
|
Command Command::smembers(const std::string& set)
|
||||||
{
|
{
|
||||||
Command cmd("SMEMBERS");
|
Command cmd("SMEMBERS");
|
||||||
|
|||||||
@@ -1473,7 +1473,8 @@ void RedisTest::testSInterStore()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RedisTest::testStrlen()
|
|
||||||
|
void RedisTest::testSIsmember()
|
||||||
{
|
{
|
||||||
if (!_connected)
|
if (!_connected)
|
||||||
{
|
{
|
||||||
@@ -1481,29 +1482,35 @@ void RedisTest::testStrlen()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Array command;
|
delKey("myset");
|
||||||
command.add("SET").add("mykey").add("Hello World");
|
|
||||||
|
|
||||||
// A set responds with a simple OK string
|
Command sadd = Command::sadd("myset", "one");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
std::string result = _redis.execute<std::string>(command);
|
Poco::Int64 result = _redis.execute<Poco::Int64>(sadd);
|
||||||
assert(result.compare("OK") == 0);
|
assert(result == 1);
|
||||||
}
|
}
|
||||||
catch(RedisException &e)
|
catch(RedisException &e)
|
||||||
{
|
{
|
||||||
fail(e.message());
|
fail(e.message());
|
||||||
}
|
}
|
||||||
|
|
||||||
command.clear();
|
Command sismember = Command::sismember("myset", "one");
|
||||||
command.add("STRLEN")
|
|
||||||
.add("mykey");
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Poco::Int64 result = _redis.execute<Poco::Int64>(command);
|
Poco::Int64 result = _redis.execute<Poco::Int64>(sismember);
|
||||||
|
assert(result == 1);
|
||||||
|
}
|
||||||
|
catch(RedisException &e)
|
||||||
|
{
|
||||||
|
fail(e.message());
|
||||||
|
}
|
||||||
|
|
||||||
assert(result == 11);
|
sismember = Command::sismember("myset", "two");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Poco::Int64 result = _redis.execute<Poco::Int64>(sismember);
|
||||||
|
assert(result == 0);
|
||||||
}
|
}
|
||||||
catch(RedisException &e)
|
catch(RedisException &e)
|
||||||
{
|
{
|
||||||
@@ -1608,6 +1615,44 @@ 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()
|
void RedisTest::testSUnionStore()
|
||||||
{
|
{
|
||||||
if (!_connected)
|
if (!_connected)
|
||||||
@@ -2033,6 +2078,7 @@ CppUnit::Test* RedisTest::suite()
|
|||||||
CppUnit_addTest(pSuite, RedisTest, testSet);
|
CppUnit_addTest(pSuite, RedisTest, testSet);
|
||||||
CppUnit_addTest(pSuite, RedisTest, testSInter);
|
CppUnit_addTest(pSuite, RedisTest, testSInter);
|
||||||
CppUnit_addTest(pSuite, RedisTest, testSInterStore);
|
CppUnit_addTest(pSuite, RedisTest, testSInterStore);
|
||||||
|
CppUnit_addTest(pSuite, RedisTest, testSIsmember);
|
||||||
CppUnit_addTest(pSuite, RedisTest, testSMembers);
|
CppUnit_addTest(pSuite, RedisTest, testSMembers);
|
||||||
CppUnit_addTest(pSuite, RedisTest, testStrlen);
|
CppUnit_addTest(pSuite, RedisTest, testStrlen);
|
||||||
CppUnit_addTest(pSuite, RedisTest, testSUnion);
|
CppUnit_addTest(pSuite, RedisTest, testSUnion);
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ public:
|
|||||||
void testSet();
|
void testSet();
|
||||||
void testSInter();
|
void testSInter();
|
||||||
void testSInterStore();
|
void testSInterStore();
|
||||||
|
void testSIsmember();
|
||||||
void testSMembers();
|
void testSMembers();
|
||||||
void testSUnion();
|
void testSUnion();
|
||||||
void testSUnionStore();
|
void testSUnionStore();
|
||||||
|
|||||||
Reference in New Issue
Block a user