diff --git a/src/backends/redis/backend_redis.cpp b/src/backends/redis/backend_redis.cpp index 00adefe..ffdd57c 100644 --- a/src/backends/redis/backend_redis.cpp +++ b/src/backends/redis/backend_redis.cpp @@ -54,6 +54,8 @@ namespace YAML { parSettings.port = parNode["port"].as(); if (parNode["database"]) parSettings.database = parNode["database"].as(); + else + parSettings.database = 0; return true; } }; @@ -90,7 +92,7 @@ namespace dindb { void BackendRedis::tag_files (const std::vector& parRegexes, const std::vector& parTags, GroupIDType parSet) { for (const auto& file_path : m_redis.scan()) { - std::cout << file_path << '\n'; + //std::cout << file_path << '\n'; } } diff --git a/src/backends/redis/command.cpp b/src/backends/redis/command.cpp index f2de461..d4a58d0 100644 --- a/src/backends/redis/command.cpp +++ b/src/backends/redis/command.cpp @@ -84,8 +84,8 @@ namespace redis { m_conn.reset(); } - RedisReplyType Command::run_pvt (const char* parCommand, int parArgc, const char** parArgv, std::size_t* parLengths) { - assert(parCommand); + RedisReplyType Command::run_pvt (int parArgc, const char** parArgv, std::size_t* parLengths) { + assert(parArgc >= 1); assert(parArgv); assert(parLengths); //This /could/ be null, but I don't see why it should assert(is_connected()); diff --git a/src/backends/redis/command.hpp b/src/backends/redis/command.hpp index 0dbb3aa..9b6e3e4 100644 --- a/src/backends/redis/command.hpp +++ b/src/backends/redis/command.hpp @@ -56,7 +56,7 @@ namespace redis { private: using RedisConnection = std::unique_ptr; - RedisReplyType run_pvt ( const char* parCommand, int parArgc, const char** parArgv, std::size_t* parLengths ); + RedisReplyType run_pvt ( int parArgc, const char** parArgv, std::size_t* parLengths ); RedisConnection m_conn; std::string m_address; @@ -65,15 +65,17 @@ namespace redis { template RedisReplyType Command::run (const char* parCommand, Args&&... parArgs) { - constexpr const std::size_t arg_count = sizeof...(Args); + constexpr const std::size_t arg_count = sizeof...(Args) + 1; using CharPointerArray = std::array; using LengthArray = std::array; + using implem::arg_to_bin_safe_char; + using implem::arg_to_bin_safe_length; + using boost::string_ref; return this->run_pvt( - parCommand, static_cast(arg_count), - CharPointerArray{ implem::arg_to_bin_safe_char(std::forward(parArgs))... }.data(), - LengthArray{ implem::arg_to_bin_safe_length(std::forward(parArgs))... }.data() + CharPointerArray{ arg_to_bin_safe_char(string_ref(parCommand)), arg_to_bin_safe_char(std::forward(parArgs))... }.data(), + LengthArray{ arg_to_bin_safe_length(string_ref(parCommand)), arg_to_bin_safe_length(std::forward(parArgs))... }.data() ); } } //namespace redis diff --git a/src/backends/redis/reply.cpp b/src/backends/redis/reply.cpp index 6020d71..34789ef 100644 --- a/src/backends/redis/reply.cpp +++ b/src/backends/redis/reply.cpp @@ -17,6 +17,7 @@ #include "reply.hpp" #include +#include namespace redis { const long long& get_integer (const RedisReplyType& parReply) { @@ -27,6 +28,21 @@ namespace redis { return boost::get(parReply); } + long long get_integer_autoconv_if_str (const RedisReplyType &parReply) { + using boost::lexical_cast; + + const auto type = parReply.which(); + switch (type) { + case implem::RedisVariantType_Integer: + return get_integer(parReply); + case implem::RedisVariantType_String: + return lexical_cast(get_string(parReply)); + default: + assert(false); + return 0; + } + } + const std::vector& get_array (const RedisReplyType& parReply) { return boost::get>(parReply); } diff --git a/src/backends/redis/reply.hpp b/src/backends/redis/reply.hpp index eb9469f..db2ccf8 100644 --- a/src/backends/redis/reply.hpp +++ b/src/backends/redis/reply.hpp @@ -50,6 +50,7 @@ namespace redis { }; const long long& get_integer ( const RedisReplyType& parReply ); + long long get_integer_autoconv_if_str ( const RedisReplyType& parReply ); const std::string& get_string ( const RedisReplyType& parReply ); const std::vector& get_array ( const RedisReplyType& parReply ); diff --git a/src/backends/redis/scan_iterator.hpp b/src/backends/redis/scan_iterator.hpp index 98bcb52..ee0946a 100644 --- a/src/backends/redis/scan_iterator.hpp +++ b/src/backends/redis/scan_iterator.hpp @@ -71,6 +71,7 @@ namespace redis { RedisReplyType forward_scan_command ( typename std::enable_if::value, int>::type parDummy ); template RedisReplyType forward_scan_command ( typename std::enable_if::value, int>::type parDummy ); + bool is_end ( void ) const; void increment ( void ); bool equal ( const ScanIterator& parOther ) const; diff --git a/src/backends/redis/scan_iterator.inl b/src/backends/redis/scan_iterator.inl index ea7f7f3..51b7466 100644 --- a/src/backends/redis/scan_iterator.inl +++ b/src/backends/redis/scan_iterator.inl @@ -30,16 +30,33 @@ namespace redis { m_scan_context(0), m_curr_index(0) { - if (not parEnd) + if (not parEnd) { + m_curr_index = 1; //Some arbitrary value so is_end()==false + assert(not is_end()); this->increment(); + } + else { + assert(is_end()); + } + } + + template + bool ScanIterator::is_end() const { + return not m_curr_index and m_reply.empty() and not m_scan_context; } template void ScanIterator::increment() { + assert(not is_end()); static_assert(ValueFetch::step > 0, "Can't have an increase step of 0"); + if (m_curr_index + ValueFetch::step < m_reply.size()) { m_curr_index += ValueFetch::step; } + else if (m_curr_index + ValueFetch::step == m_reply.size() and not m_scan_context) { + m_reply.clear(); + m_curr_index = 0; + } else { std::vector array_reply; long long new_context; @@ -50,7 +67,7 @@ namespace redis { array_reply = get_array(whole_reply); assert(2 == array_reply.size()); assert(array_reply.size() % ValueFetch::step == 0); - new_context = get_integer(array_reply[0]); + new_context = get_integer_autoconv_if_str(array_reply[0]); } while (new_context and array_reply.empty()); m_reply = get_array(array_reply[1]); @@ -63,15 +80,18 @@ namespace redis { bool ScanIterator::equal (const ScanIterator& parOther) const { return (&parOther == this) or + (is_end() and parOther.is_end()) or ( + not (is_end() or parOther.is_end()) and implem::ScanIteratorBaseClass::is_equal(parOther) and - (m_scan_context == parOther.m_scan_context) + (m_scan_context == parOther.m_scan_context) and + (m_curr_index == parOther.m_curr_index) and + (m_reply.size() == parOther.m_reply.size()) ); } template const V& ScanIterator::dereference() const { - assert(m_scan_context); assert(not m_reply.empty()); assert(m_curr_index < m_reply.size());