mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2024-11-25 00:53:43 +00:00
Rename RedisReplyType to just Reply.
This commit is contained in:
parent
533b571771
commit
316f8f585b
7 changed files with 47 additions and 47 deletions
|
@ -28,9 +28,9 @@ namespace redis {
|
|||
namespace {
|
||||
using RedisReply = std::unique_ptr<redisReply, void(*)(void*)>;
|
||||
|
||||
RedisReplyType make_redis_reply_type (redisReply* parReply) {
|
||||
Reply make_redis_reply_type (redisReply* parReply) {
|
||||
using boost::transform_iterator;
|
||||
using PtrToReplyIterator = transform_iterator<RedisReplyType(*)(redisReply*), redisReply**>;
|
||||
using PtrToReplyIterator = transform_iterator<Reply(*)(redisReply*), redisReply**>;
|
||||
|
||||
switch (parReply->type) {
|
||||
case REDIS_REPLY_INTEGER:
|
||||
|
@ -38,12 +38,12 @@ namespace redis {
|
|||
case REDIS_REPLY_STRING:
|
||||
return std::string(parReply->str, parReply->len);
|
||||
case REDIS_REPLY_ARRAY:
|
||||
return std::vector<RedisReplyType>(
|
||||
return std::vector<Reply>(
|
||||
PtrToReplyIterator(parReply->element, &make_redis_reply_type),
|
||||
PtrToReplyIterator(parReply->element + parReply->elements, &make_redis_reply_type)
|
||||
);
|
||||
default:
|
||||
return RedisReplyType();
|
||||
return Reply();
|
||||
};
|
||||
}
|
||||
} //unnamed namespace
|
||||
|
@ -84,7 +84,7 @@ namespace redis {
|
|||
m_conn.reset();
|
||||
}
|
||||
|
||||
RedisReplyType Command::run_pvt (int parArgc, const char** parArgv, std::size_t* parLengths) {
|
||||
Reply 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
|
||||
|
|
|
@ -55,7 +55,7 @@ namespace redis {
|
|||
bool is_connected ( void ) const;
|
||||
|
||||
template <typename... Args>
|
||||
RedisReplyType run ( const char* parCommand, Args&&... parArgs );
|
||||
Reply run ( const char* parCommand, Args&&... parArgs );
|
||||
|
||||
//Single Redis command wrappers
|
||||
scan_range scan ( void );
|
||||
|
@ -66,7 +66,7 @@ namespace redis {
|
|||
private:
|
||||
using RedisConnection = std::unique_ptr<redisContext, void(*)(redisContext*)>;
|
||||
|
||||
RedisReplyType run_pvt ( int parArgc, const char** parArgv, std::size_t* parLengths );
|
||||
Reply run_pvt ( int parArgc, const char** parArgv, std::size_t* parLengths );
|
||||
|
||||
RedisConnection m_conn;
|
||||
std::string m_address;
|
||||
|
@ -74,7 +74,7 @@ namespace redis {
|
|||
};
|
||||
|
||||
template <typename... Args>
|
||||
RedisReplyType Command::run (const char* parCommand, Args&&... parArgs) {
|
||||
Reply Command::run (const char* parCommand, Args&&... parArgs) {
|
||||
constexpr const std::size_t arg_count = sizeof...(Args) + 1;
|
||||
using CharPointerArray = std::array<const char*, arg_count>;
|
||||
using LengthArray = std::array<std::size_t, arg_count>;
|
||||
|
|
|
@ -20,15 +20,15 @@
|
|||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
namespace redis {
|
||||
const long long& get_integer (const RedisReplyType& parReply) {
|
||||
const long long& get_integer (const Reply& parReply) {
|
||||
return boost::get<long long>(parReply);
|
||||
}
|
||||
|
||||
const std::string& get_string (const RedisReplyType& parReply) {
|
||||
const std::string& get_string (const Reply& parReply) {
|
||||
return boost::get<std::string>(parReply);
|
||||
}
|
||||
|
||||
long long get_integer_autoconv_if_str (const RedisReplyType &parReply) {
|
||||
long long get_integer_autoconv_if_str (const Reply &parReply) {
|
||||
using boost::lexical_cast;
|
||||
|
||||
const auto type = parReply.which();
|
||||
|
@ -43,26 +43,26 @@ namespace redis {
|
|||
}
|
||||
}
|
||||
|
||||
const std::vector<RedisReplyType>& get_array (const RedisReplyType& parReply) {
|
||||
return boost::get<std::vector<RedisReplyType>>(parReply);
|
||||
const std::vector<Reply>& get_array (const Reply& parReply) {
|
||||
return boost::get<std::vector<Reply>>(parReply);
|
||||
}
|
||||
|
||||
template <>
|
||||
const std::string& get<std::string> (const RedisReplyType& parReply) {
|
||||
const std::string& get<std::string> (const Reply& parReply) {
|
||||
return get_string(parReply);
|
||||
}
|
||||
|
||||
template <>
|
||||
const std::vector<RedisReplyType>& get<std::vector<RedisReplyType>> (const RedisReplyType& parReply) {
|
||||
const std::vector<Reply>& get<std::vector<Reply>> (const Reply& parReply) {
|
||||
return get_array(parReply);
|
||||
}
|
||||
|
||||
template <>
|
||||
const long long& get<long long> (const RedisReplyType& parReply) {
|
||||
const long long& get<long long> (const Reply& parReply) {
|
||||
return get_integer(parReply);
|
||||
}
|
||||
|
||||
template const std::string& get<std::string> ( const RedisReplyType& parReply );
|
||||
template const std::vector<RedisReplyType>& get<std::vector<RedisReplyType>> ( const RedisReplyType& parReply );
|
||||
template const long long& get<long long> ( const RedisReplyType& parReply );
|
||||
template const std::string& get<std::string> ( const Reply& parReply );
|
||||
template const std::vector<Reply>& get<std::vector<Reply>> ( const Reply& parReply );
|
||||
template const long long& get<long long> ( const Reply& parReply );
|
||||
} //namespace redis
|
||||
|
|
|
@ -23,13 +23,13 @@
|
|||
#include <string>
|
||||
|
||||
namespace redis {
|
||||
class RedisReplyType;
|
||||
class Reply;
|
||||
|
||||
namespace implem {
|
||||
using RedisVariantType = boost::variant<
|
||||
long long,
|
||||
std::string,
|
||||
boost::recursive_wrapper<std::vector<RedisReplyType>>
|
||||
boost::recursive_wrapper<std::vector<Reply>>
|
||||
>;
|
||||
enum RedisVariantTypes {
|
||||
RedisVariantType_Integer = 0,
|
||||
|
@ -39,23 +39,23 @@ namespace redis {
|
|||
};
|
||||
} //namespace implem
|
||||
|
||||
struct RedisReplyType : implem::RedisVariantType {
|
||||
struct Reply : implem::RedisVariantType {
|
||||
using base_class = implem::RedisVariantType;
|
||||
|
||||
RedisReplyType ( void ) = default;
|
||||
RedisReplyType ( long long parVal ) : base_class(parVal) {}
|
||||
RedisReplyType ( std::string&& parVal ) : base_class(std::move(parVal)) {}
|
||||
RedisReplyType ( std::vector<RedisReplyType>&& parVal ) : base_class(std::move(parVal)) {}
|
||||
~RedisReplyType ( void ) noexcept = default;
|
||||
Reply ( void ) = default;
|
||||
Reply ( long long parVal ) : base_class(parVal) {}
|
||||
Reply ( std::string&& parVal ) : base_class(std::move(parVal)) {}
|
||||
Reply ( std::vector<Reply>&& parVal ) : base_class(std::move(parVal)) {}
|
||||
~Reply ( void ) noexcept = default;
|
||||
};
|
||||
|
||||
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<RedisReplyType>& get_array ( const RedisReplyType& parReply );
|
||||
const long long& get_integer ( const Reply& parReply );
|
||||
long long get_integer_autoconv_if_str ( const Reply& parReply );
|
||||
const std::string& get_string ( const Reply& parReply );
|
||||
const std::vector<Reply>& get_array ( const Reply& parReply );
|
||||
|
||||
template <typename T>
|
||||
const T& get ( const RedisReplyType& parReply );
|
||||
const T& get ( const Reply& parReply );
|
||||
} //namespace redis
|
||||
|
||||
#endif
|
||||
|
|
|
@ -35,11 +35,11 @@ namespace redis {
|
|||
return m_command and m_command->is_connected();
|
||||
}
|
||||
|
||||
RedisReplyType ScanIteratorBaseClass::run (const char* parCommand, long long parScanContext) {
|
||||
Reply ScanIteratorBaseClass::run (const char* parCommand, long long parScanContext) {
|
||||
return m_command->run(parCommand, boost::lexical_cast<std::string>(parScanContext));
|
||||
}
|
||||
|
||||
RedisReplyType ScanIteratorBaseClass::run (const char* parCommand, const boost::string_ref& parParameter, long long parScanContext) {
|
||||
Reply ScanIteratorBaseClass::run (const char* parCommand, const boost::string_ref& parParameter, long long parScanContext) {
|
||||
return m_command->run(parCommand, parParameter, boost::lexical_cast<std::string>(parScanContext));
|
||||
}
|
||||
} //namespace implem
|
||||
|
|
|
@ -43,8 +43,8 @@ namespace redis {
|
|||
~ScanIteratorBaseClass ( void ) noexcept = default;
|
||||
|
||||
bool is_connected ( void ) const;
|
||||
RedisReplyType run ( const char* parCommand, long long parScanContext );
|
||||
RedisReplyType run ( const char* parCommand, const boost::string_ref& parParameter, long long parScanContext );
|
||||
Reply run ( const char* parCommand, long long parScanContext );
|
||||
Reply run ( const char* parCommand, const boost::string_ref& parParameter, long long parScanContext );
|
||||
|
||||
bool is_equal ( const ScanIteratorBaseClass& parOther ) const { return m_command == parOther.m_command; }
|
||||
|
||||
|
@ -76,9 +76,9 @@ namespace redis {
|
|||
|
||||
private:
|
||||
template <typename T>
|
||||
RedisReplyType forward_scan_command ( typename std::enable_if<HasScanTargetMethod<T>::value, int>::type parDummy );
|
||||
Reply forward_scan_command ( typename std::enable_if<HasScanTargetMethod<T>::value, int>::type parDummy );
|
||||
template <typename T>
|
||||
RedisReplyType forward_scan_command ( typename std::enable_if<not HasScanTargetMethod<T>::value, int>::type parDummy );
|
||||
Reply forward_scan_command ( typename std::enable_if<not HasScanTargetMethod<T>::value, int>::type parDummy );
|
||||
bool is_end ( void ) const;
|
||||
|
||||
void increment ( void );
|
||||
|
@ -97,7 +97,7 @@ namespace redis {
|
|||
static constexpr const char* command ( void ) { return "SCAN"; }
|
||||
static constexpr const std::size_t step = 1;
|
||||
|
||||
static const T& make_value ( const RedisReplyType* parItem );
|
||||
static const T& make_value ( const Reply* parItem );
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
|
@ -109,7 +109,7 @@ namespace redis {
|
|||
static constexpr const char* command ( void ) { return "SSCAN"; }
|
||||
static constexpr const std::size_t step = 1;
|
||||
|
||||
static const T& make_value ( const RedisReplyType* parItem );
|
||||
static const T& make_value ( const Reply* parItem );
|
||||
boost::string_ref scan_target ( void ) const { return m_scan_target; }
|
||||
|
||||
private:
|
||||
|
@ -126,7 +126,7 @@ namespace redis {
|
|||
static constexpr const char* command ( void ) { return ScanCommands::_from_integral(Command)._to_string(); }
|
||||
static constexpr const std::size_t step = 2;
|
||||
|
||||
static value_type make_value ( const RedisReplyType* parItem );
|
||||
static value_type make_value ( const Reply* parItem );
|
||||
boost::string_ref scan_target ( void ) const { return m_scan_target; }
|
||||
|
||||
private:
|
||||
|
|
|
@ -81,7 +81,7 @@ namespace redis {
|
|||
m_curr_index = 0;
|
||||
}
|
||||
else {
|
||||
std::vector<RedisReplyType> array_reply;
|
||||
std::vector<Reply> array_reply;
|
||||
long long new_context;
|
||||
|
||||
do {
|
||||
|
@ -131,30 +131,30 @@ namespace redis {
|
|||
|
||||
template <typename ValueFetch>
|
||||
template <typename T>
|
||||
RedisReplyType ScanIterator<ValueFetch>::forward_scan_command (typename std::enable_if<HasScanTargetMethod<T>::value, int>::type) {
|
||||
Reply ScanIterator<ValueFetch>::forward_scan_command (typename std::enable_if<HasScanTargetMethod<T>::value, int>::type) {
|
||||
return implem::ScanIteratorBaseClass::run(T::command(), T::scan_target(), m_scan_context);
|
||||
}
|
||||
|
||||
template <typename ValueFetch>
|
||||
template <typename T>
|
||||
RedisReplyType ScanIterator<ValueFetch>::forward_scan_command (typename std::enable_if<not HasScanTargetMethod<T>::value, int>::type) {
|
||||
Reply ScanIterator<ValueFetch>::forward_scan_command (typename std::enable_if<not HasScanTargetMethod<T>::value, int>::type) {
|
||||
return implem::ScanIteratorBaseClass::run(T::command(), m_scan_context);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
auto ScanSingleValues<T>::make_value (const RedisReplyType* parItem) -> const value_type& {
|
||||
auto ScanSingleValues<T>::make_value (const Reply* parItem) -> const value_type& {
|
||||
assert(parItem);
|
||||
return get<T>(*parItem);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
auto ScanSingleValuesInKey<T>::make_value (const RedisReplyType* parItem) -> const value_type& {
|
||||
auto ScanSingleValuesInKey<T>::make_value (const Reply* parItem) -> const value_type& {
|
||||
assert(parItem);
|
||||
return get<T>(*parItem);
|
||||
}
|
||||
|
||||
template <typename P, char Command, typename A, typename B>
|
||||
auto ScanPairs<P, Command, A, B>::make_value (const RedisReplyType* parItem) -> value_type {
|
||||
auto ScanPairs<P, Command, A, B>::make_value (const Reply* parItem) -> value_type {
|
||||
assert(parItem);
|
||||
return value_type(get<A>(parItem[0]), get<B>(parItem[1]));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue