1
0
Fork 0
mirror of https://github.com/KingDuckZ/incredis synced 2024-12-27 21:35:42 +00:00

Add some convenience methods to check the type of a reply.

This commit is contained in:
King_DuckZ 2016-11-28 09:50:48 +00:00
parent 0d4561e2c7
commit 3b57d01b0f
2 changed files with 36 additions and 5 deletions

View file

@ -77,6 +77,13 @@ namespace redis {
Reply ( StatusString&& parVal ) : base_class(std::move(parVal)) {}
Reply ( std::nullptr_t parVal ) : base_class(parVal) {}
~Reply ( void ) noexcept = default;
bool is_integer ( void ) const;
bool is_string ( void ) const;
bool is_array ( void ) const;
bool is_error ( void ) const;
bool is_status ( void ) const;
bool is_nil ( void ) const;
};
const long long& get_integer ( const Reply& parReply );

View file

@ -21,16 +21,16 @@
namespace redis {
const long long& get_integer (const Reply& parReply) {
assert(RedisVariantType_Integer == parReply.which());
assert(parReply.is_integer());
return boost::get<long long>(parReply);
}
const std::string& get_string (const Reply& parReply) {
static const std::string empty_str;
if (RedisVariantType_Nil == parReply.which())
if (parReply.is_nil())
return empty_str;
assert(RedisVariantType_String == parReply.which());
assert(parReply.is_string());
return boost::get<std::string>(parReply);
}
@ -50,12 +50,12 @@ namespace redis {
}
const std::vector<Reply>& get_array (const Reply& parReply) {
assert(RedisVariantType_Array == parReply.which());
assert(parReply.is_array());
return boost::get<std::vector<Reply>>(parReply);
}
const ErrorString& get_error_string (const Reply& parReply) {
assert(RedisVariantType_Error == parReply.which());
assert(parReply.is_error());
return boost::get<ErrorString>(parReply);
}
@ -83,4 +83,28 @@ namespace redis {
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 );
bool Reply::is_integer() const {
return RedisVariantType_Integer == this->which();
}
bool Reply::is_string() const {
return RedisVariantType_String == this->which();
}
bool Reply::is_array() const {
return RedisVariantType_Array == this->which();
}
bool Reply::is_error() const {
return RedisVariantType_Error == this->which();
}
bool Reply::is_status() const {
return RedisVariantType_Status == this->which();
}
bool Reply::is_nil() const {
return RedisVariantType_Nil == this->which();
}
} //namespace redis