1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2024-11-25 00:53:43 +00:00

Implement hmget() method and use it.

This commit is contained in:
King_DuckZ 2016-07-12 11:40:44 +01:00
parent 64b87c52bb
commit e02b0a16f5
3 changed files with 24 additions and 8 deletions

View file

@ -18,7 +18,6 @@
#include "incredis.hpp"
#include "helpers/compatibility.h"
#include "helpers/lexical_cast.hpp"
#include <utility>
#include <cassert>
#include <ciso646>
@ -50,7 +49,8 @@ namespace redis {
return IncRedis::opt_string_list(std::move(retval));
}
}
}
} //unnamed namespace
IncRedis::IncRedis (std::string &&parAddress, uint16_t parPort) :
m_command(std::move(parAddress), parPort)
{
@ -110,4 +110,8 @@ namespace redis {
auto IncRedis::srandmember (boost::string_ref parKey) -> opt_string {
return optional_string(m_command.run("SRANDMEMBER", parKey));
}
auto IncRedis::reply_to_string_list (const Reply& parReply) -> opt_string_list {
return optional_string_list(parReply);
}
} //namespace redis

View file

@ -26,6 +26,7 @@
#include <vector>
#include <boost/range/iterator_range_core.hpp>
#include <boost/range/empty.hpp>
#include <utility>
namespace redis {
class IncRedis {
@ -63,6 +64,8 @@ namespace redis {
//Hash
opt_string hget ( boost::string_ref parKey, boost::string_ref parField );
template <typename... Args>
opt_string_list hmget ( boost::string_ref parKey, Args&&... parArgs );
int hincrby ( boost::string_ref parKey, boost::string_ref parField, int parInc );
//Set
@ -70,8 +73,15 @@ namespace redis {
opt_string srandmember ( boost::string_ref parKey );
private:
static opt_string_list reply_to_string_list ( const Reply& parReply );
Command m_command;
};
template <typename... Args>
auto IncRedis::hmget (boost::string_ref parKey, Args&&... parArgs) -> opt_string_list {
return reply_to_string_list(m_command.run("HMGET", parKey, std::forward<Args>(parArgs)...));
}
} //namespace redis
#endif

View file

@ -151,15 +151,17 @@ namespace dindb {
for (const auto& itm : parRedis.scan(PROGRAM_NAME ":file:*")) {
const auto& file_key = itm;
auto file_reply = parRedis.command().run("HMGET", file_key, "path", "tags", "group_id");
auto& file_replies = redis::get_array(file_reply);
assert(file_replies.size() == 3);
const auto group_id = lexical_cast<GroupIDType>(redis::get_string(file_replies[2]));
auto opt_file_replies = parRedis.hmget(file_key, "path", "tags", "group_id");
assert(opt_file_replies and opt_file_replies->size() == 3);
if (not opt_file_replies)
continue;
const auto& file_replies = *opt_file_replies;
const auto group_id = lexical_cast<GroupIDType>(*file_replies[2]);
if (parSet != InvalidGroupID and parSet != group_id)
continue;
const auto path = redis::get_string(file_replies[0]);
const auto tags_str = (file_replies[1].which() == redis::RedisVariantType_Nil ? std::string() : redis::get_string(file_replies[1]));
const auto& path = *file_replies[0];
const auto tags_str = (file_replies[1] ? std::string() : *file_replies[1]);
const auto tags = dincore::split_tags(tags_str);
const auto file_id = id_from_redis_key<FileIDType>(file_key);