Take the server-address in the format host[:port] instead of separatly.

This commit is contained in:
Christoph Heiss 2018-02-26 13:09:14 +01:00
parent 14c3d80861
commit cebc909cf1
3 changed files with 26 additions and 7 deletions

View file

@ -222,6 +222,16 @@ namespace resply {
*/
void close();
/*! \brief Retrieves the address of the server this client is connected to.
* \return The server address of the redis server.
*/
const std::string& host() const;
/*! \brief Retrieves the port of the server this client is connected to.
* \return The server port of the redis server.
*/
const std::string& port() const;
/*! \brief Creates a new pipelined client using this client.
* \return A pipelined client.
*/

View file

@ -158,6 +158,16 @@ public:
return channel_callbacks_;
}
const std::string& host() const
{
return host_;
}
const std::string& port() const
{
return port_;
}
private:
Result receive_response()
{
@ -227,6 +237,8 @@ Client::~Client() { }
void Client::connect() { impl_->connect(); }
void Client::close() { impl_->close(); }
const std::string& Client::host() const { return impl_->host(); }
const std::string& Client::port() const { return impl_->port(); }
bool Client::in_subscribed_mode() const
{

View file

@ -17,10 +17,9 @@
struct Options {
Options() : host{"localhost"}, port{"6379"}, show_version{} { }
Options() : host{"localhost:6379"}, show_version{} { }
std::string host;
std::string port;
bool show_version;
};
@ -32,9 +31,7 @@ static Options parse_commandline(int argc, char** argv)
auto cli = (
clipp::option("-h", "--host").set(options.host)
.doc("Set the host to connect to [default: localhost]"),
clipp::option("-p", "--port").set(options.port)
.doc("Set the port to connect to [default: 6379]"),
.doc("Set the host (and port, optional) to connect to [default: localhost:6379]"),
clipp::option("--help").set(show_help).doc("Show help and exit."),
clipp::option("--version").set(options.show_version).doc("Show version and exit.")
);
@ -69,11 +66,11 @@ int main(int argc, char* argv[])
{
auto options{parse_commandline(argc, argv)};
resply::Client client{options.host, options.port};
resply::Client client{options.host};
client.connect();
while (std::cin) {
std::cout << options.host << ':' << options.port << "> ";
std::cout << client.host() << ':' << client.port() << "> ";
std::string line;
std::getline(std::cin, line);