Added CommandPrivate class and updated the README with usage instructions.

This commit is contained in:
Nathan Osman 2013-06-29 23:16:59 -07:00
parent e136754ec1
commit b1f784205f
7 changed files with 74 additions and 9 deletions

View File

@ -28,7 +28,8 @@ include_directories(include)
# QRedis source files.
set(QREDIS_SRC
src/client.cpp)
src/client.cpp
src/command.cpp)
# QRedis header files requiring MOC.
qt5_wrap_cpp(QREDIS_MOC

View File

@ -36,4 +36,15 @@ QRedis uses [CMake](http://www.cmake.org/) for building the client library, whic
### Usage
[TODO]
In order to send commands to a Redis server, you need to create an instance of the `Client` class and connect to the server. For example, if Redis is running on the same server as your application, your code might look something like this:
#include <qredis/client.h>
QRedis::Client client;
client.connectToHost(QHostAddress::LocalHost);
Once the connection is complete, the client will emit the `connected()` signal. You can then begin executing commands. For example, to send the `PING` command:
QRedis::Command * command = client.sendCommand("PING");
The `sendCommand()` method returns a `Command *`, which provides signals to indicate when the command has completed or when an error occurs.

View File

@ -22,13 +22,13 @@ namespace QRedis
public:
/**
* @brief Connects to a Redis server
* @brief Creates a Redis client
* @param parent the parent QObject
*/
explicit Client(QObject * parent = nullptr);
/**
* @brief Disconnects from the Redis server
* @brief Destroys the client
*/
virtual ~Client();
@ -49,9 +49,10 @@ namespace QRedis
/**
* @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
*/
Command * sendCommand();
Command * sendCommand(const QString & command);
signals:

View File

@ -1,15 +1,40 @@
#ifndef QREDIS_COMMAND_H
#define QREDIS_COMMAND_H
#include <QObject>
#include <QScopedPointer>
#include "qredis_export.h"
namespace QRedis
{
class QREDIS_EXPORT Command
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;
};
}

View File

@ -24,7 +24,7 @@ void Client::disconnectFromHost()
d->socket.disconnectFromHost();
}
Command * Client::sendCommand()
Command * Client::sendCommand(const QString & command)
{
return nullptr;
return new Command(this);
}

13
src/command.cpp Normal file
View File

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

14
src/command_p.h Normal file
View File

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