mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-02-17 11:45:50 +00:00
Implement hmget() method and use it.
This commit is contained in:
parent
64b87c52bb
commit
e02b0a16f5
3 changed files with 24 additions and 8 deletions
|
@ -18,7 +18,6 @@
|
||||||
#include "incredis.hpp"
|
#include "incredis.hpp"
|
||||||
#include "helpers/compatibility.h"
|
#include "helpers/compatibility.h"
|
||||||
#include "helpers/lexical_cast.hpp"
|
#include "helpers/lexical_cast.hpp"
|
||||||
#include <utility>
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <ciso646>
|
#include <ciso646>
|
||||||
|
|
||||||
|
@ -50,7 +49,8 @@ namespace redis {
|
||||||
return IncRedis::opt_string_list(std::move(retval));
|
return IncRedis::opt_string_list(std::move(retval));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} //unnamed namespace
|
||||||
|
|
||||||
IncRedis::IncRedis (std::string &&parAddress, uint16_t parPort) :
|
IncRedis::IncRedis (std::string &&parAddress, uint16_t parPort) :
|
||||||
m_command(std::move(parAddress), parPort)
|
m_command(std::move(parAddress), parPort)
|
||||||
{
|
{
|
||||||
|
@ -110,4 +110,8 @@ namespace redis {
|
||||||
auto IncRedis::srandmember (boost::string_ref parKey) -> opt_string {
|
auto IncRedis::srandmember (boost::string_ref parKey) -> opt_string {
|
||||||
return optional_string(m_command.run("SRANDMEMBER", parKey));
|
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
|
} //namespace redis
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <boost/range/iterator_range_core.hpp>
|
#include <boost/range/iterator_range_core.hpp>
|
||||||
#include <boost/range/empty.hpp>
|
#include <boost/range/empty.hpp>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
namespace redis {
|
namespace redis {
|
||||||
class IncRedis {
|
class IncRedis {
|
||||||
|
@ -63,6 +64,8 @@ namespace redis {
|
||||||
|
|
||||||
//Hash
|
//Hash
|
||||||
opt_string hget ( boost::string_ref parKey, boost::string_ref parField );
|
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 );
|
int hincrby ( boost::string_ref parKey, boost::string_ref parField, int parInc );
|
||||||
|
|
||||||
//Set
|
//Set
|
||||||
|
@ -70,8 +73,15 @@ namespace redis {
|
||||||
opt_string srandmember ( boost::string_ref parKey );
|
opt_string srandmember ( boost::string_ref parKey );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static opt_string_list reply_to_string_list ( const Reply& parReply );
|
||||||
|
|
||||||
Command m_command;
|
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
|
} //namespace redis
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -151,15 +151,17 @@ namespace dindb {
|
||||||
|
|
||||||
for (const auto& itm : parRedis.scan(PROGRAM_NAME ":file:*")) {
|
for (const auto& itm : parRedis.scan(PROGRAM_NAME ":file:*")) {
|
||||||
const auto& file_key = itm;
|
const auto& file_key = itm;
|
||||||
auto file_reply = parRedis.command().run("HMGET", file_key, "path", "tags", "group_id");
|
auto opt_file_replies = parRedis.hmget(file_key, "path", "tags", "group_id");
|
||||||
auto& file_replies = redis::get_array(file_reply);
|
assert(opt_file_replies and opt_file_replies->size() == 3);
|
||||||
assert(file_replies.size() == 3);
|
if (not opt_file_replies)
|
||||||
const auto group_id = lexical_cast<GroupIDType>(redis::get_string(file_replies[2]));
|
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)
|
if (parSet != InvalidGroupID and parSet != group_id)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const auto path = redis::get_string(file_replies[0]);
|
const auto& path = *file_replies[0];
|
||||||
const auto tags_str = (file_replies[1].which() == redis::RedisVariantType_Nil ? std::string() : redis::get_string(file_replies[1]));
|
const auto tags_str = (file_replies[1] ? std::string() : *file_replies[1]);
|
||||||
const auto tags = dincore::split_tags(tags_str);
|
const auto tags = dincore::split_tags(tags_str);
|
||||||
const auto file_id = id_from_redis_key<FileIDType>(file_key);
|
const auto file_id = id_from_redis_key<FileIDType>(file_key);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue