mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-14 02:57:45 +01:00
added new commands; fixed handling of broken connections
This commit is contained in:
parent
2e26da9b34
commit
196540ce34
@ -133,7 +133,7 @@ public:
|
|||||||
/// Array and void. When the reply is an Error, it will throw
|
/// Array and void. When the reply is an Error, it will throw
|
||||||
/// a RedisException.
|
/// a RedisException.
|
||||||
{
|
{
|
||||||
T result;
|
T result = T();
|
||||||
writeCommand(command, true);
|
writeCommand(command, true);
|
||||||
readReply(result);
|
readReply(result);
|
||||||
return result;
|
return result;
|
||||||
|
@ -84,6 +84,9 @@ public:
|
|||||||
static Command get(const std::string& key);
|
static Command get(const std::string& key);
|
||||||
/// Creates and returns an GET command.
|
/// 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);
|
static Command hdel(const std::string& hash, const std::string& field);
|
||||||
/// Creates and returns an HDEL command.
|
/// Creates and returns an HDEL command.
|
||||||
|
|
||||||
@ -253,8 +256,20 @@ public:
|
|||||||
static Command rpush(const std::string& list, const StringVec& value, bool create = true);
|
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.
|
/// 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();
|
static Command ping();
|
||||||
/// Creates and returns a PING command.
|
/// 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.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ void Client::connect()
|
|||||||
poco_assert(! _input);
|
poco_assert(! _input);
|
||||||
poco_assert(! _output);
|
poco_assert(! _output);
|
||||||
|
|
||||||
_socket.connect(_address);
|
_socket = Net::StreamSocket(_address);
|
||||||
_input = new RedisInputStream(_socket);
|
_input = new RedisInputStream(_socket);
|
||||||
_output = new RedisOutputStream(_socket);
|
_output = new RedisOutputStream(_socket);
|
||||||
}
|
}
|
||||||
@ -105,6 +105,7 @@ void Client::connect(const Timespan& timeout)
|
|||||||
poco_assert(! _input);
|
poco_assert(! _input);
|
||||||
poco_assert(! _output);
|
poco_assert(! _output);
|
||||||
|
|
||||||
|
_socket = Net::StreamSocket();
|
||||||
_socket.connect(_address, timeout);
|
_socket.connect(_address, timeout);
|
||||||
_input = new RedisInputStream(_socket);
|
_input = new RedisInputStream(_socket);
|
||||||
_output = new RedisOutputStream(_socket);
|
_output = new RedisOutputStream(_socket);
|
||||||
@ -166,6 +167,11 @@ RedisType::Ptr Client::readReply()
|
|||||||
poco_assert(_input);
|
poco_assert(_input);
|
||||||
|
|
||||||
int c = _input->get();
|
int c = _input->get();
|
||||||
|
if (c == -1)
|
||||||
|
{
|
||||||
|
disconnect();
|
||||||
|
throw RedisException("Lost connection to Redis server");
|
||||||
|
}
|
||||||
RedisType::Ptr result = RedisType::createRedisType(c);
|
RedisType::Ptr result = RedisType::createRedisType(c);
|
||||||
if (result.isNull())
|
if (result.isNull())
|
||||||
{
|
{
|
||||||
|
@ -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 Command::hdel(const std::string& hash, const std::string& field)
|
||||||
{
|
{
|
||||||
Command cmd("HDEL");
|
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 Command::ping()
|
||||||
{
|
{
|
||||||
Command cmd("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
|
} } // namespace Poco::Redis
|
||||||
|
Loading…
Reference in New Issue
Block a user