/* 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 idD83EEBFC927840C6B9F32D61A1D1E582 #define idD83EEBFC927840C6B9F32D61A1D1E582 #include "arg_to_bin_safe.hpp" #include "scan_iterator.hpp" #include "reply.hpp" #include #include #include #include #include #include #include #include #include #include #include struct redisContext; namespace redis { class Command { public: typedef ScanIterator> scan_iterator; typedef boost::iterator_range scan_range; typedef ScanIterator, ScanCommands::HSCAN>> hscan_iterator; typedef boost::iterator_range hscan_range; typedef ScanIterator> sscan_iterator; typedef boost::iterator_range sscan_range; typedef ScanIterator, ScanCommands::ZSCAN>> zscan_iterator; typedef boost::iterator_range zscan_range; Command ( std::string&& parAddress, uint16_t parPort ); ~Command ( void ) noexcept; void connect ( void ); void disconnect ( void ); bool is_connected ( void ) const; template Reply run ( const char* parCommand, Args&&... parArgs ); //Single Redis command wrappers scan_range scan ( void ); hscan_range hscan ( boost::string_ref parKey ); sscan_range sscan ( boost::string_ref parKey ); zscan_range zscan ( boost::string_ref parKey ); private: using RedisConnection = std::unique_ptr; Reply run_pvt ( int parArgc, const char** parArgv, std::size_t* parLengths ); RedisConnection m_conn; std::string m_address; uint16_t m_port; }; template Reply Command::run (const char* parCommand, Args&&... parArgs) { 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 implem::MakeCharInfo; using boost::string_ref; return this->run_pvt( static_cast(arg_count), CharPointerArray{ (arg_to_bin_safe_char(string_ref(parCommand))), MakeCharInfo::type>::type>(std::forward(parArgs)).data()... }.data(), LengthArray{ arg_to_bin_safe_length(string_ref(parCommand)), arg_to_bin_safe_length(std::forward(parArgs))... }.data() ); } } //namespace redis #endif