1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2024-11-25 00:53:43 +00:00

Add support for 'status string' replies from Redis.

This commit is contained in:
King_DuckZ 2016-06-29 22:49:38 +01:00
parent 2e68e639bf
commit 7f25fdb37c
2 changed files with 28 additions and 2 deletions

View file

@ -50,6 +50,11 @@ namespace redis {
return boost::get<std::vector<Reply>>(parReply);
}
const ErrorString& get_error_string (const Reply& parReply) {
assert(RedisVariantType_Error == parReply.which());
return boost::get<ErrorString>(parReply);
}
template <>
const std::string& get<std::string> (const Reply& parReply) {
return get_string(parReply);
@ -65,7 +70,13 @@ namespace redis {
return get_integer(parReply);
}
template <>
const ErrorString& get<ErrorString> (const Reply& parReply) {
return get_error_string(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 );
template const ErrorString& get<ErrorString> ( const Reply& parReply );
} //namespace redis

View file

@ -32,6 +32,17 @@ namespace redis {
{ }
const std::string& message ( void ) const noexcept { return m_msg; }
private:
std::string m_msg;
};
class StatusString {
public:
StatusString ( const char* parCStr, std::size_t parLen ) :
m_msg(parCStr, parLen)
{ }
const std::string& message ( void ) const noexcept { return m_msg; }
bool is_ok ( void ) const { return "OK" == m_msg; }
private:
std::string m_msg;
};
@ -41,14 +52,16 @@ namespace redis {
long long,
std::string,
std::vector<Reply>,
ErrorString
ErrorString,
StatusString
>;
} //namespace implem
enum RedisVariantTypes {
RedisVariantType_Integer = 0,
RedisVariantType_String,
RedisVariantType_Array,
RedisVariantType_Error
RedisVariantType_Error,
RedisVariantType_Status
};
struct Reply : implem::RedisVariantType {
@ -59,6 +72,7 @@ namespace redis {
Reply ( std::string&& parVal ) : base_class(std::move(parVal)) {}
Reply ( std::vector<Reply>&& parVal ) : base_class(std::move(parVal)) {}
Reply ( ErrorString&& parVal ) : base_class(std::move(parVal)) {}
Reply ( StatusString&& parVal ) : base_class(std::move(parVal)) {}
~Reply ( void ) noexcept = default;
};
@ -66,6 +80,7 @@ namespace redis {
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 );
const ErrorString& get_error_string ( const Reply& parReply );
template <typename T>
const T& get ( const Reply& parReply );