From 6e44f82d2a5840dcb3aed25c060e7605fc2e201d Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Fri, 15 Aug 2025 10:13:48 +0200 Subject: [PATCH] Make redis host configurable --- main.cpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/main.cpp b/main.cpp index 81a93d3..ad5cb8e 100644 --- a/main.cpp +++ b/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(),