From 4104a591e322fabb75188610fcebaf910c026961 Mon Sep 17 00:00:00 2001 From: Nathan Osman Date: Mon, 1 Jul 2013 09:00:58 -0700 Subject: [PATCH] Renamed Command class to Request to better reflect its actual role. --- CMakeLists.txt | 5 +-- include/qredis/client.h | 8 ++--- include/qredis/command.h | 41 ---------------------- include/qredis/request.h | 73 ++++++++++++++++++++++++++++++++++++++++ src/client.cpp | 5 +-- src/client_p.h | 4 +++ src/command.cpp | 13 ------- src/command_p.h | 14 -------- src/request.cpp | 13 +++++++ src/request_p.h | 14 ++++++++ 10 files changed, 114 insertions(+), 76 deletions(-) delete mode 100644 include/qredis/command.h create mode 100644 include/qredis/request.h delete mode 100644 src/command.cpp delete mode 100644 src/command_p.h create mode 100644 src/request.cpp create mode 100644 src/request_p.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 547aadf..7986064 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,11 +29,12 @@ include_directories(include) # QRedis source files. set(QREDIS_SRC src/client.cpp - src/command.cpp) + src/request.cpp) # QRedis header files requiring MOC. qt5_wrap_cpp(QREDIS_MOC - include/qredis/client.h) + include/qredis/client.h + include/qredis/request.h) # Create the client library. add_library(qredis SHARED diff --git a/include/qredis/client.h b/include/qredis/client.h index 5af71df..009b33a 100644 --- a/include/qredis/client.h +++ b/include/qredis/client.h @@ -5,7 +5,7 @@ #include #include -#include +#include #include "qredis_export.h" namespace QRedis @@ -48,11 +48,11 @@ namespace QRedis void disconnectFromHost(); /** - * @brief Sends the specified command to the Redis server. + * @brief Sends the specified command to the Redis server * @param command the command to execute - * @return an object that may be used for obtaining the response + * @return an object representing the request */ - Command * sendCommand(const QString & command); + Request * sendCommand(const QString & command); signals: diff --git a/include/qredis/command.h b/include/qredis/command.h deleted file mode 100644 index b0f01dc..0000000 --- a/include/qredis/command.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef QREDIS_COMMAND_H -#define QREDIS_COMMAND_H - -#include -#include - -#include "qredis_export.h" - -namespace QRedis -{ - class QREDIS_EXPORT CommandPrivate; - - /** - * @brief Represents a specific command and its response. - */ - class QREDIS_EXPORT Command : public QObject - { - public: - - /** - * @brief Creates a command - * @param parent - */ - explicit Command(QObject * parent = nullptr); - - /** - * @brief Destroys the command - */ - virtual ~Command(); - - signals: - - void completed(); - - private: - - const QScopedPointer d; - }; -} - -#endif // QREDIS_COMMAND_H diff --git a/include/qredis/request.h b/include/qredis/request.h new file mode 100644 index 0000000..c35c875 --- /dev/null +++ b/include/qredis/request.h @@ -0,0 +1,73 @@ +#ifndef QREDIS_REQUEST_H +#define QREDIS_REQUEST_H + +#include +#include +#include +#include + +#include "qredis_export.h" + +namespace QRedis +{ + class QREDIS_EXPORT RequestPrivate; + + /** + * @brief Represents a request and its response + */ + class QREDIS_EXPORT Request : public QObject + { + Q_OBJECT + + public: + + /** + * @brief Creates a request + * @param parent + */ + explicit Request(QObject * parent = nullptr); + + /** + * @brief Destroys the request + */ + virtual ~Request(); + + signals: + + /** + * @brief Emitted when a bulk reply is received + * @param value the bulk value + */ + void bulk(const QVariant & value); + + /** + * @brief Emitted when an error reply is received + * @param message a descriptive error message + */ + void error(const QString & message); + + /** + * @brief Emitted when an integer reply is received + * @param value the integer value + */ + void integer(qint64 value); + + /** + * @brief Emitted when a multi-bulk reply is received + * @param value the multi-bulk value + */ + void multiBulk(const QVariantList & value); + + /** + * @brief Emitted when a status reply is received + * @param message a descriptive status message + */ + void status(const QString & message); + + private: + + const QScopedPointer d; + }; +} + +#endif // QREDIS_REQUEST_H diff --git a/src/client.cpp b/src/client.cpp index d193ba9..235688e 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -24,7 +24,8 @@ void Client::disconnectFromHost() d->socket.disconnectFromHost(); } -Command * Client::sendCommand(const QString & command) +Request * Client::sendCommand(const QString & command) { - return new Command(this); + Request * request = new Request(this); + d->queue.enqueue(request); } diff --git a/src/client_p.h b/src/client_p.h index 712430a..dbdfedd 100644 --- a/src/client_p.h +++ b/src/client_p.h @@ -1,8 +1,11 @@ #ifndef QREDIS_CLIENT_P_H #define QREDIS_CLIENT_P_H +#include #include +#include + namespace QRedis { class ClientPrivate @@ -10,6 +13,7 @@ namespace QRedis public: QTcpSocket socket; + QQueue queue; }; } diff --git a/src/command.cpp b/src/command.cpp deleted file mode 100644 index 9fb56df..0000000 --- a/src/command.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include "command_p.h" - -using namespace QRedis; - -Command::Command(QObject * parent) - : QObject(parent), d(new CommandPrivate) -{ -} - -Command::~Command() -{ -} diff --git a/src/command_p.h b/src/command_p.h deleted file mode 100644 index 904367c..0000000 --- a/src/command_p.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef QREDIS_COMMAND_P_H -#define QREDIS_COMMAND_P_H - -namespace QRedis -{ - class CommandPrivate - { - public: - - //... - }; -} - -#endif // QREDIS_COMMAND_P_H diff --git a/src/request.cpp b/src/request.cpp new file mode 100644 index 0000000..55abb27 --- /dev/null +++ b/src/request.cpp @@ -0,0 +1,13 @@ +#include +#include "request_p.h" + +using namespace QRedis; + +Request::Request(QObject * parent) + : QObject(parent), d(new RequestPrivate) +{ +} + +Request::~Request() +{ +} diff --git a/src/request_p.h b/src/request_p.h new file mode 100644 index 0000000..3580e54 --- /dev/null +++ b/src/request_p.h @@ -0,0 +1,14 @@ +#ifndef QREDIS_REQUEST_P_H +#define QREDIS_REQUEST_P_H + +namespace QRedis +{ + class RequestPrivate + { + public: + + //... + }; +} + +#endif // QREDIS_REQUEST_P_H