From bd06158d4c1e0fab65647342bbc05e6868ea3083 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Mon, 11 Jul 2016 17:44:54 +0100 Subject: [PATCH] Store group id and file id instead of full keys. --- src/backends/redis/backend_redis.cpp | 7 ++++--- src/backends/redis/dele_tag_if_in_set.lua | 8 ++++---- src/backends/redis/tag.cpp | 11 +++++------ src/backends/redis/tag_if_in_set.lua | 8 ++++---- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/backends/redis/backend_redis.cpp b/src/backends/redis/backend_redis.cpp index 35b235d..711d1b9 100644 --- a/src/backends/redis/backend_redis.cpp +++ b/src/backends/redis/backend_redis.cpp @@ -158,7 +158,8 @@ namespace dindb { redis::Reply set_id_reply = m_redis.run("HINCRBY", PROGRAM_NAME ":indices", "set", "1"); redis::Reply file_id_reply = m_redis.run("HINCRBY", PROGRAM_NAME ":indices", "files", lexical_cast(parData.size())); - const std::string set_key = PROGRAM_NAME ":set:" + lexical_cast(redis::get_integer(set_id_reply)); + const auto group_id = lexical_cast(redis::get_integer(set_id_reply)); + const std::string set_key = PROGRAM_NAME ":set:" + group_id; const auto casted_data_size = static_cast(parData.size()); assert(redis::get_integer(file_id_reply) >= casted_data_size); const auto base_file_id = redis::get_integer(file_id_reply) - casted_data_size + 1; @@ -192,13 +193,13 @@ namespace dindb { "is_symlink", (file_data.is_symlink ? '1' : '0'), "unreadable", (file_data.unreadable ? '1' : '0'), "hash_valid", (file_data.hash_valid ? '1' : '0'), - "group_id", set_key + "group_id", group_id ); batch.run( "SADD", PROGRAM_NAME ":hash:" + hash, - file_key + lexical_cast(z) ); } diff --git a/src/backends/redis/dele_tag_if_in_set.lua b/src/backends/redis/dele_tag_if_in_set.lua index 23ca35d..eb5ada7 100644 --- a/src/backends/redis/dele_tag_if_in_set.lua +++ b/src/backends/redis/dele_tag_if_in_set.lua @@ -16,7 +16,7 @@ local tag_key = KEYS[1] local file_key = KEYS[2] -local group_key = ARGV[1] +local group_id = ARGV[1] local function split_string(inputstr, sep) if sep == nil then @@ -45,9 +45,9 @@ local function dele_tag_from_list(tag_list, dele_tag) return table.concat(tag_list, ",") end -if group_key ~= "" then - local found_group_key = redis.call("HGET", file_key, "group_id") - if found_group_key ~= group_key then +if group_id ~= 0 then + local found_group_id = redis.call("HGET", file_key, "group_id") + if found_group_id ~= group_id then return nil end end diff --git a/src/backends/redis/tag.cpp b/src/backends/redis/tag.cpp index 6562b37..e979c64 100644 --- a/src/backends/redis/tag.cpp +++ b/src/backends/redis/tag.cpp @@ -58,14 +58,14 @@ namespace dindb { using dinhelp::lexical_cast; auto batch = parRedis.make_batch(); - const std::string set_key = (parSet != InvalidGroupID ? PROGRAM_NAME ":set:" + lexical_cast(parSet) : ""); + const std::string set_id = lexical_cast(parSet); for (const auto file_id : parFiles) { for (const auto &tag : parTags) { std::ostringstream oss; oss << PROGRAM_NAME ":tag:" << tag; const std::string tag_key = oss.str(); const std::string file_key = make_file_key(file_id); - parScript.run(batch, std::make_tuple(tag_key, file_key), std::make_tuple(set_key)); + parScript.run(batch, std::make_tuple(tag_key, file_key), std::make_tuple(set_id)); } } @@ -75,7 +75,7 @@ namespace dindb { void run_regex_based_script(redis::Command& parRedis, redis::Script& parTagIfInSet, const std::vector& parRegexes, const std::vector& parTags, GroupIDType parSet) { using dinhelp::lexical_cast; - const std::string set_key = (parSet != InvalidGroupID ? PROGRAM_NAME ":set:" + lexical_cast(parSet) : ""); + const std::string set_id = lexical_cast(parSet); const auto regexes = compile_regexes(parRegexes); for (const auto &itm : parRedis.scan(PROGRAM_NAME ":file:*")) { const auto &file_key = itm; @@ -90,7 +90,7 @@ namespace dindb { std::ostringstream oss; oss << PROGRAM_NAME ":tag:" << tag; const std::string tag_key = oss.str(); - parTagIfInSet.run(batch, std::make_tuple(tag_key, file_key), std::make_tuple(set_key)); + parTagIfInSet.run(batch, std::make_tuple(tag_key, file_key), std::make_tuple(set_id)); } break; } @@ -144,7 +144,6 @@ namespace dindb { void delete_all_tags (redis::Command& parRedis, redis::Script& parDeleIfInSet, const std::vector& parRegexes, GroupIDType parSet) { using dinhelp::lexical_cast; - const std::string set_key = (parSet != InvalidGroupID ? PROGRAM_NAME ":set:" + lexical_cast(parSet) : ""); const auto regexes = compile_regexes(parRegexes); std::set dele_tags; @@ -155,7 +154,7 @@ namespace dindb { auto file_reply = parRedis.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 = id_from_redis_key(redis::get_string(file_replies[2])); + const auto group_id = lexical_cast(redis::get_string(file_replies[2])); if (parSet != InvalidGroupID and parSet != group_id) continue; diff --git a/src/backends/redis/tag_if_in_set.lua b/src/backends/redis/tag_if_in_set.lua index 70c3419..2fc166f 100644 --- a/src/backends/redis/tag_if_in_set.lua +++ b/src/backends/redis/tag_if_in_set.lua @@ -16,7 +16,7 @@ local tag_key = KEYS[1] local file_key = KEYS[2] -local group_key = ARGV[1] +local group_id = ARGV[1] local function split_string(inputstr, sep) if sep == nil then @@ -51,9 +51,9 @@ local function add_tag_to_list(tag_list, new_tag) return table.concat(tag_list, ",") end -if group_key ~= "" then - local found_group_key = redis.call("HGET", file_key, "group_id") - if found_group_key ~= group_key then +if group_id ~= 0 then + local found_group_id = redis.call("HGET", file_key, "group_id") + if found_group_id ~= group_id then return nil end end