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

@@ -29,7 +29,7 @@ poco: libexecs $(if $(TESTS),tests) $(if $(SAMPLES),samples)
all: libexecs tests samples
INSTALLDIR = $(DESTDIR)$(POCO_PREFIX)
COMPONENTS = Foundation XML JSON Util Net Crypto NetSSL_OpenSSL Data Data/SQLite Data/ODBC Data/MySQL MongoDB Zip PageCompiler PageCompiler/File2Page CppParser PDF
COMPONENTS = Foundation XML JSON Util Net Crypto NetSSL_OpenSSL Data Data/SQLite Data/ODBC Data/MySQL MongoDB Redis Zip PageCompiler PageCompiler/File2Page CppParser PDF
cppunit:
$(MAKE) -C $(POCO_BASE)/CppUnit
@@ -52,10 +52,10 @@ install: libexecs
find $(POCO_BUILD)/lib/$(POCO_TARGET_OSNAME)/$(POCO_TARGET_OSARCH) -name "$(LIBPREFIX)Poco*" -type f -exec cp -f {} $(INSTALLDIR)/lib \;
find $(POCO_BUILD)/lib/$(POCO_TARGET_OSNAME)/$(POCO_TARGET_OSARCH) -name "$(LIBPREFIX)Poco*" -type l -exec cp -Rf {} $(INSTALLDIR)/lib \;
libexecs = Foundation-libexec XML-libexec JSON-libexec Util-libexec Net-libexec Crypto-libexec NetSSL_OpenSSL-libexec Data-libexec Data/SQLite-libexec Data/ODBC-libexec Data/MySQL-libexec MongoDB-libexec Zip-libexec PageCompiler-libexec PageCompiler/File2Page-libexec CppParser-libexec PDF-libexec
tests = Foundation-tests XML-tests JSON-tests Util-tests Net-tests Crypto-tests NetSSL_OpenSSL-tests Data-tests Data/SQLite-tests Data/ODBC-tests Data/MySQL-tests MongoDB-tests Zip-tests CppParser-tests PDF-tests
libexecs = Foundation-libexec XML-libexec JSON-libexec Util-libexec Net-libexec Crypto-libexec NetSSL_OpenSSL-libexec Data-libexec Data/SQLite-libexec Data/ODBC-libexec Data/MySQL-libexec MongoDB-libexec Redis-libexec Zip-libexec PageCompiler-libexec PageCompiler/File2Page-libexec CppParser-libexec PDF-libexec
tests = Foundation-tests XML-tests JSON-tests Util-tests Net-tests Crypto-tests NetSSL_OpenSSL-tests Data-tests Data/SQLite-tests Data/ODBC-tests Data/MySQL-tests MongoDB-tests Redis-tests Zip-tests CppParser-tests PDF-tests
samples = Foundation-samples XML-samples JSON-samples Util-samples Net-samples Crypto-samples NetSSL_OpenSSL-samples Data-samples MongoDB-samples Zip-samples PageCompiler-samples PDF-samples
cleans = Foundation-clean XML-clean JSON-clean Util-clean Net-clean Crypto-clean NetSSL_OpenSSL-clean Data-clean Data/SQLite-clean Data/ODBC-clean Data/MySQL-clean MongoDB-clean Zip-clean PageCompiler-clean PageCompiler/File2Page-clean CppParser-clean PDF-clean
cleans = Foundation-clean XML-clean JSON-clean Util-clean Net-clean Crypto-clean NetSSL_OpenSSL-clean Data-clean Data/SQLite-clean Data/ODBC-clean Data/MySQL-clean MongoDB-clean Redis-clean Zip-clean PageCompiler-clean PageCompiler/File2Page-clean CppParser-clean PDF-clean
.PHONY: $(libexecs)
.PHONY: $(tests)
@@ -223,6 +223,21 @@ MongoDB-clean:
$(MAKE) -C $(POCO_BASE)/MongoDB/testsuite clean
$(MAKE) -C $(POCO_BASE)/MongoDB/samples clean
Redis-libexec: Foundation-libexec Net-libexec
$(MAKE) -C $(POCO_BASE)/Redis
Redis-tests: Redis-libexec cppunit
$(MAKE) -C $(POCO_BASE)/Redis/testsuite
#No samples yet ... uncomment this when added, and add Redis-samples to samples above
#Redis-samples: Redis-libexec
# $(MAKE) -C $(POCO_BASE)/Redis/samples
Redis-clean:
$(MAKE) -C $(POCO_BASE)/Redis clean
$(MAKE) -C $(POCO_BASE)/Redis/testsuite clean
# $(MAKE) -C $(POCO_BASE)/Redis/samples clean
Zip-libexec: Foundation-libexec Net-libexec Util-libexec XML-libexec
$(MAKE) -C $(POCO_BASE)/Zip

37
Redis/CMakeLists.txt Normal file
View File

@@ -0,0 +1,37 @@
set(LIBNAME "Redis")
set(POCO_LIBNAME "Poco${LIBNAME}")
# Sources
file(GLOB SRCS_G "src/*.cpp")
POCO_SOURCES_AUTO( SRCS ${SRCS_G})
# Headers
file(GLOB_RECURSE HDRS_G "include/*.h" )
POCO_HEADERS_AUTO( SRCS ${HDRS_G})
add_library( "${LIBNAME}" ${LIB_MODE} ${SRCS} )
add_library( "${POCO_LIBNAME}" ALIAS "${LIBNAME}")
set_target_properties( "${LIBNAME}"
PROPERTIES
VERSION ${SHARED_LIBRARY_VERSION} SOVERSION ${SHARED_LIBRARY_VERSION}
OUTPUT_NAME ${POCO_LIBNAME}
DEFINE_SYMBOL Redis_EXPORTS
)
target_link_libraries( "${LIBNAME}" Net Foundation)
target_include_directories( "${LIBNAME}"
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src
)
target_compile_definitions("${LIBNAME}" PUBLIC ${LIB_MODE_DEFINITIONS})
POCO_INSTALL("${LIBNAME}")
POCO_GENERATE_PACKAGE("${LIBNAME}")
if (ENABLE_TESTS)
add_subdirectory(samples)
add_subdirectory(testsuite)
endif ()

19
Redis/Makefile Normal file
View File

@@ -0,0 +1,19 @@
#
# Makefile
#
# $Id$
#
# Makefile for Poco Redis
#
include $(POCO_BASE)/build/rules/global
INCLUDE += -I $(POCO_BASE)/Redis/include/Poco/Redis
objects = Array Client Error Exception RedisSocket Type
target = PocoRedis
target_version = $(LIBVERSION)
target_libs = PocoFoundation PocoNet
include $(POCO_BASE)/build/rules/lib

16
Redis/Redis.progen Normal file
View File

@@ -0,0 +1,16 @@
vc.project.guid = ${vc.project.guidFromName}
vc.project.name = Redis
vc.project.target = Poco${vc.project.name}
vc.project.type = library
vc.project.pocobase = ..
vc.project.outdir = ${vc.project.pocobase}
vc.project.platforms = Win32, x64
vc.project.configurations = debug_shared, release_shared, debug_static_mt, release_static_mt, debug_static_md, release_static_md
vc.project.prototype = ${vc.project.name}_vs90.vcproj
vc.project.compiler.include = ..\\Foundation\\include;..\\Net\\include
vc.project.compiler.defines =
vc.project.compiler.defines.shared = ${vc.project.name}_EXPORTS
vc.project.compiler.defines.debug_shared = ${vc.project.compiler.defines.shared}
vc.project.compiler.defines.release_shared = ${vc.project.compiler.defines.shared}
vc.solution.create = true
vc.solution.include = testsuite\\TestSuite

2
Redis/dependencies Normal file
View File

@@ -0,0 +1,2 @@
Foundation
Net

View File

@@ -19,6 +19,8 @@
#define Redis_Array_INCLUDED
#include <vector>
#include <sstream>
#include "Poco/Redis/Redis.h"
#include "Poco/Redis/Type.h"
#include "Poco/Redis/Exception.h"
@@ -43,9 +45,13 @@ public:
void add();
void add(AbstractType::Ptr value);
void add(RedisType::Ptr value);
std::vector<RedisType::Ptr>::const_iterator begin() const;
void clear();
std::vector<RedisType::Ptr>::const_iterator end() const;
std::string toString() const;
@@ -53,22 +59,32 @@ public:
private:
std::vector<AbstractType::Ptr> _elements;
std::vector<RedisType::Ptr> _elements;
friend class Connection;
};
inline std::vector<RedisType::Ptr>::const_iterator Array::begin() const
{
return _elements.begin();
}
inline void Array::clear()
{
_elements.clear();
}
inline std::vector<RedisType::Ptr>::const_iterator Array::end() const
{
return _elements.end();
}
inline size_t Array::size() const
{
return _elements.size();
}
inline void Array::add(AbstractType::Ptr value)
inline void Array::add(RedisType::Ptr value)
{
_elements.push_back(value);
}
@@ -76,7 +92,9 @@ inline void Array::add(AbstractType::Ptr value)
template<>
struct ElementTraits<Array>
{
enum { TypeId = AbstractType::REDIS_ARRAY };
enum { TypeId = RedisType::REDIS_ARRAY };
static const char marker = '*';
static std::string typeName()
{
@@ -85,39 +103,45 @@ struct ElementTraits<Array>
static std::string toString(const Array& value)
{
return value.toString();
std::stringstream result;
result << marker << value.size() << LineEnding::NEWLINE_CRLF;
for(std::vector<RedisType::Ptr>::const_iterator it = value.begin(); it != value.end(); ++it)
{
result << (*it)->toString();
}
return result.str();
}
};
template<> inline
void Type<Array>::read(RedisSocket& socket)
{
std::string line;
socket.readLine(line);
Int64 length = NumberParser::parse64(line);
for(int i = 0; i < length; ++i)
{
char elementType = socket.get();
AbstractType::Ptr t;
RedisType::Ptr element;
switch(elementType)
{
case ':': // Integer
t = new Type<Int64>();
case ElementTraits<Int64>::marker :
element = new Type<Int64>();
break;
case '+' : // Simple String
t = new Type<std::string>();
case ElementTraits<std::string>::marker :
element = new Type<std::string>();
break;
case '$' : // Bulk String
t = new Type<BulkString>();
case ElementTraits<BulkString>::marker :
element = new Type<BulkString>();
break;
}
if ( t.isNull() ) throw RedisException("Wrong answer received from Redis server");
if ( element.isNull() ) throw RedisException("Wrong answer received from Redis server");
t->read(socket);
_value.add(t);
element->read(socket);
_value.add(element);
}
}

View File

@@ -1,13 +1,13 @@
//
// Connection.h
// Client.h
//
// $Id$
//
// Library: Redis
// Package: Redis
// Module: Connection
// Module: Client
//
// Definition of the Connection class.
// Definition of the Client class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// and Contributors.
@@ -25,33 +25,34 @@
#include "Poco/Redis/Redis.h"
#include "Poco/Redis/Array.h"
#include "Poco/Redis/Error.h"
#include "Poco/Redis/RedisSocket.h"
namespace Poco {
namespace Redis {
class Redis_API Connection
class Redis_API Client
/// Represents a connection to a Redis server
{
public:
typedef Poco::SharedPtr<Connection> Ptr;
typedef Poco::SharedPtr<Client> Ptr;
Connection();
Client();
/// Default constructor. Use this when you want to
/// connect later on.
Connection(const std::string& hostAndPort);
Client(const std::string& hostAndPort);
/// Constructor which connects to the given Redis host/port.
/// The host and port must be separated with a colon.
Connection(const std::string& host, int port);
Client(const std::string& host, int port);
/// Constructor which connects to the given Redis host/port.
Connection(const Net::SocketAddress& addrs);
Client(const Net::SocketAddress& addrs);
/// Constructor which connects to the given Redis host/port.
virtual ~Connection();
virtual ~Client();
/// Destructor
Net::SocketAddress address() const;
@@ -70,111 +71,47 @@ public:
void disconnect();
/// Disconnects from the Redis server
void sendCommand(const Array& command);
/// Sends a request to the Redis server
RedisType::Ptr sendCommand(const Array& command);
template<typename T>
void sendCommand(const Array& command, T& result)
void sendCommand(const Array& command, T& result)
{
Type<T> resultType;
sendCommand(command);
char type = _socket.get();
switch(type)
{
case ':':
{
if ( resultType.getType() == AbstractType::REDIS_INTEGER )
{
resultType.read(_socket);
}
else
{
std::string message;
message.append("Expected ");
message.append(ElementTraits<T>::typeName());
message.append(", got an Integer");
throw InvalidArgumentException(message);
}
break;
}
case '+': // Simple String
{
if ( resultType.getType() == AbstractType::REDIS_SIMPLE_STRING )
{
resultType.read(_socket);
}
else
{
std::string message;
message.append("Expected ");
message.append(ElementTraits<T>::typeName());
message.append(", got a Simple String");
throw InvalidArgumentException(message);
}
break;
}
case '-' : // Error
{
std::string error;
_socket.readLine(error);
throw RedisException(error);
}
case '$' : // Bulk String
{
if ( resultType.getType() == AbstractType::REDIS_BULK_STRING )
{
resultType.read(_socket);
}
else
{
std::string message;
message.append("Expected ");
message.append(ElementTraits<T>::typeName());
message.append(", got a Bulk String");
throw InvalidArgumentException(message);
}
break;
}
case '*' : //Array
{
if ( resultType.getType() == AbstractType::REDIS_ARRAY )
{
resultType.read(_socket);
}
else
{
std::string message;
message.append("Expected ");
message.append(ElementTraits<T>::typeName());
message.append(", got an Array");
throw InvalidArgumentException(message);
}
throw InvalidArgumentException("Expected integer, got an array");
}
default:
throw IOException("Invalid Redis type returned");
}
result = resultType.value();
readReply(result);
}
RedisType::Ptr readReply();
template<typename T>
void readReply(T& result)
{
RedisType::Ptr redisResult = readReply();
if ( redisResult->type() == ElementTraits<T>::TypeId )
result = ((Type<T>*) redisResult.get())->value();
else throw BadCastException();
}
void sendCommands(const std::vector<Array>& commands, std::vector<RedisType::Ptr>& results);
void writeCommand(const Array& command);
/// Sends a request to the Redis server
private:
Connection(const Connection&);
Connection& operator = (const Connection&);
Client(const Client&);
Client& operator = (const Client&);
Net::SocketAddress _address;
RedisSocket _socket;
void connect();
/// Connects to the Redis server
static RedisType::Ptr createRedisType(char marker);
};
inline Net::SocketAddress Connection::address() const
inline Net::SocketAddress Client::address() const
{
return _address;
}

View File

@@ -0,0 +1,83 @@
//
// Error.h
//
// $Id$
//
// Library: Redis
// Package: Redis
// Module: Error
//
// Definition of the Error class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef Redis_Error_INCLUDED
#define Redis_Error_INCLUDED
#include "Poco/Redis/Type.h"
#include "Poco/Redis/RedisSocket.h"
namespace Poco {
namespace Redis {
class Redis_API Error
{
public:
Error();
Error(const std::string& message);
virtual ~Error();
std::string getMessage() const;
void setMessage(const std::string& message);
private:
std::string _message;
};
inline std::string Error::getMessage() const
{
return _message;
}
inline void Error::setMessage(const std::string& message)
{
_message = message;
}
template<>
struct ElementTraits<Error>
{
enum { TypeId = RedisType::REDIS_ERROR };
static const char marker = '-';
static std::string typeName()
{
return "Error";
}
static std::string toString(const Error& value)
{
return marker + value.getMessage() + "\r\n";
}
};
template<> inline
void Type<Error>::read(RedisSocket& socket)
{
std::string s;
socket.readLine(s);
_value = s;
}
}} // Namespace Poco::Redis
#endif // Redis_Error_INCLUDED

View File

@@ -18,6 +18,7 @@
#ifndef Redis_Type_INCLUDED
#define Redis_Type_INCLUDED
#include "Poco/LineEndingConverter.h"
#include "Poco/NumberFormatter.h"
#include "Poco/NumberParser.h"
#include "Poco/SharedPtr.h"
@@ -30,16 +31,16 @@ namespace Poco {
namespace Redis {
class Redis_API AbstractType
class Redis_API RedisType
{
public:
typedef SharedPtr<AbstractType> Ptr;
typedef SharedPtr<RedisType> Ptr;
AbstractType();
virtual ~AbstractType();
RedisType();
virtual ~RedisType();
virtual int getType() const = 0;
virtual int type() const = 0;
virtual void read(RedisSocket& socket) = 0;
@@ -49,7 +50,8 @@ public:
REDIS_INTEGER,
REDIS_SIMPLE_STRING,
REDIS_BULK_STRING,
REDIS_ARRAY
REDIS_ARRAY,
REDIS_ERROR
};
private:
@@ -65,7 +67,9 @@ struct ElementTraits
template<>
struct ElementTraits<Poco::Int64>
{
enum { TypeId = AbstractType::REDIS_INTEGER };
enum { TypeId = RedisType::REDIS_INTEGER };
static const char marker = ':';
static std::string typeName()
{
@@ -74,7 +78,7 @@ struct ElementTraits<Poco::Int64>
static std::string toString(const Poco::Int64& value)
{
return ":" + NumberFormatter::format(value) + "\r\n";
return marker + NumberFormatter::format(value) + "\r\n";
}
};
@@ -82,16 +86,18 @@ struct ElementTraits<Poco::Int64>
template<>
struct ElementTraits<std::string>
{
enum { TypeId = AbstractType::REDIS_SIMPLE_STRING };
enum { TypeId = RedisType::REDIS_SIMPLE_STRING };
static std::string typeName()
{
return "Simple String";
}
static const char marker = '+';
static std::string toString(const std::string& value)
{
return "+" + value + "\r\n";
return marker + value + LineEnding::NEWLINE_CRLF;
}
};
@@ -102,28 +108,31 @@ typedef Optional<std::string> BulkString;
template<>
struct ElementTraits<BulkString>
{
enum { TypeId = AbstractType::REDIS_BULK_STRING };
enum { TypeId = RedisType::REDIS_BULK_STRING };
static std::string typeName()
{
return "Bulk String";
}
static const char marker = '$';
static std::string toString(const BulkString& value)
{
if ( value.isSpecified() ) {
if ( value.isSpecified() )
{
std::string s = value.value();
return "$" + NumberFormatter::format(s.length()) + "\r\n" + s + "\r\n";
return marker + NumberFormatter::format(s.length()) + LineEnding::NEWLINE_CRLF + s + LineEnding::NEWLINE_CRLF;
}
return "$-1\r\n";
return marker + std::string("-1") + LineEnding::NEWLINE_CRLF;
}
};
template<typename T>
class Redis_API Type : public AbstractType
class Redis_API Type : public RedisType
{
public:
public:
Type()
{
@@ -141,16 +150,15 @@ class Redis_API Type : public AbstractType
{
}
int getType() const
int type() const
{
return ElementTraits<T>::TypeId;
}
void read(RedisSocket& socket)
{
}
virtual void read(RedisSocket& socket);
virtual std::string toString() const {
virtual std::string toString() const
{
return ElementTraits<T>::toString(_value);
}
@@ -175,9 +183,8 @@ void Type<Int64>::read(RedisSocket& socket)
template<> inline
void Type<std::string>::read(RedisSocket& socket)
{
std::string s;
socket.readLine(s);
_value = s;
_value.clear();
socket.readLine(_value);
}
template<> inline
@@ -187,16 +194,15 @@ void Type<BulkString>::read(RedisSocket& socket)
std::string line;
socket.readLine(line);
int length = NumberParser::parse64(line);
if ( length >= 0 )
{
std::string s;
socket.read(length, s);
_value.assign(s);
socket.readLine(line);
}
else // -1
{
socket.readLine(line);
}
}

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()
{
}

View File

@@ -0,0 +1,23 @@
set(TESTUNIT "${LIBNAME}-testrunner")
# Sources
file(GLOB SRCS_G "src/*.cpp")
POCO_SOURCES_AUTO( TEST_SRCS ${SRCS_G})
# Headers
file(GLOB_RECURSE HDRS_G "src/*.h" )
POCO_HEADERS_AUTO( TEST_SRCS ${HDRS_G})
POCO_SOURCES_AUTO_PLAT( TEST_SRCS OFF
src/WinDriver.cpp
)
POCO_SOURCES_AUTO_PLAT( TEST_SRCS WINCE
src/WinCEDriver.cpp
)
set(TESTUNIT "${LIBNAME}-testrunner")
add_executable( ${TESTUNIT} ${TEST_SRCS} )
add_test(NAME ${LIBNAME} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${TESTUNIT} -all)
target_link_libraries( ${TESTUNIT} PocoRedis PocoFoundation CppUnit )

17
Redis/testsuite/Makefile Normal file
View File

@@ -0,0 +1,17 @@
#
# Makefile
#
# $Id$
#
# Makefile for Poco Redis testsuite
#
include $(POCO_BASE)/build/rules/global
objects = Driver RedisTest RedisTestSuite
target = testrunner
target_version = 1
target_libs = PocoRedis PocoFoundation PocoNet CppUnit
include $(POCO_BASE)/build/rules/exec

View File

@@ -0,0 +1,9 @@
vc.project.guid = ${vc.project.guidFromName}
vc.project.name = TestSuite
vc.project.target = TestSuite
vc.project.type = testsuite
vc.project.pocobase = ..\\..
vc.project.platforms = Win32, x64
vc.project.configurations = debug_shared, release_shared, debug_static_mt, release_static_mt, debug_static_md, release_static_md
vc.project.prototype = TestSuite_vs90.vcproj
vc.project.compiler.include = ..\\..\\Foundation\\include;..\\..\\Net\\include

View File

@@ -25,7 +25,7 @@ using namespace Poco::Redis;
bool RedisTest::_connected = false;
Poco::Redis::Connection RedisTest::_redis;
Poco::Redis::Client RedisTest::_redis;
RedisTest::RedisTest(const std::string& name):
@@ -98,16 +98,55 @@ void RedisTest::testPing()
Array command;
command.add("PING");
std::string result;
_redis.sendCommand(command, result);
RedisType::Ptr result = _redis.sendCommand(command);
}
void RedisTest::testSet()
{
if (!_connected)
{
std::cout << "Not connected, test skipped." << std::endl;
return;
}
Array command;
command.add("SET");
command.add("mykey");
command.add("Hello");
command.add("NX");
RedisType::Ptr result = _redis.sendCommand(command);
}
void RedisTest::testPipelining()
{
if (!_connected)
{
std::cout << "Not connected, test skipped." << std::endl;
return;
}
std::vector<Array> commands;
Array ping;
ping.add("PING");
commands.push_back(ping);
commands.push_back(ping);
std::vector<RedisType::Ptr> result;
_redis.sendCommands(commands, result);
}
CppUnit::Test* RedisTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("RedisTest");
CppUnit_addTest(pSuite, RedisTest, testEcho);
CppUnit_addTest(pSuite, RedisTest, testPing);
CppUnit_addTest(pSuite, RedisTest, testSet);
CppUnit_addTest(pSuite, RedisTest, testPipelining);
return pSuite;
}

View File

@@ -32,6 +32,8 @@ public:
void testEcho();
void testPing();
void testSet();
void testPipelining();
void setUp();
void tearDown();
@@ -43,7 +45,7 @@ private:
std::string _host;
unsigned _port;
static bool _connected;
static Poco::Redis::Connection _redis;
static Poco::Redis::Client _redis;
};

View File

@@ -18,5 +18,6 @@ PageCompiler/File2Page
PDF
CppParser
MongoDB
Redis
PocoDoc
ProGen