1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2025-02-20 12:14:55 +00:00

Call wrapper methods instead of plain run().

This commit is contained in:
King_DuckZ 2016-07-12 12:30:53 +01:00
parent f4c495c5ea
commit d6682eb130
4 changed files with 19 additions and 22 deletions

View file

@ -169,10 +169,9 @@ namespace dindb {
assert(file_id_int >= data_size); assert(file_id_int >= data_size);
const auto base_file_id = file_id_int - data_size + 1; const auto base_file_id = file_id_int - data_size + 1;
auto batch = m_redis.command().make_batch(); auto batch = m_redis.make_batch();
batch.run( batch.hmset(
"HMSET",
set_key, set_key,
"name", parSetData.name, "name", parSetData.name,
"disk_label", parSetData.disk_label, "disk_label", parSetData.disk_label,
@ -187,8 +186,7 @@ namespace dindb {
const std::string file_key = PROGRAM_NAME ":file:" + lexical_cast<std::string>(z); const std::string file_key = PROGRAM_NAME ":file:" + lexical_cast<std::string>(z);
const auto& file_data = parData[z - base_file_id]; const auto& file_data = parData[z - base_file_id];
const std::string hash = tiger_to_string(file_data.hash); const std::string hash = tiger_to_string(file_data.hash);
batch.run( batch.hmset(
"HMSET",
file_key, file_key,
"hash", hash, "hash", hash,
"path", file_data.path(), "path", file_data.path(),
@ -203,8 +201,7 @@ namespace dindb {
"group_id", group_id "group_id", group_id
); );
batch.run( batch.sadd(
"SADD",
PROGRAM_NAME ":hash:" + hash, PROGRAM_NAME ":hash:" + hash,
lexical_cast<std::string>(z) lexical_cast<std::string>(z)
); );

View file

@ -29,7 +29,7 @@
namespace dindb { namespace dindb {
namespace { namespace {
std::pair<bool, std::size_t> confirm_dele (redis::Batch& parBatch, const std::vector<GroupIDType>& parIDs, ConfirmDeleCallback parConf) { std::pair<bool, std::size_t> confirm_dele (redis::IncRedisBatch& parBatch, const std::vector<GroupIDType>& parIDs, ConfirmDeleCallback parConf) {
using dinhelp::lexical_cast; using dinhelp::lexical_cast;
if (parIDs.empty()) if (parIDs.empty())
@ -37,7 +37,7 @@ namespace dindb {
for (auto id : parIDs) { for (auto id : parIDs) {
const auto set_key = PROGRAM_NAME ":set:" + lexical_cast<std::string>(id); const auto set_key = PROGRAM_NAME ":set:" + lexical_cast<std::string>(id);
parBatch.run("HMGET", set_key, "base_file_id", "file_count", "name"); parBatch.hmget(set_key, "base_file_id", "file_count", "name");
} }
std::map<GroupIDType, std::string> set_dele_list; std::map<GroupIDType, std::string> set_dele_list;
@ -80,10 +80,10 @@ namespace dindb {
using dinhelp::lexical_cast; using dinhelp::lexical_cast;
using IDRange = std::tuple<GroupIDType, FileIDType, FileIDType>; using IDRange = std::tuple<GroupIDType, FileIDType, FileIDType>;
auto set_batch = parRedis.command().make_batch(); auto set_batch = parRedis.make_batch();
auto dele_pair = confirm_dele(set_batch, parIDs, parConf); auto dele_pair = confirm_dele(set_batch, parIDs, parConf);
assert(set_batch.replies_requested()); assert(set_batch.batch().replies_requested());
if (not dele_pair.first) if (not dele_pair.first)
return; return;
@ -121,30 +121,30 @@ namespace dindb {
delete_all_tags(parRedis, parDeleTagIfInSet, ids, set_id); delete_all_tags(parRedis, parDeleTagIfInSet, ids, set_id);
} }
auto dele_batch = parRedis.command().make_batch(); auto dele_batch = parRedis.make_batch();
for (const auto& dele_tuple : ranges) { for (const auto& dele_tuple : ranges) {
const auto set_id = std::get<0>(dele_tuple); const auto set_id = std::get<0>(dele_tuple);
const auto file_base_index = std::get<1>(dele_tuple); const auto file_base_index = std::get<1>(dele_tuple);
const auto file_count = std::get<2>(dele_tuple); const auto file_count = std::get<2>(dele_tuple);
auto hash_query_batch = parRedis.command().make_batch(); auto hash_query_batch = parRedis.make_batch();
for (FileIDType i = file_base_index; i < file_base_index + file_count; ++i) { for (FileIDType i = file_base_index; i < file_base_index + file_count; ++i) {
const auto file_key = PROGRAM_NAME ":file:" + lexical_cast<std::string>(i); const auto file_key = PROGRAM_NAME ":file:" + lexical_cast<std::string>(i);
hash_query_batch.run("HGET", file_key, "hash"); hash_query_batch.hget(file_key, "hash");
} }
hash_query_batch.throw_if_failed(); hash_query_batch.throw_if_failed();
for (const auto& rep : hash_query_batch.replies()) { for (const auto& rep : hash_query_batch.replies()) {
const auto hash_key = PROGRAM_NAME ":hash:" + redis::get_string(rep); const auto hash_key = PROGRAM_NAME ":hash:" + redis::get_string(rep);
parDeleHash.run( parDeleHash.run(
dele_batch, dele_batch.batch(),
std::make_tuple(hash_key), std::make_tuple(hash_key),
std::make_tuple(lexical_cast<std::string>(file_base_index), lexical_cast<std::string>(file_count)) std::make_tuple(lexical_cast<std::string>(file_base_index), lexical_cast<std::string>(file_count))
); );
} }
dele_batch.run("DEL", PROGRAM_NAME ":set:" + lexical_cast<std::string>(set_id)); dele_batch.del(PROGRAM_NAME ":set:" + lexical_cast<std::string>(set_id));
chunked_run<FileIDType, 8>(dele_batch, +"DEL", file_base_index, file_count, [](FileIDType id){return PROGRAM_NAME ":file:" + lexical_cast<std::string>(id);}); chunked_run<FileIDType, 8>(dele_batch.batch(), +"DEL", file_base_index, file_count, [](FileIDType id){return PROGRAM_NAME ":file:" + lexical_cast<std::string>(id);});
} }
dele_batch.throw_if_failed(); dele_batch.throw_if_failed();

View file

@ -42,7 +42,7 @@ namespace dindb {
return true; return true;
} }
void store_matching_paths (redis::Batch& parBatch, std::vector<LocatedItem>& parOut, std::vector<FileIDType>& parIDs, const boost::regex& parSearch, const TagList& parTags) { void store_matching_paths (redis::IncRedisBatch& parBatch, std::vector<LocatedItem>& parOut, std::vector<FileIDType>& parIDs, const boost::regex& parSearch, const TagList& parTags) {
using dinhelp::lexical_cast; using dinhelp::lexical_cast;
assert(parIDs.size() == parBatch.replies().size()); assert(parIDs.size() == parBatch.replies().size());
@ -87,10 +87,10 @@ namespace dindb {
ids.reserve(prefetch_count); ids.reserve(prefetch_count);
int curr_count = 0; int curr_count = 0;
auto batch = parRedis.command().make_batch(); auto batch = parRedis.make_batch();
for (const auto& itm : parRedis.scan(PROGRAM_NAME ":file:*")) { for (const auto& itm : parRedis.scan(PROGRAM_NAME ":file:*")) {
++curr_count; ++curr_count;
batch.run("HMGET", itm, "path", "group_id", "tags"); batch.hmget(itm, "path", "group_id", "tags");
ids.push_back(lexical_cast<FileIDType>(split_and_trim(itm, ':').back())); ids.push_back(lexical_cast<FileIDType>(split_and_trim(itm, ':').back()));
if (curr_count == prefetch_count) { if (curr_count == prefetch_count) {

View file

@ -122,10 +122,10 @@ namespace dindb {
} }
void delete_all_tags (redis::IncRedis& parRedis, redis::Script& parDeleIfInSet, const std::vector<FileIDType>& parFiles, GroupIDType parSet) { void delete_all_tags (redis::IncRedis& parRedis, redis::Script& parDeleIfInSet, const std::vector<FileIDType>& parFiles, GroupIDType parSet) {
auto batch = parRedis.command().make_batch(); auto batch = parRedis.make_batch();
for (const auto file_id : parFiles) { for (const auto file_id : parFiles) {
const auto file_key = make_file_key(file_id); const auto file_key = make_file_key(file_id);
batch.run("HGET", file_key, "tags"); batch.hget(file_key, "tags");
} }
batch.throw_if_failed(); batch.throw_if_failed();