mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-27 19:10:20 +01:00
Add hvals
This commit is contained in:
@@ -109,7 +109,10 @@ public:
|
|||||||
/// Returns an HSET or HSETNX (when create is false) command
|
/// Returns an HSET or HSETNX (when create is false) command
|
||||||
|
|
||||||
static Command hstrlen(const std::string& hash, const std::string& field);
|
static Command hstrlen(const std::string& hash, const std::string& field);
|
||||||
/// Returns an HSTRLEN command
|
/// Returns an HSTRLEN command (Available for Redis 3.2)
|
||||||
|
|
||||||
|
static Command hvals(const std::string& hash);
|
||||||
|
/// Returns an HVALS command
|
||||||
|
|
||||||
static Command incr(const std::string& key, Int64 by = 0);
|
static Command incr(const std::string& key, Int64 by = 0);
|
||||||
/// Returns an INCR or INCRBY command. Calls INCR when by is omitted or zero.
|
/// Returns an INCR or INCRBY command. Calls INCR when by is omitted or zero.
|
||||||
|
|||||||
@@ -224,6 +224,15 @@ Command Command::hstrlen(const std::string& hash, const std::string& field)
|
|||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Command Command::hvals(const std::string& hash)
|
||||||
|
{
|
||||||
|
Command cmd("HVALS");
|
||||||
|
|
||||||
|
cmd << hash;
|
||||||
|
|
||||||
|
return cmd;
|
||||||
|
}
|
||||||
|
|
||||||
Command Command::incr(const std::string& key, Int64 by)
|
Command Command::incr(const std::string& key, Int64 by)
|
||||||
{
|
{
|
||||||
Command cmd(by == 0 ? "INCR" : "INCRBY");
|
Command cmd(by == 0 ? "INCR" : "INCRBY");
|
||||||
|
|||||||
@@ -812,6 +812,45 @@ void RedisTest::testHSTRLEN()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RedisTest::testHVALS()
|
||||||
|
{
|
||||||
|
if (!_connected)
|
||||||
|
{
|
||||||
|
std::cout << "Not connected, test skipped." << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
delKey("myhash");
|
||||||
|
|
||||||
|
std::map<std::string, std::string> fields;
|
||||||
|
fields.insert(std::make_pair<std::string, std::string>("field1", "Hello"));
|
||||||
|
fields.insert(std::make_pair<std::string, std::string>("field2", "World"));
|
||||||
|
|
||||||
|
Command hmset = Command::hmset("myhash", fields);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
std::string result = _redis.execute<std::string>(hmset);
|
||||||
|
assert(result.compare("OK") == 0);
|
||||||
|
}
|
||||||
|
catch(RedisException &e)
|
||||||
|
{
|
||||||
|
fail(e.message());
|
||||||
|
}
|
||||||
|
|
||||||
|
Command hvals = Command::hvals("myhash");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Array result = _redis.execute<Array>(hvals);
|
||||||
|
assert(result.size() == 2);
|
||||||
|
assert(result.get<BulkString>(0).value().compare("Hello") == 0);
|
||||||
|
assert(result.get<BulkString>(1).value().compare("World") == 0);
|
||||||
|
}
|
||||||
|
catch(RedisException &e)
|
||||||
|
{
|
||||||
|
fail(e.message());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void RedisTest::testINCR()
|
void RedisTest::testINCR()
|
||||||
{
|
{
|
||||||
if (!_connected)
|
if (!_connected)
|
||||||
@@ -2853,6 +2892,7 @@ CppUnit::Test* RedisTest::suite()
|
|||||||
CppUnit_addTest(pSuite, RedisTest, testHMSET);
|
CppUnit_addTest(pSuite, RedisTest, testHMSET);
|
||||||
CppUnit_addTest(pSuite, RedisTest, testHSET);
|
CppUnit_addTest(pSuite, RedisTest, testHSET);
|
||||||
//CppUnit_addTest(pSuite, RedisTest, testHSTRLEN);
|
//CppUnit_addTest(pSuite, RedisTest, testHSTRLEN);
|
||||||
|
CppUnit_addTest(pSuite, RedisTest, testHVALS);
|
||||||
CppUnit_addTest(pSuite, RedisTest, testINCR);
|
CppUnit_addTest(pSuite, RedisTest, testINCR);
|
||||||
CppUnit_addTest(pSuite, RedisTest, testINCRBY);
|
CppUnit_addTest(pSuite, RedisTest, testINCRBY);
|
||||||
CppUnit_addTest(pSuite, RedisTest, testLINDEX);
|
CppUnit_addTest(pSuite, RedisTest, testLINDEX);
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ public:
|
|||||||
void testHMSET();
|
void testHMSET();
|
||||||
void testHSET();
|
void testHSET();
|
||||||
void testHSTRLEN();
|
void testHSTRLEN();
|
||||||
|
void testHVALS();
|
||||||
void testINCR();
|
void testINCR();
|
||||||
void testINCRBY();
|
void testINCRBY();
|
||||||
void testLINDEX();
|
void testLINDEX();
|
||||||
|
|||||||
Reference in New Issue
Block a user