diff --git a/Redis/include/Poco/Redis/Client.h b/Redis/include/Poco/Redis/Client.h index d09f68287..6b204ae6c 100644 --- a/Redis/include/Poco/Redis/Client.h +++ b/Redis/include/Poco/Redis/Client.h @@ -133,7 +133,7 @@ public: /// Array and void. When the reply is an Error, it will throw /// a RedisException. { - T result; + T result = T(); writeCommand(command, true); readReply(result); return result; diff --git a/Redis/include/Poco/Redis/Command.h b/Redis/include/Poco/Redis/Command.h index d45ffcae2..627441c65 100644 --- a/Redis/include/Poco/Redis/Command.h +++ b/Redis/include/Poco/Redis/Command.h @@ -84,6 +84,9 @@ public: static Command get(const std::string& key); /// Creates and returns an GET command. + static Command exists(const std::string& key); + /// Creates and returns an EXISTS command. + static Command hdel(const std::string& hash, const std::string& field); /// Creates and returns an HDEL command. @@ -253,8 +256,20 @@ 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 expire(const std::string& key, Int64 seconds); + /// Creates and returns an EXPIRE command. + static Command ping(); /// Creates and returns a PING command. + + static Command multi(); + /// Creates and returns a MULTI command. + + static Command exec(); + /// Creates and returns a EXEC command. + + static Command discard(); + /// Creates and returns a DISCARD command. }; diff --git a/Redis/src/Client.cpp b/Redis/src/Client.cpp index 6375485a8..6d28f6a29 100644 --- a/Redis/src/Client.cpp +++ b/Redis/src/Client.cpp @@ -73,7 +73,7 @@ void Client::connect() poco_assert(! _input); poco_assert(! _output); - _socket.connect(_address); + _socket = Net::StreamSocket(_address); _input = new RedisInputStream(_socket); _output = new RedisOutputStream(_socket); } @@ -105,6 +105,7 @@ void Client::connect(const Timespan& timeout) poco_assert(! _input); poco_assert(! _output); + _socket = Net::StreamSocket(); _socket.connect(_address, timeout); _input = new RedisInputStream(_socket); _output = new RedisOutputStream(_socket); @@ -166,6 +167,11 @@ RedisType::Ptr Client::readReply() poco_assert(_input); int c = _input->get(); + if (c == -1) + { + disconnect(); + throw RedisException("Lost connection to Redis server"); + } RedisType::Ptr result = RedisType::createRedisType(c); if (result.isNull()) { diff --git a/Redis/src/Command.cpp b/Redis/src/Command.cpp index 404ee894f..0c2de1e17 100644 --- a/Redis/src/Command.cpp +++ b/Redis/src/Command.cpp @@ -119,6 +119,16 @@ Command Command::get(const std::string& key) } +Command Command::exists(const std::string& key) +{ + Command cmd("EXISTS"); + + cmd << key; + + return cmd; +} + + Command Command::hdel(const std::string& hash, const std::string& field) { Command cmd("HDEL"); @@ -683,6 +693,16 @@ Command Command::rpush(const std::string& list, const StringVec& values, bool cr } +Command Command::expire(const std::string& key, Int64 seconds) +{ + Command cmd("EXPIRE"); + + cmd << key << NumberFormatter::format(seconds); + + return cmd; +} + + Command Command::ping() { Command cmd("PING"); @@ -691,4 +711,28 @@ Command Command::ping() } +Command Command::multi() +{ + Command cmd("MULTI"); + + return cmd; +} + + +Command Command::exec() +{ + Command cmd("EXEC"); + + return cmd; +} + + +Command Command::discard() +{ + Command cmd("DISCARD"); + + return cmd; +} + + } } // namespace Poco::Redis