Add hvals

This commit is contained in:
fbraem 2015-11-19 18:29:06 +01:00
parent 2d10de0c30
commit 05703f2f9f
4 changed files with 54 additions and 1 deletions
Redis
include/Poco/Redis
src
testsuite/src

@ -109,7 +109,10 @@ public:
/// Returns an HSET or HSETNX (when create is false) command
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);
/// 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;
}
Command Command::hvals(const std::string& hash)
{
Command cmd("HVALS");
cmd << hash;
return cmd;
}
Command Command::incr(const std::string& key, Int64 by)
{
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()
{
if (!_connected)
@ -2853,6 +2892,7 @@ CppUnit::Test* RedisTest::suite()
CppUnit_addTest(pSuite, RedisTest, testHMSET);
CppUnit_addTest(pSuite, RedisTest, testHSET);
//CppUnit_addTest(pSuite, RedisTest, testHSTRLEN);
CppUnit_addTest(pSuite, RedisTest, testHVALS);
CppUnit_addTest(pSuite, RedisTest, testINCR);
CppUnit_addTest(pSuite, RedisTest, testINCRBY);
CppUnit_addTest(pSuite, RedisTest, testLINDEX);

@ -46,6 +46,7 @@ public:
void testHMSET();
void testHSET();
void testHSTRLEN();
void testHVALS();
void testINCR();
void testINCRBY();
void testLINDEX();