mirror of
https://github.com/pocoproject/poco.git
synced 2025-07-04 09:37:11 +02:00
Add hstrlen (note: only available in Redis 3.2)
This commit is contained in:
parent
fd5579cb8c
commit
2d10de0c30
@ -108,6 +108,9 @@ public:
|
|||||||
static Command hset(const std::string& hash, const std::string& field, Int64 value, bool create = true);
|
static Command hset(const std::string& hash, const std::string& field, Int64 value, bool create = true);
|
||||||
/// 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);
|
||||||
|
/// Returns an HSTRLEN 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.
|
||||||
|
|
||||||
|
@ -215,6 +215,15 @@ Command Command::hset(const std::string& hash, const std::string& field, Int64 v
|
|||||||
return hset(hash, field, NumberFormatter::format(value), create);
|
return hset(hash, field, NumberFormatter::format(value), create);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Command Command::hstrlen(const std::string& hash, const std::string& field)
|
||||||
|
{
|
||||||
|
Command cmd("HSTRLEN");
|
||||||
|
|
||||||
|
cmd << hash << field;
|
||||||
|
|
||||||
|
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");
|
||||||
|
@ -752,6 +752,66 @@ void RedisTest::testHMSET()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RedisTest::testHSTRLEN()
|
||||||
|
{
|
||||||
|
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>("f1", "HelloWorld"));
|
||||||
|
fields.insert(std::make_pair<std::string, std::string>("f2", "99"));
|
||||||
|
fields.insert(std::make_pair<std::string, std::string>("f3", "-256"));
|
||||||
|
|
||||||
|
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 hstrlen = Command::hstrlen("myhash", "f1");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Poco::Int64 len = _redis.execute<Poco::Int64>(hstrlen);
|
||||||
|
assert(len == 10);
|
||||||
|
}
|
||||||
|
catch(RedisException &e)
|
||||||
|
{
|
||||||
|
fail(e.message());
|
||||||
|
}
|
||||||
|
|
||||||
|
hstrlen = Command::hstrlen("myhash", "f2");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Poco::Int64 len = _redis.execute<Poco::Int64>(hstrlen);
|
||||||
|
assert(len == 2);
|
||||||
|
}
|
||||||
|
catch(RedisException &e)
|
||||||
|
{
|
||||||
|
fail(e.message());
|
||||||
|
}
|
||||||
|
|
||||||
|
hstrlen = Command::hstrlen("myhash", "f3");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Poco::Int64 len = _redis.execute<Poco::Int64>(hstrlen);
|
||||||
|
assert(len == 4);
|
||||||
|
}
|
||||||
|
catch(RedisException &e)
|
||||||
|
{
|
||||||
|
fail(e.message());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void RedisTest::testINCR()
|
void RedisTest::testINCR()
|
||||||
{
|
{
|
||||||
if (!_connected)
|
if (!_connected)
|
||||||
@ -2792,6 +2852,7 @@ CppUnit::Test* RedisTest::suite()
|
|||||||
CppUnit_addTest(pSuite, RedisTest, testHMGET);
|
CppUnit_addTest(pSuite, RedisTest, testHMGET);
|
||||||
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, 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);
|
||||||
|
@ -45,6 +45,7 @@ public:
|
|||||||
void testHMGET();
|
void testHMGET();
|
||||||
void testHMSET();
|
void testHMSET();
|
||||||
void testHSET();
|
void testHSET();
|
||||||
|
void testHSTRLEN();
|
||||||
void testINCR();
|
void testINCR();
|
||||||
void testINCRBY();
|
void testINCRBY();
|
||||||
void testLINDEX();
|
void testLINDEX();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user