Add hexists

This commit is contained in:
fbraem
2015-11-17 21:38:07 +01:00
parent f618d7a5cf
commit 8d08cc3909
4 changed files with 59 additions and 1 deletions

View File

@@ -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

View File

@@ -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");

View File

@@ -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);

View File

@@ -38,6 +38,7 @@ public:
void testError();
void testEVAL();
void testHDEL();
void testHEXISTS();
void testHSET();
void testINCR();
void testINCRBY();