diff --git a/src/backends/redis/backend_redis.cpp b/src/backends/redis/backend_redis.cpp index 555337e..720cce6 100644 --- a/src/backends/redis/backend_redis.cpp +++ b/src/backends/redis/backend_redis.cpp @@ -167,6 +167,7 @@ namespace dindb { const auto group_id = lexical_cast(group_id_int); const std::string set_key = PROGRAM_NAME ":set:" + group_id; + const std::string level_key = PROGRAM_NAME ":levels:" + group_id; assert(file_id_int >= data_size); const auto base_file_id = file_id_int - data_size + 1; @@ -215,6 +216,8 @@ namespace dindb { PROGRAM_NAME ":hash:" + hash, lexical_cast(z) ); + + batch.zadd(level_key, redis::IncRedisBatch::ZADD_None, false, static_cast(file_data.level), file_key); #if !defined(NDEBUG) ++inserted_count; #endif @@ -275,7 +278,7 @@ namespace dindb { } std::vector> BackendRedis::find_file_details (GroupIDType parSetID, uint16_t parLevel, boost::string_ref parDir) { - return std::vector>(); + return dindb::find_file_details(m_redis, parSetID, parLevel, parDir); } std::vector BackendRedis::find_paths_starting_by (GroupIDType parGroupID, uint16_t parLevel, boost::string_ref parPath) { diff --git a/src/backends/redis/delete.cpp b/src/backends/redis/delete.cpp index fb612e1..b7711d5 100644 --- a/src/backends/redis/delete.cpp +++ b/src/backends/redis/delete.cpp @@ -144,6 +144,7 @@ namespace dindb { } dele_batch.del(PROGRAM_NAME ":set:" + lexical_cast(set_id)); + dele_batch.del(PROGRAM_NAME ":levels:" + lexical_cast(set_id)); chunked_run(dele_batch.batch(), +"DEL", file_base_index, file_count, [](FileIDType id){return PROGRAM_NAME ":file:" + lexical_cast(id);}); } diff --git a/src/backends/redis/find.cpp b/src/backends/redis/find.cpp index 737988a..16f1405 100644 --- a/src/backends/redis/find.cpp +++ b/src/backends/redis/find.cpp @@ -31,6 +31,7 @@ #include #include #include +#include namespace dindb { namespace { @@ -261,7 +262,6 @@ namespace dindb { std::vector> find_set_details (redis::IncRedis& parRedis, const std::vector& parSets) { using dinhelp::lexical_cast; - using MArr = dinhelp::MaxSizedArray; auto batch = parRedis.make_batch(); for (auto set_id : parSets) { @@ -270,7 +270,7 @@ namespace dindb { } batch.throw_if_failed(); - std::vector retval; + std::vector> retval; auto curr_set = parSets.begin(); for (const auto& reply : batch.replies()) { const auto& reply_list = get_array(reply); @@ -288,4 +288,33 @@ namespace dindb { } return retval; }; + + std::vector> find_file_details (redis::IncRedis& parRedis, GroupIDType parSetID, uint16_t parLevel, boost::string_ref parDir) { + using dinhelp::lexical_cast; + using RetListType = std::vector>; + + const double level = static_cast(parLevel); + auto lst = parRedis.zrangebyscore(PROGRAM_NAME ":levels:" + lexical_cast(parSetID), level, true, level, true, false); + if (not lst) + return RetListType(); + + auto batch = parRedis.make_batch(); + for (const auto& itm : *lst) { + if (itm) + batch.hget(*itm, "path"); + } + batch.throw_if_failed(); + + std::vector> retval; + for (auto& reply : batch.replies()) { + if (redis::RedisVariantType_Nil != reply.which()) { + auto curr_path = get_string(reply); + if (boost::starts_with(curr_path, parDir)) { + retval.resize(retval.size() + 1); + retval.back().push_back(std::move(curr_path)); + } + } + } + return retval; + }; } //namespace dindb diff --git a/src/backends/redis/find.hpp b/src/backends/redis/find.hpp index b31b64d..d06395d 100644 --- a/src/backends/redis/find.hpp +++ b/src/backends/redis/find.hpp @@ -33,6 +33,7 @@ namespace dindb { std::vector locate_sets_in_db ( redis::IncRedis& parRedis, const std::string& parSubstr, bool parCaseInsensitive ); std::vector locate_sets_in_db ( redis::IncRedis& parRedis, const std::string& parSubstr, const std::vector& parSets, bool parCaseInsensitive ); std::vector> find_set_details ( redis::IncRedis& parRedis, const std::vector& parSets ); + std::vector> find_file_details ( redis::IncRedis& parRedis, GroupIDType parSetID, uint16_t parLevel, boost::string_ref parDir ); } //namespace dindb #endif