2013-06-30 02:34:10 +08:00
|
|
|
#ifndef QREDIS_CLIENT_H
|
|
|
|
|
#define QREDIS_CLIENT_H
|
|
|
|
|
|
|
|
|
|
#include <QObject>
|
2013-06-30 03:04:01 +08:00
|
|
|
#include <QScopedPointer>
|
2013-06-30 02:34:10 +08:00
|
|
|
|
2013-07-02 00:00:58 +08:00
|
|
|
#include <qredis/request.h>
|
2013-06-30 02:34:10 +08:00
|
|
|
#include "qredis_export.h"
|
|
|
|
|
|
|
|
|
|
namespace QRedis
|
|
|
|
|
{
|
2013-06-30 03:04:01 +08:00
|
|
|
class QREDIS_EXPORT ClientPrivate;
|
|
|
|
|
|
|
|
|
|
/**
|
2013-06-30 03:34:22 +08:00
|
|
|
* @brief Provides access to a Redis server
|
2013-06-30 03:04:01 +08:00
|
|
|
*/
|
2013-06-30 02:34:10 +08:00
|
|
|
class QREDIS_EXPORT Client : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
2013-06-30 03:04:01 +08:00
|
|
|
/**
|
2013-06-30 14:16:59 +08:00
|
|
|
* @brief Creates a Redis client
|
2013-06-30 03:42:39 +08:00
|
|
|
* @param parent the parent QObject
|
2013-06-30 03:04:01 +08:00
|
|
|
*/
|
2013-07-03 06:26:19 +08:00
|
|
|
explicit Client(QObject * parent = 0);
|
2013-06-30 03:04:01 +08:00
|
|
|
|
|
|
|
|
/**
|
2013-06-30 14:16:59 +08:00
|
|
|
* @brief Destroys the client
|
2013-06-30 03:04:01 +08:00
|
|
|
*/
|
2013-06-30 02:34:10 +08:00
|
|
|
virtual ~Client();
|
2013-06-30 03:04:01 +08:00
|
|
|
|
2013-07-03 06:26:19 +08:00
|
|
|
/*
|
|
|
|
|
* Note: we specifically avoid an overload of connectToHost that
|
|
|
|
|
* uses QHostAddress since that would force anyone using the client
|
|
|
|
|
* library to use the QtNetwork module, which we wish to avoid.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-06-30 03:34:22 +08:00
|
|
|
/**
|
|
|
|
|
* @brief Attempts to connect to the specified Redis server
|
2013-07-02 12:45:04 +08:00
|
|
|
* @param hostName the hostname of the Redis server
|
2013-06-30 03:34:22 +08:00
|
|
|
* @param port the port that the Redis server is listening on
|
|
|
|
|
*
|
|
|
|
|
* If the connection was successful, the connected() signal will be
|
|
|
|
|
* emitted.
|
|
|
|
|
*/
|
2013-07-02 12:45:04 +08:00
|
|
|
void connectToHost(const QString & hostName, quint16 port = 6379);
|
2013-06-30 03:34:22 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Disconnects from the Redis server
|
|
|
|
|
*/
|
2013-06-30 03:04:01 +08:00
|
|
|
void disconnectFromHost();
|
|
|
|
|
|
2013-07-02 12:51:48 +08:00
|
|
|
/**
|
|
|
|
|
* @brief Indicates whether the client is connected to a Redis server
|
|
|
|
|
* @return true if the client is connected
|
|
|
|
|
*/
|
|
|
|
|
bool isConnected() const;
|
|
|
|
|
|
2013-06-30 03:34:22 +08:00
|
|
|
/**
|
2013-07-02 00:00:58 +08:00
|
|
|
* @brief Sends the specified command to the Redis server
|
2013-06-30 14:16:59 +08:00
|
|
|
* @param command the command to execute
|
2013-07-02 00:00:58 +08:00
|
|
|
* @return an object representing the request
|
2013-06-30 03:34:22 +08:00
|
|
|
*/
|
2013-07-05 05:14:53 +08:00
|
|
|
Request * sendCommand(const QByteArray & command);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Attempts to set the specified key to the specified value
|
|
|
|
|
* @param name the name of the key
|
|
|
|
|
* @param value the value of the key
|
|
|
|
|
* @return the request issued
|
|
|
|
|
*/
|
|
|
|
|
Request * set(const QByteArray & name, const QByteArray & value);
|
2013-06-30 03:04:01 +08:00
|
|
|
|
2013-07-02 12:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* @brief Waits for the socket to finish connecting
|
|
|
|
|
* @param msecs the amount of time in milliseconds to wait
|
|
|
|
|
* @return true if the connection was completed
|
|
|
|
|
*
|
|
|
|
|
* Note: to wait indefinitely, pass a value of -1.
|
|
|
|
|
*/
|
|
|
|
|
bool waitForConnected(int msecs = 30000);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Waits for the socket to finish disconnecting
|
|
|
|
|
* @param msecs the amount of time in milliseconds to wait
|
|
|
|
|
* @return true if the disconnection was completed
|
|
|
|
|
*/
|
|
|
|
|
bool waitForDisconnected(int msecs = 30000);
|
|
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
2013-06-30 03:04:01 +08:00
|
|
|
|
2013-06-30 03:34:22 +08:00
|
|
|
/**
|
|
|
|
|
* @brief Emitted when the client establishes a connection with the Redis server
|
|
|
|
|
*/
|
2013-06-30 03:04:01 +08:00
|
|
|
void connected();
|
|
|
|
|
|
2013-06-30 03:34:22 +08:00
|
|
|
/**
|
|
|
|
|
* @brief Emitted when the client disconnects from the Redis server
|
|
|
|
|
*/
|
|
|
|
|
void disconnected();
|
|
|
|
|
|
2013-06-30 03:04:01 +08:00
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
const QScopedPointer<ClientPrivate> d;
|
2013-06-30 02:34:10 +08:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-30 03:04:01 +08:00
|
|
|
#endif // QREDIS_CLIENT_H
|