From 7f25fdb37ce5dfebea034059ff1bc61b176f0d3f Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Wed, 29 Jun 2016 22:49:38 +0100 Subject: [PATCH] Add support for 'status string' replies from Redis. --- src/backends/redis/reply.cpp | 11 +++++++++++ src/backends/redis/reply.hpp | 19 +++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/backends/redis/reply.cpp b/src/backends/redis/reply.cpp index 9751f11..575d543 100644 --- a/src/backends/redis/reply.cpp +++ b/src/backends/redis/reply.cpp @@ -50,6 +50,11 @@ namespace redis { return boost::get>(parReply); } + const ErrorString& get_error_string (const Reply& parReply) { + assert(RedisVariantType_Error == parReply.which()); + return boost::get(parReply); + } + template <> const std::string& get (const Reply& parReply) { return get_string(parReply); @@ -65,7 +70,13 @@ namespace redis { return get_integer(parReply); } + template <> + const ErrorString& get (const Reply& parReply) { + return get_error_string(parReply); + } + template const std::string& get ( const Reply& parReply ); template const std::vector& get> ( const Reply& parReply ); template const long long& get ( const Reply& parReply ); + template const ErrorString& get ( const Reply& parReply ); } //namespace redis diff --git a/src/backends/redis/reply.hpp b/src/backends/redis/reply.hpp index 2bce8bc..bffbe25 100644 --- a/src/backends/redis/reply.hpp +++ b/src/backends/redis/reply.hpp @@ -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, - 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&& 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& get_array ( const Reply& parReply ); + const ErrorString& get_error_string ( const Reply& parReply ); template const T& get ( const Reply& parReply );