mirror of
https://github.com/pocoproject/poco.git
synced 2025-01-31 06:35:03 +01:00
Add hkeys / hlen
This commit is contained in:
parent
2f850b8a43
commit
8015d827f4
@ -87,6 +87,12 @@ public:
|
|||||||
static Command hincrby(const std::string& hash, const std::string& field, Int64 by = 1);
|
static Command hincrby(const std::string& hash, const std::string& field, Int64 by = 1);
|
||||||
/// Returns an HINCRBY command
|
/// Returns an HINCRBY command
|
||||||
|
|
||||||
|
static Command hkeys(const std::string& hash);
|
||||||
|
/// Returns an HKEYS command
|
||||||
|
|
||||||
|
static Command hlen(const std::string& hash);
|
||||||
|
/// Returns an HLEN command
|
||||||
|
|
||||||
static Command hset(const std::string& hash, const std::string& field, const std::string& value, bool create = true);
|
static Command hset(const std::string& hash, const std::string& field, const std::string& value, bool create = true);
|
||||||
/// Returns an HSET or HSETNX (when create is false) command
|
/// Returns an HSET or HSETNX (when create is false) command
|
||||||
|
|
||||||
|
@ -176,6 +176,24 @@ Command Command::hincrby(const std::string& hash, const std::string& field, Int6
|
|||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Command Command::hkeys(const std::string& hash)
|
||||||
|
{
|
||||||
|
Command cmd("HKEYS");
|
||||||
|
|
||||||
|
cmd << hash;
|
||||||
|
|
||||||
|
return cmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
Command Command::hlen(const std::string& hash)
|
||||||
|
{
|
||||||
|
Command cmd("HLEN");
|
||||||
|
|
||||||
|
cmd << hash;
|
||||||
|
|
||||||
|
return cmd;
|
||||||
|
}
|
||||||
|
|
||||||
Command Command::hset(const std::string& hash, const std::string& field, const std::string& value, bool create)
|
Command Command::hset(const std::string& hash, const std::string& field, const std::string& value, bool create)
|
||||||
{
|
{
|
||||||
Command cmd(create ? "HSET" : "HSETNX");
|
Command cmd(create ? "HSET" : "HSETNX");
|
||||||
|
@ -561,6 +561,63 @@ void RedisTest::testHINCRBY()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RedisTest::testHKEYS()
|
||||||
|
{
|
||||||
|
if (!_connected)
|
||||||
|
{
|
||||||
|
std::cout << "Not connected, test skipped." << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
delKey("myhash");
|
||||||
|
|
||||||
|
Command hset = Command::hset("myhash", "field1", "Hello");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Poco::Int64 value = _redis.execute<Poco::Int64>(hset);
|
||||||
|
assert(value == 1);
|
||||||
|
}
|
||||||
|
catch(RedisException &e)
|
||||||
|
{
|
||||||
|
fail(e.message());
|
||||||
|
}
|
||||||
|
|
||||||
|
hset = Command::hset("myhash", "field2", "World");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Poco::Int64 value = _redis.execute<Poco::Int64>(hset);
|
||||||
|
assert(value == 1);
|
||||||
|
}
|
||||||
|
catch(RedisException &e)
|
||||||
|
{
|
||||||
|
fail(e.message());
|
||||||
|
}
|
||||||
|
|
||||||
|
Command hlen = Command::hlen("myhash");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Poco::Int64 value = _redis.execute<Poco::Int64>(hlen);
|
||||||
|
assert(value == 2);
|
||||||
|
}
|
||||||
|
catch(RedisException &e)
|
||||||
|
{
|
||||||
|
fail(e.message());
|
||||||
|
}
|
||||||
|
|
||||||
|
Command hkeys = Command::hkeys("myhash");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Array result = _redis.execute<Array>(hkeys);
|
||||||
|
assert(result.size() == 2);
|
||||||
|
assert(result.get<BulkString>(0).value().compare("field1") == 0);
|
||||||
|
assert(result.get<BulkString>(1).value().compare("field2") == 0);
|
||||||
|
}
|
||||||
|
catch(RedisException &e)
|
||||||
|
{
|
||||||
|
fail(e.message());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void RedisTest::testHSET()
|
void RedisTest::testHSET()
|
||||||
{
|
{
|
||||||
if (!_connected)
|
if (!_connected)
|
||||||
@ -2629,6 +2686,7 @@ CppUnit::Test* RedisTest::suite()
|
|||||||
CppUnit_addTest(pSuite, RedisTest, testHEXISTS);
|
CppUnit_addTest(pSuite, RedisTest, testHEXISTS);
|
||||||
CppUnit_addTest(pSuite, RedisTest, testHGETALL);
|
CppUnit_addTest(pSuite, RedisTest, testHGETALL);
|
||||||
CppUnit_addTest(pSuite, RedisTest, testHINCRBY);
|
CppUnit_addTest(pSuite, RedisTest, testHINCRBY);
|
||||||
|
CppUnit_addTest(pSuite, RedisTest, testHKEYS);
|
||||||
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);
|
||||||
|
@ -41,6 +41,7 @@ public:
|
|||||||
void testHEXISTS();
|
void testHEXISTS();
|
||||||
void testHGETALL();
|
void testHGETALL();
|
||||||
void testHINCRBY();
|
void testHINCRBY();
|
||||||
|
void testHKEYS();
|
||||||
void testHSET();
|
void testHSET();
|
||||||
void testINCR();
|
void testINCR();
|
||||||
void testINCRBY();
|
void testINCRBY();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user