diff --git a/src/backends/redis/CMakeLists.txt b/src/backends/redis/CMakeLists.txt index 19f7f05..121572a 100644 --- a/src/backends/redis/CMakeLists.txt +++ b/src/backends/redis/CMakeLists.txt @@ -15,6 +15,7 @@ add_library(${PROJECT_NAME} SHARED script.cpp script_manager.cpp async_connection.cpp + tag.cpp ) target_include_directories(${PROJECT_NAME} SYSTEM diff --git a/src/backends/redis/backend_redis.cpp b/src/backends/redis/backend_redis.cpp index 63c6eab..822b4e0 100644 --- a/src/backends/redis/backend_redis.cpp +++ b/src/backends/redis/backend_redis.cpp @@ -22,6 +22,7 @@ #include "helpers/lexical_cast.hpp" #include "dindexerConfig.h" #include "helpers/stringize.h" +#include "tag.hpp" #include "record_data_adapt.hpp" #include #include @@ -29,7 +30,6 @@ #include #include #include -#include namespace dindb { namespace { @@ -124,21 +124,7 @@ namespace dindb { } void BackendRedis::tag_files (const std::vector& parFiles, const std::vector& parTags, GroupIDType parSet) { - using dinhelp::lexical_cast; - - auto batch = m_redis.make_batch(); - const std::string set_key = (parSet != InvalidGroupID ? PROGRAM_NAME ":set:" + 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 = PROGRAM_NAME ":file:" + lexical_cast(file_id); - m_tag_if_in_set.run(batch, std::make_tuple(tag_key, file_key), std::make_tuple(set_key)); - } - } - - batch.throw_if_failed(); + dindb::tag_files(m_redis, m_tag_if_in_set, parFiles, parTags, parSet); } void BackendRedis::tag_files (const std::vector& parRegexes, const std::vector& parTags, GroupIDType parSet) { diff --git a/src/backends/redis/tag.cpp b/src/backends/redis/tag.cpp new file mode 100644 index 0000000..99fbba1 --- /dev/null +++ b/src/backends/redis/tag.cpp @@ -0,0 +1,63 @@ +/* Copyright 2015, 2016, Michele Santullo + * This file is part of "dindexer". + * + * "dindexer" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * "dindexer" is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with "dindexer". If not, see . + */ + +#include "tag.hpp" +#include "command.hpp" +#include "dindexerConfig.h" +#include "helpers/lexical_cast.hpp" +#include +#include +#include + +namespace dindb { + namespace { + } //unnamed namespace + + void tag_files (redis::Command& parRedis, redis::Script& parTagIfInSet, const std::vector& parFiles, const std::vector& parTags, GroupIDType parSet) { + using dinhelp::lexical_cast; + + auto batch = parRedis.make_batch(); + const std::string set_key = (parSet != InvalidGroupID ? PROGRAM_NAME ":set:" + 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 = PROGRAM_NAME ":file:" + lexical_cast(file_id); + parTagIfInSet.run(batch, std::make_tuple(tag_key, file_key), std::make_tuple(set_key)); + } + } + + batch.throw_if_failed(); + } + + void tag_files (redis::Command& parRedis, redis::Script& parTagIfInSet, const std::vector& parRegexes, const std::vector& parTags, GroupIDType parSet) { + } + + void delete_tags (redis::Command& parRedis, redis::Script& parDeleIfInSet, const std::vector& parFiles, const std::vector& parTags, GroupIDType parSet) { + } + + void delete_tags (redis::Command& parRedis, redis::Script& parDeleIfInSet, const std::vector& parRegexes, const std::vector& parTags, GroupIDType parSet) { + } + + void delete_all_tags (redis::Command& parRedis, redis::Script& parDeleIfInSet, const std::vector& parFiles, GroupIDType parSet) { + } + + void delete_all_tags (redis::Command& parRedis, redis::Script& parDeleIfInSet, const std::vector& parRegexes, GroupIDType parSet) { + } +} //namespace dindb + diff --git a/src/backends/redis/tag.hpp b/src/backends/redis/tag.hpp new file mode 100644 index 0000000..1b4b55b --- /dev/null +++ b/src/backends/redis/tag.hpp @@ -0,0 +1,75 @@ +/* Copyright 2015, 2016, Michele Santullo + * This file is part of "dindexer". + * + * "dindexer" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * "dindexer" is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with "dindexer". If not, see . + */ + +#ifndef id2874EA620CF0415CAF5B005E227BC44B +#define id2874EA620CF0415CAF5B005E227BC44B + +#include "backends/db_backend.hpp" +#include +#include +#include + +namespace redis { + class Command; + class Script; +} //namespace redis + +namespace dindb { + void tag_files ( + redis::Command& parRedis, + redis::Script& parTagIfInSet, + const std::vector& parFiles, + const std::vector& parTags, + GroupIDType parSet + ); + void tag_files ( + redis::Command& parRedis, + redis::Script& parTagIfInSet, + const std::vector& parRegexes, + const std::vector& parTags, + GroupIDType parSet + ); + + void delete_tags ( + redis::Command& parRedis, + redis::Script& parDeleIfInSet, + const std::vector& parFiles, + const std::vector& parTags, + GroupIDType parSet + ); + void delete_tags ( + redis::Command& parRedis, + redis::Script& parDeleIfInSet, + const std::vector& parRegexes, + const std::vector& parTags, + GroupIDType parSet + ); + void delete_all_tags ( + redis::Command& parRedis, + redis::Script& parDeleIfInSet, + const std::vector& parFiles, + GroupIDType parSet + ); + void delete_all_tags ( + redis::Command& parRedis, + redis::Script& parDeleIfInSet, + const std::vector& parRegexes, + GroupIDType parSet + ); +} //namespace dindb + +#endif