mirror of
https://github.com/pocoproject/poco.git
synced 2025-03-04 07:27:23 +01:00
merge changes from 1.11.3
This commit is contained in:
parent
06718f49c1
commit
9bde3bc634
@ -87,6 +87,11 @@ public:
|
||||
Client(const Net::SocketAddress& addrs);
|
||||
/// 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();
|
||||
/// Destroys the Client.
|
||||
|
||||
@ -113,18 +118,17 @@ public:
|
||||
void connect(const Net::SocketAddress& addrs, const Timespan& timeout);
|
||||
/// 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();
|
||||
/// Disconnects from the Redis server.
|
||||
|
||||
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
|
||||
@ -205,7 +209,6 @@ private:
|
||||
Net::StreamSocket _socket;
|
||||
RedisInputStream* _input;
|
||||
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
|
||||
|
||||
|
||||
|
@ -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()
|
||||
{
|
||||
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()
|
||||
{
|
||||
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)
|
||||
{
|
||||
poco_assert(_output);
|
||||
|
Loading…
x
Reference in New Issue
Block a user