Renamed Command class to Request to better reflect its actual role.

This commit is contained in:
Nathan Osman 2013-07-01 09:00:58 -07:00
parent b1f784205f
commit 4104a591e3
10 changed files with 114 additions and 76 deletions

View File

@ -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

View File

@ -5,7 +5,7 @@
#include <QObject>
#include <QScopedPointer>
#include <qredis/command.h>
#include <qredis/request.h>
#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:

View File

@ -1,41 +0,0 @@
#ifndef QREDIS_COMMAND_H
#define QREDIS_COMMAND_H
#include <QObject>
#include <QScopedPointer>
#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<CommandPrivate> d;
};
}
#endif // QREDIS_COMMAND_H

73
include/qredis/request.h Normal file
View File

@ -0,0 +1,73 @@
#ifndef QREDIS_REQUEST_H
#define QREDIS_REQUEST_H
#include <QObject>
#include <QScopedPointer>
#include <QVariant>
#include <QVariantList>
#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<RequestPrivate> d;
};
}
#endif // QREDIS_REQUEST_H

View File

@ -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);
}

View File

@ -1,8 +1,11 @@
#ifndef QREDIS_CLIENT_P_H
#define QREDIS_CLIENT_P_H
#include <QQueue>
#include <QTcpSocket>
#include <qredis/request.h>
namespace QRedis
{
class ClientPrivate
@ -10,6 +13,7 @@ namespace QRedis
public:
QTcpSocket socket;
QQueue<Request *> queue;
};
}

View File

@ -1,13 +0,0 @@
#include <qredis/command.h>
#include "command_p.h"
using namespace QRedis;
Command::Command(QObject * parent)
: QObject(parent), d(new CommandPrivate)
{
}
Command::~Command()
{
}

View File

@ -1,14 +0,0 @@
#ifndef QREDIS_COMMAND_P_H
#define QREDIS_COMMAND_P_H
namespace QRedis
{
class CommandPrivate
{
public:
//...
};
}
#endif // QREDIS_COMMAND_P_H

13
src/request.cpp Normal file
View File

@ -0,0 +1,13 @@
#include <qredis/request.h>
#include "request_p.h"
using namespace QRedis;
Request::Request(QObject * parent)
: QObject(parent), d(new RequestPrivate)
{
}
Request::~Request()
{
}

14
src/request_p.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef QREDIS_REQUEST_P_H
#define QREDIS_REQUEST_P_H
namespace QRedis
{
class RequestPrivate
{
public:
//...
};
}
#endif // QREDIS_REQUEST_P_H