Make redis host configurable

This commit is contained in:
2025-08-15 10:13:48 +02:00
parent 22862a2795
commit 6e44f82d2a

View File

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