Make redis host configurable
This commit is contained in:
25
main.cpp
25
main.cpp
@@ -30,7 +30,10 @@ int main(int argc, char *argv[])
|
||||
QHostAddress listenAddress = QHostAddress::Any;
|
||||
uint16_t port = 8000;
|
||||
QString identity = "test";
|
||||
#ifdef FEATURE_REDIS
|
||||
QString redisHost = "localhost";
|
||||
QString redisPassword;
|
||||
#endif
|
||||
|
||||
{
|
||||
QCommandLineParser parser;
|
||||
@@ -53,10 +56,17 @@ int main(int argc, char *argv[])
|
||||
QCoreApplication::translate("main", "identity")};
|
||||
parser.addOption(identityOption);
|
||||
|
||||
#ifdef FEATURE_REDIS
|
||||
QCommandLineOption redisHostOption{QStringList{ "H", "redisHost" },
|
||||
QCoreApplication::translate("main", "The redis host"),
|
||||
QCoreApplication::translate("main", "redisHost")};
|
||||
parser.addOption(redisHostOption);
|
||||
|
||||
QCommandLineOption redisPasswordOption{QStringList{ "r", "redisPassword" },
|
||||
QCoreApplication::translate("main", "The redis password"),
|
||||
QCoreApplication::translate("main", "redisPassword")};
|
||||
parser.addOption(redisPasswordOption);
|
||||
#endif
|
||||
|
||||
parser.process(app);
|
||||
|
||||
@@ -88,8 +98,12 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
if (parser.isSet(identityOption))
|
||||
identity = parser.value(identityOption);
|
||||
#ifdef FEATURE_REDIS
|
||||
if (parser.isSet(redisHostOption))
|
||||
redisHost = parser.value(redisHostOption);
|
||||
if (parser.isSet(redisPasswordOption))
|
||||
redisPassword = parser.value(redisPasswordOption);
|
||||
#endif
|
||||
}
|
||||
|
||||
qSetMessagePattern(QString{"%{time dd.MM.yyyy HH:mm:ss.zzz} %0 "
|
||||
@@ -104,7 +118,7 @@ int main(int argc, char *argv[])
|
||||
"%{message}"}.arg(identity));
|
||||
|
||||
#ifdef FEATURE_REDIS
|
||||
redisAsyncContext * const redis = redisAsyncConnect("localhost", 6379);
|
||||
redisAsyncContext * const redis = redisAsyncConnect(redisHost.toUtf8().constData(), 6379);
|
||||
|
||||
if (redis->err)
|
||||
qFatal("error with redis connection: %s", redis->errstr);
|
||||
@@ -112,10 +126,13 @@ int main(int argc, char *argv[])
|
||||
RedisQtAdapter redisAdapter;
|
||||
redisAdapter.setContext(redis);
|
||||
|
||||
qDebug() << "redis AUTH" << redisPassword;
|
||||
if (!redisPassword.isEmpty())
|
||||
{
|
||||
qDebug() << "redis AUTH" << redisPassword;
|
||||
|
||||
redisAsyncCommand(redis, NULL, NULL, "AUTH %s",
|
||||
redisPassword.toUtf8().constData());
|
||||
redisAsyncCommand(redis, NULL, NULL, "AUTH %s",
|
||||
redisPassword.toUtf8().constData());
|
||||
}
|
||||
|
||||
redisAsyncCommand(redis, NULL, NULL, "SET %s %s",
|
||||
QString{"traefik/http/services/proxyjs_%0/loadbalancer/servers/0/url"}.arg(identity).toUtf8().constData(),
|
||||
|
Reference in New Issue
Block a user