From d6682eb1309773d3ddf2e5cdca144707f9c39943 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Tue, 12 Jul 2016 12:30:53 +0100 Subject: [PATCH] Call wrapper methods instead of plain run(). --- src/backends/redis/backend_redis.cpp | 11 ++++------- src/backends/redis/delete.cpp | 20 ++++++++++---------- src/backends/redis/find.cpp | 6 +++--- src/backends/redis/tag.cpp | 4 ++-- 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/backends/redis/backend_redis.cpp b/src/backends/redis/backend_redis.cpp index 0d68294..e981772 100644 --- a/src/backends/redis/backend_redis.cpp +++ b/src/backends/redis/backend_redis.cpp @@ -169,10 +169,9 @@ namespace dindb { assert(file_id_int >= data_size); 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( - "HMSET", + batch.hmset( set_key, "name", parSetData.name, "disk_label", parSetData.disk_label, @@ -187,8 +186,7 @@ namespace dindb { const std::string file_key = PROGRAM_NAME ":file:" + lexical_cast(z); const auto& file_data = parData[z - base_file_id]; const std::string hash = tiger_to_string(file_data.hash); - batch.run( - "HMSET", + batch.hmset( file_key, "hash", hash, "path", file_data.path(), @@ -203,8 +201,7 @@ namespace dindb { "group_id", group_id ); - batch.run( - "SADD", + batch.sadd( PROGRAM_NAME ":hash:" + hash, lexical_cast(z) ); diff --git a/src/backends/redis/delete.cpp b/src/backends/redis/delete.cpp index 18a1c87..3e6945f 100644 --- a/src/backends/redis/delete.cpp +++ b/src/backends/redis/delete.cpp @@ -29,7 +29,7 @@ namespace dindb { namespace { - std::pair confirm_dele (redis::Batch& parBatch, const std::vector& parIDs, ConfirmDeleCallback parConf) { + std::pair confirm_dele (redis::IncRedisBatch& parBatch, const std::vector& parIDs, ConfirmDeleCallback parConf) { using dinhelp::lexical_cast; if (parIDs.empty()) @@ -37,7 +37,7 @@ namespace dindb { for (auto id : parIDs) { const auto set_key = PROGRAM_NAME ":set:" + lexical_cast(id); - parBatch.run("HMGET", set_key, "base_file_id", "file_count", "name"); + parBatch.hmget(set_key, "base_file_id", "file_count", "name"); } std::map set_dele_list; @@ -80,10 +80,10 @@ namespace dindb { using dinhelp::lexical_cast; using IDRange = std::tuple; - auto set_batch = parRedis.command().make_batch(); + auto set_batch = parRedis.make_batch(); 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) return; @@ -121,30 +121,30 @@ namespace dindb { 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) { const auto set_id = std::get<0>(dele_tuple); const auto file_base_index = std::get<1>(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) { const auto file_key = PROGRAM_NAME ":file:" + lexical_cast(i); - hash_query_batch.run("HGET", file_key, "hash"); + hash_query_batch.hget(file_key, "hash"); } hash_query_batch.throw_if_failed(); for (const auto& rep : hash_query_batch.replies()) { const auto hash_key = PROGRAM_NAME ":hash:" + redis::get_string(rep); parDeleHash.run( - dele_batch, + dele_batch.batch(), std::make_tuple(hash_key), std::make_tuple(lexical_cast(file_base_index), lexical_cast(file_count)) ); } - dele_batch.run("DEL", PROGRAM_NAME ":set:" + lexical_cast(set_id)); - chunked_run(dele_batch, +"DEL", file_base_index, file_count, [](FileIDType id){return PROGRAM_NAME ":file:" + lexical_cast(id);}); + dele_batch.del(PROGRAM_NAME ":set:" + lexical_cast(set_id)); + chunked_run(dele_batch.batch(), +"DEL", file_base_index, file_count, [](FileIDType id){return PROGRAM_NAME ":file:" + lexical_cast(id);}); } dele_batch.throw_if_failed(); diff --git a/src/backends/redis/find.cpp b/src/backends/redis/find.cpp index daa4155..6f750c6 100644 --- a/src/backends/redis/find.cpp +++ b/src/backends/redis/find.cpp @@ -42,7 +42,7 @@ namespace dindb { return true; } - void store_matching_paths (redis::Batch& parBatch, std::vector& parOut, std::vector& parIDs, const boost::regex& parSearch, const TagList& parTags) { + void store_matching_paths (redis::IncRedisBatch& parBatch, std::vector& parOut, std::vector& parIDs, const boost::regex& parSearch, const TagList& parTags) { using dinhelp::lexical_cast; assert(parIDs.size() == parBatch.replies().size()); @@ -87,10 +87,10 @@ namespace dindb { ids.reserve(prefetch_count); int curr_count = 0; - auto batch = parRedis.command().make_batch(); + auto batch = parRedis.make_batch(); for (const auto& itm : parRedis.scan(PROGRAM_NAME ":file:*")) { ++curr_count; - batch.run("HMGET", itm, "path", "group_id", "tags"); + batch.hmget(itm, "path", "group_id", "tags"); ids.push_back(lexical_cast(split_and_trim(itm, ':').back())); if (curr_count == prefetch_count) { diff --git a/src/backends/redis/tag.cpp b/src/backends/redis/tag.cpp index 36f5462..1c7cfc0 100644 --- a/src/backends/redis/tag.cpp +++ b/src/backends/redis/tag.cpp @@ -122,10 +122,10 @@ namespace dindb { } void delete_all_tags (redis::IncRedis& parRedis, redis::Script& parDeleIfInSet, const std::vector& parFiles, GroupIDType parSet) { - auto batch = parRedis.command().make_batch(); + auto batch = parRedis.make_batch(); for (const auto file_id : parFiles) { const auto file_key = make_file_key(file_id); - batch.run("HGET", file_key, "tags"); + batch.hget(file_key, "tags"); } batch.throw_if_failed();