merge changes from 1.11.3

This commit is contained in:
Günter Obiltschnig 2022-07-03 16:09:29 +02:00
parent 06718f49c1
commit 9bde3bc634
2 changed files with 32 additions and 36 deletions

View File

@ -87,6 +87,11 @@ public:
Client(const Net::SocketAddress& addrs); Client(const Net::SocketAddress& addrs);
/// Constructor which connects to the given Redis host/port. /// Constructor which connects to the given Redis host/port.
Client(const Net::StreamSocket& socket);
/// Constructor which connects using an existing TCP
/// connection. This can be used to connect via TLS, if the
/// given socket is a Poco::Net::SecureStreamSocket.
virtual ~Client(); virtual ~Client();
/// Destroys the Client. /// Destroys the Client.
@ -113,18 +118,17 @@ public:
void connect(const Net::SocketAddress& addrs, const Timespan& timeout); void connect(const Net::SocketAddress& addrs, const Timespan& timeout);
/// Connects to the given Redis server. /// Connects to the given Redis server.
void connect(const Net::StreamSocket& socket);
/// Connects to the given Redis server using an existing TCP
/// connection. This can be used to connect via TLS, if the
/// given socket is a Poco::Net::SecureStreamSocket.
void disconnect(); void disconnect();
/// Disconnects from the Redis server. /// Disconnects from the Redis server.
bool isConnected() const; bool isConnected() const;
/// Returns true iff the Client is connected to a Redis server. /// 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> template<typename T>
T execute(const Array& command) T execute(const Array& command)
/// Sends the Redis Command to the server. It gets the reply /// Sends the Redis Command to the server. It gets the reply
@ -205,7 +209,6 @@ private:
Net::StreamSocket _socket; Net::StreamSocket _socket;
RedisInputStream* _input; RedisInputStream* _input;
RedisOutputStream* _output; RedisOutputStream* _output;
bool _authenticated = false;
}; };
@ -240,12 +243,6 @@ inline void Client::setReceiveTimeout(const Timespan& timeout)
} }
inline bool Client::isAuthenticated()
{
return _authenticated;
}
} } // namespace Poco::Redis } } // namespace Poco::Redis

View File

@ -61,6 +61,16 @@ Client::Client(const Net::SocketAddress& addrs):
} }
Client::Client(const Net::StreamSocket& socket):
_address(),
_socket(),
_input(0),
_output(0)
{
connect(socket);
}
Client::~Client() Client::~Client()
{ {
delete _input; delete _input;
@ -133,6 +143,18 @@ void Client::connect(const Net::SocketAddress& addrs, const Timespan& timeout)
} }
void Client::connect(const Poco::Net::StreamSocket& socket)
{
poco_assert(! _input);
poco_assert(! _output);
_address = socket.peerAddress();
_socket = socket;
_input = new RedisInputStream(_socket);
_output = new RedisOutputStream(_socket);
}
void Client::disconnect() void Client::disconnect()
{ {
delete _input; delete _input;
@ -151,29 +173,6 @@ 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) void Client::writeCommand(const Array& command, bool doFlush)
{ {
poco_assert(_output); poco_assert(_output);