redis-plus-plus
redis-plus-plus copied to clipboard
@ about URI
I read about connection API, it support like "tcp://[passwd@]host[:port]" but if passwd contain "@" , it's error?
i find the code
auto ConnectionOptions::_split_uri(const std::string &uri) const
-> std::tuple<std::string, std::string, std::string> {
auto pos = uri.find("://");
if (pos == std::string::npos) {
throw Error("invalid URI: no scheme");
}
auto type = uri.substr(0, pos);
auto start = pos + 3;
pos = uri.find("@", start);
if (pos == std::string::npos) {
// No auth info.
return std::make_tuple(type, std::string{}, uri.substr(start));
}
auto auth = uri.substr(start, pos - start);
return std::make_tuple(type, auth, uri.substr(pos + 1));
}
if i want to connect a tcp://david@[email protected]:6379 , it is error
one solution it is use auth ?
after connetion, auth is ok. and i think if parse from back to front, is it perfect solution?
Yes, so far, the URI does not support password with @. In this case, you need to use ConnectionOption
to construct a Redis
object:
ConnectionOptions opts;
opts.host = "xxx";
opts.port = 6379;
opts.password = "david@james";
auto redis = Redis(opts);
after connetion, auth is ok.
This is not a reliable solution. Because if the connection is broken for some reason, redis-plus-plus will automatically try to reconnect to server. In this case, since it won't send auth command automatically, it will fail to send other command to Redis.
if parse from back to front, is it perfect solution?
What's if there's a @ in the host part? It will break your suggestion.
So far, the best solution is to construct Redis
object with ConnectionOptions
. Sorry for the inconvenience.
Regards