Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Plugins/Redis/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ std::unique_ptr<cpp_redis::redis_client> Redis::PoolMakeFunc()

auto p = std::make_unique<cpp_redis::redis_client>();
(*p).connect(m_internal->m_config.m_host, static_cast<size_t>(m_internal->m_config.m_port));

// Pool ctor currently authenticates synchronously.
// Invalid passwords aren't handled at all - you'll have to watch the server logs for that.
if (!m_internal->m_config.m_password.empty())
{
(*p).auth(m_internal->m_config.m_password);
(*p).sync_commit();
}

return p;
}

Expand All @@ -30,6 +39,7 @@ void Redis::Reconfigure()
// Redis server.
m_internal->m_config.m_host = *Config::Get<std::string>("HOST");
m_internal->m_config.m_port = Config::Get<int>("PORT", 6379);
m_internal->m_config.m_password = Config::Get<std::string>("AUTH_PASSWORD", "");

// Pubsub.
m_internal->m_config.m_pubsub_script = Config::Get<std::string>("PUBSUB_SCRIPT", "on_pubsub");
Expand All @@ -53,6 +63,12 @@ void Redis::Reconfigure()
m_internal->m_connection_pubsub.connect(
m_internal->m_config.m_host, static_cast<size_t>(m_internal->m_config.m_port));

if (!m_internal->m_config.m_password.empty())
{
m_internal->m_connection_pubsub.auth(m_internal->m_config.m_password);
m_internal->m_connection_pubsub.commit();
}

auto bound = std::bind(&Redis::OnPubsub, this, _1, _2);
for (auto& ch : m_internal->m_config.m_pubsub_channels)
{
Expand Down
1 change: 1 addition & 0 deletions Plugins/Redis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,6 @@ if (NWNX_Redis_GetResultAsInt(NWNX_Redis_EXISTS("examples:examplekey")))
| ---------------------------- | :---------------------: | ---------------------------------- |
| `NWNX_REDIS_HOST` | string | (none) |
| `NWNX_REDIS_PORT` | int16 | 6379 |
| `NWNX_REDIS_AUTH_PASSWORD` | string | "" |
| `NWNX_REDIS_PUBSUB_SCRIPT` | string | on_pubsub |
| `NWNX_REDIS_PUBSUB_CHANNELS` | comma-separated strings | "" |
2 changes: 2 additions & 0 deletions Plugins/Redis/Redis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class Redis : public NWNXLib::Plugin
std::string m_host;
// PORT
int m_port;
// AUTH (no ACL support)
std::string m_password;

// TODO:
// Bridge the internal message bus to redis?
Expand Down