diff --git a/Redis/include/Poco/Redis/Client.h b/Redis/include/Poco/Redis/Client.h index bd69b74c6..d09f68287 100644 --- a/Redis/include/Poco/Redis/Client.h +++ b/Redis/include/Poco/Redis/Client.h @@ -116,6 +116,9 @@ public: void disconnect(); /// Disconnects from the Redis server. + bool isConnected() const; + /// Returns true iff the Client is connected to a Redis server. + template T execute(const Array& command) /// Sends the Redis Command to the server. It gets the reply diff --git a/Redis/include/Poco/Redis/Command.h b/Redis/include/Poco/Redis/Command.h index 63498b4a1..d45ffcae2 100644 --- a/Redis/include/Poco/Redis/Command.h +++ b/Redis/include/Poco/Redis/Command.h @@ -252,6 +252,9 @@ public: static Command rpush(const std::string& list, const StringVec& value, bool create = true); /// Creates and returns a RPUSH or RPUSHX (when create is false) command. + + static Command ping(); + /// Creates and returns a PING command. }; diff --git a/Redis/src/Client.cpp b/Redis/src/Client.cpp index 914801085..6375485a8 100644 --- a/Redis/src/Client.cpp +++ b/Redis/src/Client.cpp @@ -22,39 +22,39 @@ namespace Poco { namespace Redis { -Client::Client(): - _address(), - _socket(), - _input(0), +Client::Client(): + _address(), + _socket(), + _input(0), _output(0) { } Client::Client(const std::string& hostAndPort): - _address(hostAndPort), - _socket(), - _input(0), + _address(hostAndPort), + _socket(), + _input(0), _output(0) { connect(); } -Client::Client(const std::string& host, int port): - _address(host, port), - _socket(), - _input(0), +Client::Client(const std::string& host, int port): + _address(host, port), + _socket(), + _input(0), _output(0) { connect(); } -Client::Client(const Net::SocketAddress& addrs): - _address(addrs), - _socket(), - _input(0), +Client::Client(const Net::SocketAddress& addrs): + _address(addrs), + _socket(), + _input(0), _output(0) { connect(); @@ -144,6 +144,12 @@ void Client::disconnect() } +bool Client::isConnected() const +{ + return _input != 0; +} + + void Client::writeCommand(const Array& command, bool doFlush) { poco_assert(_output); diff --git a/Redis/src/Command.cpp b/Redis/src/Command.cpp index 3c33ba245..404ee894f 100644 --- a/Redis/src/Command.cpp +++ b/Redis/src/Command.cpp @@ -683,4 +683,12 @@ Command Command::rpush(const std::string& list, const StringVec& values, bool cr } +Command Command::ping() +{ + Command cmd("PING"); + + return cmd; +} + + } } // namespace Poco::Redis