Committing more work ...

This commit is contained in:
fbraem
2015-10-22 18:54:44 +02:00
parent 9acd00e25a
commit 8f950a903a
20 changed files with 492 additions and 178 deletions

View File

@@ -15,8 +15,6 @@
// SPDX-License-Identifier: BSL-1.0
//
#include <sstream>
#include "Poco/Redis/Array.h"
namespace Poco {
@@ -60,13 +58,7 @@ void Array::add()
std::string Array::toString() const
{
std::stringstream result;
result << "*" << _elements.size() << "\r\n";
for(std::vector<AbstractType::Ptr>::const_iterator it = _elements.begin(); it != _elements.end(); ++it)
{
result << (*it)->toString();
}
return result.str();
return ElementTraits<Array>::toString(*this);
}
} }

View File

@@ -1,20 +1,20 @@
//
// Connection.cpp
// Client.cpp
//
// $Id$
//
// Library: Redis
// Package: Redis
// Module: Connection
// Module: Client
//
// Implementation of the Connection class.
// Implementation of the Client class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include <iostream>
#include "Poco/Redis/Client.h"
@@ -22,71 +22,128 @@ namespace Poco {
namespace Redis {
Connection::Connection() : _address(), _socket()
Client::Client() : _address(), _socket()
{
}
Connection::Connection(const std::string& hostAndPort) : _address(hostAndPort), _socket()
Client::Client(const std::string& hostAndPort) : _address(hostAndPort), _socket()
{
connect();
}
Connection::Connection(const std::string& host, int port) : _address(host, port), _socket()
Client::Client(const std::string& host, int port) : _address(host, port), _socket()
{
connect();
}
Connection::Connection(const Net::SocketAddress& addrs) : _address(addrs), _socket()
Client::Client(const Net::SocketAddress& addrs) : _address(addrs), _socket()
{
connect();
}
Connection::~Connection()
Client::~Client()
{
}
void Connection::connect()
void Client::connect()
{
_socket.connect(_address);
}
void Connection::connect(const std::string& hostAndPort)
void Client::connect(const std::string& hostAndPort)
{
_address = Net::SocketAddress(hostAndPort);
connect();
}
void Connection::connect(const std::string& host, int port)
void Client::connect(const std::string& host, int port)
{
_address = Net::SocketAddress(host, port);
connect();
}
void Connection::connect(const Net::SocketAddress& addrs)
void Client::connect(const Net::SocketAddress& addrs)
{
_address = addrs;
connect();
}
void Connection::disconnect()
void Client::disconnect()
{
_socket.close();
}
void Connection::sendCommand(const Array& command)
void Client::writeCommand(const Array& command)
{
std::string commandStr = command.toString();
_socket.write(commandStr.c_str(), commandStr.length());
}
RedisType::Ptr Client::readReply()
{
RedisType::Ptr result = createRedisType( _socket.get());
if ( result.isNull() )
{
throw IOException("Invalid Redis type returned");
}
result->read(_socket);
return result;
}
RedisType::Ptr Client::sendCommand(const Array& command)
{
writeCommand(command);
return readReply();
}
void Client::sendCommands(const std::vector<Array>& commands, std::vector<RedisType::Ptr>& results)
{
for(std::vector<Array>::const_iterator it = commands.begin(); it != commands.end(); ++it)
{
writeCommand(*it);
}
for(int i = 0; i < commands.size(); ++i)
{
RedisType::Ptr result = readReply();
results.push_back(result);
}
}
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

35
Redis/src/Error.cpp Normal file
View File

@@ -0,0 +1,35 @@
//
// Error.cpp
//
// $Id$
//
// Library: Redis
// Package: Redis
// Module: Error
//
// Implementation of the Error class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/Redis/Error.h"
namespace Poco {
namespace Redis {
Error::Error()
{
}
Error::Error(const std::string& message) : _message(message)
{
}
Error::~Error()
{
}
} }

View File

@@ -14,7 +14,7 @@
//
// SPDX-License-Identifier: BSL-1.0
//
#include <iostream>
#include "Poco/Redis/RedisSocket.h"
namespace Poco {
@@ -82,7 +82,7 @@ void RedisSocket::read(UInt64 length, std::string& data)
int RedisSocket::write(const char* buffer, std::streamsize length)
{
_socket.sendBytes(buffer, (int) length);
return _socket.sendBytes(buffer, (int) length);
}
void RedisSocket::refill()

View File

@@ -21,11 +21,11 @@ namespace Poco {
namespace Redis {
AbstractType::AbstractType()
RedisType::RedisType()
{
}
AbstractType::~AbstractType()
RedisType::~RedisType()
{
}