mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-13 10:32:57 +01:00
fix(Redis): Poco::Redis after executing auth command next command always return OK #2457
This commit is contained in:
parent
ae00f1c8eb
commit
5ef96287ee
@ -119,6 +119,12 @@ public:
|
||||
bool isConnected() const;
|
||||
/// Returns true iff the Client is connected to a Redis server.
|
||||
|
||||
bool sendAuth(const std::string& password);
|
||||
/// Sends password to Redis server
|
||||
|
||||
bool isAuthenticated();
|
||||
/// Returns true when the client is authenticated
|
||||
|
||||
template<typename T>
|
||||
T execute(const Array& command)
|
||||
/// Sends the Redis Command to the server. It gets the reply
|
||||
@ -199,6 +205,7 @@ private:
|
||||
Net::StreamSocket _socket;
|
||||
RedisInputStream* _input;
|
||||
RedisOutputStream* _output;
|
||||
bool _authenticated = false;
|
||||
};
|
||||
|
||||
|
||||
@ -233,6 +240,12 @@ inline void Client::setReceiveTimeout(const Timespan& timeout)
|
||||
}
|
||||
|
||||
|
||||
inline bool Client::isAuthenticated()
|
||||
{
|
||||
return _authenticated;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Redis
|
||||
|
||||
|
||||
|
@ -151,6 +151,29 @@ bool Client::isConnected() const
|
||||
}
|
||||
|
||||
|
||||
bool Client::sendAuth(const std::string& password)
|
||||
{
|
||||
Array cmd;
|
||||
cmd << "AUTH" << password;
|
||||
|
||||
bool ret = true;
|
||||
std::string response;
|
||||
|
||||
try
|
||||
{
|
||||
response = execute<std::string>(cmd);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
ret = false;
|
||||
}
|
||||
|
||||
_authenticated = (ret && (response == "OK"));
|
||||
|
||||
return _authenticated;
|
||||
}
|
||||
|
||||
|
||||
void Client::writeCommand(const Array& command, bool doFlush)
|
||||
{
|
||||
poco_assert(_output);
|
||||
|
@ -287,7 +287,7 @@ void RedisTest::testDECR()
|
||||
|
||||
try
|
||||
{
|
||||
Poco::Int64 result = _redis.execute<Poco::Int64>(decr);
|
||||
_redis.execute<Poco::Int64>(decr);
|
||||
fail("This must fail");
|
||||
}
|
||||
catch (RedisException& e)
|
||||
|
Loading…
Reference in New Issue
Block a user