mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-25 02:06:04 +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);
|
static Command hdel(const std::string& hash, const std::string& field);
|
||||||
/// Returns an HDEL command
|
/// Returns an HDEL command
|
||||||
|
|
||||||
static Command hdel(const std::string& hash, const std::vector<std::string>& fields);
|
static Command hdel(const std::string& hash, const std::vector<std::string>& fields);
|
||||||
/// Returns an HDEL command
|
/// 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);
|
static Command hget(const std::string& hash, const std::string& field);
|
||||||
/// Returns an HGET command
|
/// Returns an HGET command
|
||||||
|
|
||||||
|
|||||||
@@ -140,6 +140,15 @@ Command Command::hdel(const std::string& hash, const std::vector<std::string>& f
|
|||||||
return cmd;
|
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 Command::hget(const std::string& hash, const std::string& field)
|
||||||
{
|
{
|
||||||
Command cmd("HGET");
|
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()
|
void RedisTest::testHSET()
|
||||||
{
|
{
|
||||||
if (!_connected)
|
if (!_connected)
|
||||||
@@ -2483,6 +2527,7 @@ CppUnit::Test* RedisTest::suite()
|
|||||||
CppUnit_addTest(pSuite, RedisTest, testError);
|
CppUnit_addTest(pSuite, RedisTest, testError);
|
||||||
CppUnit_addTest(pSuite, RedisTest, testEVAL);
|
CppUnit_addTest(pSuite, RedisTest, testEVAL);
|
||||||
CppUnit_addTest(pSuite, RedisTest, testHDEL);
|
CppUnit_addTest(pSuite, RedisTest, testHDEL);
|
||||||
|
CppUnit_addTest(pSuite, RedisTest, testHEXISTS);
|
||||||
CppUnit_addTest(pSuite, RedisTest, testHSET);
|
CppUnit_addTest(pSuite, RedisTest, testHSET);
|
||||||
CppUnit_addTest(pSuite, RedisTest, testINCR);
|
CppUnit_addTest(pSuite, RedisTest, testINCR);
|
||||||
CppUnit_addTest(pSuite, RedisTest, testINCRBY);
|
CppUnit_addTest(pSuite, RedisTest, testINCRBY);
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ public:
|
|||||||
void testError();
|
void testError();
|
||||||
void testEVAL();
|
void testEVAL();
|
||||||
void testHDEL();
|
void testHDEL();
|
||||||
|
void testHEXISTS();
|
||||||
void testHSET();
|
void testHSET();
|
||||||
void testINCR();
|
void testINCR();
|
||||||
void testINCRBY();
|
void testINCRBY();
|
||||||
|
|||||||
Reference in New Issue
Block a user