mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-17 11:05:03 +02:00
Add hexists
This commit is contained in:
@@ -71,10 +71,13 @@ public:
|
||||
|
||||
static Command hdel(const std::string& hash, const std::string& field);
|
||||
/// Returns an HDEL command
|
||||
|
||||
|
||||
static Command hdel(const std::string& hash, const std::vector<std::string>& fields);
|
||||
/// Returns an HDEL command
|
||||
|
||||
static Command hexists(const std::string& hash, const std::string& field);
|
||||
/// Returns an HEXISTS command
|
||||
|
||||
static Command hget(const std::string& hash, const std::string& field);
|
||||
/// Returns an HGET command
|
||||
|
||||
|
@@ -140,6 +140,15 @@ Command Command::hdel(const std::string& hash, const std::vector<std::string>& f
|
||||
return cmd;
|
||||
}
|
||||
|
||||
Command Command::hexists(const std::string& hash, const std::string& field)
|
||||
{
|
||||
Command cmd("HEXISTS");
|
||||
|
||||
cmd << hash << field;
|
||||
|
||||
return cmd;
|
||||
}
|
||||
|
||||
Command Command::hget(const std::string& hash, const std::string& field)
|
||||
{
|
||||
Command cmd("HGET");
|
||||
|
@@ -418,6 +418,50 @@ void RedisTest::testHDEL()
|
||||
}
|
||||
}
|
||||
|
||||
void RedisTest::testHEXISTS()
|
||||
{
|
||||
if (!_connected)
|
||||
{
|
||||
std::cout << "Not connected, test skipped." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
delKey("myhash");
|
||||
|
||||
Command hset = Command::hset("myhash", "field1", "foo");
|
||||
try
|
||||
{
|
||||
Poco::Int64 value = _redis.execute<Poco::Int64>(hset);
|
||||
assert(value == 1);
|
||||
}
|
||||
catch(RedisException &e)
|
||||
{
|
||||
fail(e.message());
|
||||
}
|
||||
|
||||
Command hexists = Command::hexists("myhash", "field1");
|
||||
try
|
||||
{
|
||||
Poco::Int64 result = _redis.execute<Poco::Int64>(hexists);
|
||||
assert(result == 1);
|
||||
}
|
||||
catch(RedisException &e)
|
||||
{
|
||||
fail(e.message());
|
||||
}
|
||||
|
||||
hexists = Command::hexists("myhash", "field2");
|
||||
try
|
||||
{
|
||||
Poco::Int64 result = _redis.execute<Poco::Int64>(hexists);
|
||||
assert(result == 0);
|
||||
}
|
||||
catch(RedisException &e)
|
||||
{
|
||||
fail(e.message());
|
||||
}
|
||||
}
|
||||
|
||||
void RedisTest::testHSET()
|
||||
{
|
||||
if (!_connected)
|
||||
@@ -2483,6 +2527,7 @@ CppUnit::Test* RedisTest::suite()
|
||||
CppUnit_addTest(pSuite, RedisTest, testError);
|
||||
CppUnit_addTest(pSuite, RedisTest, testEVAL);
|
||||
CppUnit_addTest(pSuite, RedisTest, testHDEL);
|
||||
CppUnit_addTest(pSuite, RedisTest, testHEXISTS);
|
||||
CppUnit_addTest(pSuite, RedisTest, testHSET);
|
||||
CppUnit_addTest(pSuite, RedisTest, testINCR);
|
||||
CppUnit_addTest(pSuite, RedisTest, testINCRBY);
|
||||
|
@@ -38,6 +38,7 @@ public:
|
||||
void testError();
|
||||
void testEVAL();
|
||||
void testHDEL();
|
||||
void testHEXISTS();
|
||||
void testHSET();
|
||||
void testINCR();
|
||||
void testINCRBY();
|
||||
|
Reference in New Issue
Block a user