1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2025-02-17 11:45:50 +00:00

Don't throw if reply is of error type - just put it in Reply.

This commit is contained in:
King_DuckZ 2016-06-20 18:06:26 +01:00
parent 53a42fa7c0
commit cdae333e1f
3 changed files with 17 additions and 13 deletions

View file

@ -43,7 +43,7 @@ namespace redis {
PtrToReplyIterator(parReply->element + parReply->elements, &make_redis_reply_type)
);
case REDIS_REPLY_ERROR:
throw RedisError(parReply->str, parReply->len);
return ErrorString(parReply->str, parReply->len);
default:
return Reply();
};
@ -143,9 +143,4 @@ namespace redis {
auto Command::zscan (boost::string_ref parKey) -> zscan_range {
return zscan_range(zscan_iterator(this, parKey, false), zscan_iterator(this, parKey, true));
}
RedisError::RedisError (const char* parMessage, std::size_t parLength) :
std::runtime_error(std::string(parMessage, parLength))
{
}
} //namespace redis

View file

@ -90,11 +90,6 @@ namespace redis {
LengthArray{ arg_to_bin_safe_length(string_ref(parCommand)), arg_to_bin_safe_length(std::forward<Args>(parArgs))... }.data()
);
}
class RedisError : public std::runtime_error {
public:
RedisError ( const char* parMessage, std::size_t parLength );
};
} //namespace redis
#endif

View file

@ -25,17 +25,30 @@
namespace redis {
struct Reply;
class ErrorString {
public:
ErrorString ( const char* parCStr, std::size_t parLen ) :
m_msg(parCStr, parLen)
{ }
const std::string& message ( void ) const noexcept { return m_msg; }
private:
std::string m_msg;
};
namespace implem {
using RedisVariantType = boost::variant<
long long,
std::string,
std::vector<Reply>
std::vector<Reply>,
ErrorString
>;
} //namespace implem
enum RedisVariantTypes {
RedisVariantType_Integer = 0,
RedisVariantType_String,
RedisVariantType_Array
RedisVariantType_Array,
RedisVariantType_Error
};
struct Reply : implem::RedisVariantType {
@ -45,6 +58,7 @@ namespace redis {
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 ( ErrorString&& parVal ) : base_class(std::move(parVal)) {}
~Reply ( void ) noexcept = default;
};