mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-26 10:32:56 +01:00
Add hdel
This commit is contained in:
@@ -69,6 +69,12 @@ public:
|
||||
static Command get(const std::string& key);
|
||||
/// Returns an GET command
|
||||
|
||||
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 hget(const std::string& hash, const std::string& field);
|
||||
/// Returns an HGET command
|
||||
|
||||
|
||||
@@ -118,6 +118,28 @@ Command Command::get(const std::string& key)
|
||||
return cmd;
|
||||
}
|
||||
|
||||
Command Command::hdel(const std::string& hash, const std::string& field)
|
||||
{
|
||||
Command cmd("HDEL");
|
||||
|
||||
cmd << hash << field;
|
||||
|
||||
return cmd;
|
||||
}
|
||||
|
||||
Command Command::hdel(const std::string& hash, const std::vector<std::string>& fields)
|
||||
{
|
||||
Command cmd("HDEL");
|
||||
|
||||
cmd << hash;
|
||||
for(std::vector<std::string>::const_iterator it = fields.begin(); it != fields.end(); ++it)
|
||||
{
|
||||
cmd << *it;
|
||||
}
|
||||
|
||||
return cmd;
|
||||
}
|
||||
|
||||
Command Command::hget(const std::string& hash, const std::string& field)
|
||||
{
|
||||
Command cmd("HGET");
|
||||
|
||||
@@ -374,6 +374,50 @@ void RedisTest::testEval()
|
||||
|
||||
}
|
||||
|
||||
void RedisTest::testHDel()
|
||||
{
|
||||
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 hdel = Command::hdel("myhash", "field1");
|
||||
try
|
||||
{
|
||||
Poco::Int64 result = _redis.execute<Poco::Int64>(hdel);
|
||||
assert(result == 1);
|
||||
}
|
||||
catch(RedisException &e)
|
||||
{
|
||||
fail(e.message());
|
||||
}
|
||||
|
||||
hdel = Command::hdel("myhash", "field2");
|
||||
try
|
||||
{
|
||||
Poco::Int64 result = _redis.execute<Poco::Int64>(hdel);
|
||||
assert(result == 0);
|
||||
}
|
||||
catch(RedisException &e)
|
||||
{
|
||||
fail(e.message());
|
||||
}
|
||||
}
|
||||
|
||||
void RedisTest::testHSet()
|
||||
{
|
||||
if (!_connected)
|
||||
@@ -2438,6 +2482,7 @@ CppUnit::Test* RedisTest::suite()
|
||||
CppUnit_addTest(pSuite, RedisTest, testEcho);
|
||||
CppUnit_addTest(pSuite, RedisTest, testError);
|
||||
CppUnit_addTest(pSuite, RedisTest, testEval);
|
||||
CppUnit_addTest(pSuite, RedisTest, testHDel);
|
||||
CppUnit_addTest(pSuite, RedisTest, testHSet);
|
||||
CppUnit_addTest(pSuite, RedisTest, testIncr);
|
||||
CppUnit_addTest(pSuite, RedisTest, testIncrBy);
|
||||
|
||||
@@ -37,6 +37,7 @@ public:
|
||||
void testEcho();
|
||||
void testError();
|
||||
void testEval();
|
||||
void testHDel();
|
||||
void testHSet();
|
||||
void testIncr();
|
||||
void testIncrBy();
|
||||
|
||||
Reference in New Issue
Block a user