Added CommandPrivate class and updated the README with usage instructions.
This commit is contained in:
parent
e136754ec1
commit
b1f784205f
|
|
@ -28,7 +28,8 @@ include_directories(include)
|
||||||
|
|
||||||
# QRedis source files.
|
# QRedis source files.
|
||||||
set(QREDIS_SRC
|
set(QREDIS_SRC
|
||||||
src/client.cpp)
|
src/client.cpp
|
||||||
|
src/command.cpp)
|
||||||
|
|
||||||
# QRedis header files requiring MOC.
|
# QRedis header files requiring MOC.
|
||||||
qt5_wrap_cpp(QREDIS_MOC
|
qt5_wrap_cpp(QREDIS_MOC
|
||||||
|
|
|
||||||
13
README.md
13
README.md
|
|
@ -36,4 +36,15 @@ QRedis uses [CMake](http://www.cmake.org/) for building the client library, whic
|
||||||
|
|
||||||
### Usage
|
### 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.
|
||||||
|
|
@ -22,13 +22,13 @@ namespace QRedis
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Connects to a Redis server
|
* @brief Creates a Redis client
|
||||||
* @param parent the parent QObject
|
* @param parent the parent QObject
|
||||||
*/
|
*/
|
||||||
explicit Client(QObject * parent = nullptr);
|
explicit Client(QObject * parent = nullptr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Disconnects from the Redis server
|
* @brief Destroys the client
|
||||||
*/
|
*/
|
||||||
virtual ~Client();
|
virtual ~Client();
|
||||||
|
|
||||||
|
|
@ -49,9 +49,10 @@ namespace QRedis
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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 that may be used for obtaining the response
|
||||||
*/
|
*/
|
||||||
Command * sendCommand();
|
Command * sendCommand(const QString & command);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,40 @@
|
||||||
#ifndef QREDIS_COMMAND_H
|
#ifndef QREDIS_COMMAND_H
|
||||||
#define QREDIS_COMMAND_H
|
#define QREDIS_COMMAND_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QScopedPointer>
|
||||||
|
|
||||||
#include "qredis_export.h"
|
#include "qredis_export.h"
|
||||||
|
|
||||||
namespace QRedis
|
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:
|
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;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ void Client::disconnectFromHost()
|
||||||
d->socket.disconnectFromHost();
|
d->socket.disconnectFromHost();
|
||||||
}
|
}
|
||||||
|
|
||||||
Command * Client::sendCommand()
|
Command * Client::sendCommand(const QString & command)
|
||||||
{
|
{
|
||||||
return nullptr;
|
return new Command(this);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
#ifndef QREDIS_COMMAND_P_H
|
||||||
|
#define QREDIS_COMMAND_P_H
|
||||||
|
|
||||||
|
namespace QRedis
|
||||||
|
{
|
||||||
|
class CommandPrivate
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
//...
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // QREDIS_COMMAND_P_H
|
||||||
Loading…
Reference in New Issue