diff --git a/README.md b/README.md index 6ba811d..dfd5d4f 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,15 @@ QRedis provides a modern Qt client library for communicating with a [Redis server](http://redis.io/). The code uses many new constructs introduced in [C++11](https://en.wikipedia.org/wiki/C%2B%2B11) and compiles exclusively with Qt 5, ensuring years of compatibility down the road. +### Requirements + +To compile QRedis, the following requirements must be met: + +* GCC 4.6+ or Microsoft Visual C++ 2010+ +* Qt 5+ + +*It is not necessary to have Redis installed in order to build the client library. However, you will be unable to run the test suite.* + ### Building QRedis QRedis uses [CMake](http://www.cmake.org/) for building the client library, which simplifies the necessary steps across all supported platforms. Assuming you have Qt 5 installed in a location that CMake can find, the client library can be built with the following steps: diff --git a/include/qredis/client.h b/include/qredis/client.h index f6296a2..8935137 100644 --- a/include/qredis/client.h +++ b/include/qredis/client.h @@ -1,6 +1,7 @@ #ifndef QREDIS_CLIENT_H #define QREDIS_CLIENT_H +#include #include #include @@ -12,7 +13,7 @@ namespace QRedis class QREDIS_EXPORT ClientPrivate; /** - * @brief Provides access to a Redis server. + * @brief Provides access to a Redis server */ class QREDIS_EXPORT Client : public QObject { @@ -21,24 +22,48 @@ namespace QRedis public: /** - * @brief Connects to a Redis server. + * @brief Connects to a Redis server */ Client(); /** - * @brief Disconnects from the Redis server. + * @brief Disconnects from the Redis server */ virtual ~Client(); - void connectToHost(); + /** + * @brief Attempts to connect to the specified Redis server + * @param address the address of the Redis server + * @param port the port that the Redis server is listening on + * + * If the connection was successful, the connected() signal will be + * emitted. + */ + void connectToHost(const QHostAddress & address, quint16 port = 6379); + + /** + * @brief Disconnects from the Redis server + */ void disconnectFromHost(); + /** + * @brief Sends the specified command to the Redis server. + * @return an object that may be used for obtaining the response + */ Command * sendCommand(); signals: + /** + * @brief Emitted when the client establishes a connection with the Redis server + */ void connected(); + /** + * @brief Emitted when the client disconnects from the Redis server + */ + void disconnected(); + private: const QScopedPointer d; diff --git a/src/client.cpp b/src/client.cpp index 1bb96e1..566295e 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -6,16 +6,25 @@ using namespace QRedis; Client::Client() : d(new ClientPrivate) { + connect(d->socket, &QTcpSocket::connected, this, &Client::connected); + connect(d->socket, &QTcpSocket::disconnected, this, &Client::disconnected); } Client::~Client() { } -void Client::connectToHost() +void Client::connectToHost(const QHostAddress & address, quint16 port) { + d->socket.connectToHost(address, port); } void Client::disconnectFromHost() { + d->socket.disconnectFromHost(); +} + +Command * Client::sendCommand() +{ + return nullptr; }