Move createRedisType to Type

This commit is contained in:
fbraem 2015-10-26 12:05:00 +01:00
parent 74b1ef2bb2
commit 723704ad16
3 changed files with 39 additions and 25 deletions

View File

@ -54,6 +54,14 @@ public:
REDIS_ERROR REDIS_ERROR
}; };
static RedisType::Ptr createRedisType(char marker);
/// Create a Redis type based on the marker :
/// + : a simple string (std::string)
/// - : an error (Error)
/// $ : a bulk string (BulkString)
/// * : an array (Array)
/// : : a signed 64 bit integer (Int64)
private: private:
}; };
@ -199,6 +207,7 @@ void Type<BulkString>::read(RedisSocket& socket)
socket.readLine(line); socket.readLine(line);
} }
} }

View File

@ -90,7 +90,7 @@ void Client::writeCommand(const Array& command)
RedisType::Ptr Client::readReply() RedisType::Ptr Client::readReply()
{ {
RedisType::Ptr result = createRedisType(_socket.get()); RedisType::Ptr result = RedisType::createRedisType(_socket.get());
if ( result.isNull() ) if ( result.isNull() )
{ {
throw RedisException("Invalid Redis type returned"); throw RedisException("Invalid Redis type returned");
@ -121,29 +121,5 @@ void Client::sendCommands(const std::vector<Array>& commands, std::vector<RedisT
} }
} }
RedisType::Ptr Client::createRedisType(char marker)
{
RedisType::Ptr result;
switch(marker)
{
case ElementTraits<Int64>::marker :
result = new Type<Int64>();
break;
case ElementTraits<std::string>::marker :
result = new Type<std::string>();
break;
case ElementTraits<BulkString>::marker :
result = new Type<BulkString>();
break;
case ElementTraits<Array>::marker :
result = new Type<Array>();
break;
case ElementTraits<Error>::marker :
result = new Type<Error>();
break;
}
return result;
}
} } // Poco::Redis } } // Poco::Redis

View File

@ -16,6 +16,8 @@
// //
#include "Poco/Redis/Type.h" #include "Poco/Redis/Type.h"
#include "Poco/Redis/Error.h"
#include "Poco/Redis/Array.h"
namespace Poco { namespace Poco {
namespace Redis { namespace Redis {
@ -29,4 +31,31 @@ RedisType::~RedisType()
{ {
} }
RedisType::Ptr RedisType::createRedisType(char marker)
{
RedisType::Ptr result;
switch(marker)
{
case ElementTraits<Int64>::marker :
result = new Type<Int64>();
break;
case ElementTraits<std::string>::marker :
result = new Type<std::string>();
break;
case ElementTraits<BulkString>::marker :
result = new Type<BulkString>();
break;
case ElementTraits<Array>::marker :
result = new Type<Array>();
break;
case ElementTraits<Error>::marker :
result = new Type<Error>();
break;
}
return result;
}
}} }}