diff --git a/cpp_redis b/cpp_redis index db49c94..9f12aeb 160000 --- a/cpp_redis +++ b/cpp_redis @@ -1 +1 @@ -Subproject commit db49c94475109dceac14ff38d1f97fb39d602e3c +Subproject commit 9f12aeb012838d83fdacb12ba2a1485f67be3d56 diff --git a/module/Module.h b/module/Module.h index 144763c..bc8d516 100644 --- a/module/Module.h +++ b/module/Module.h @@ -23,9 +23,9 @@ class Module inline void RemoveLuaVM(lua_State* luaVM) { _luaStates.erase(luaVM); } inline bool HasLuaVM(lua_State* luaVM) { return _luaStates.find(luaVM) != _luaStates.end(); } - inline void AddRedisClient(redis_client* client) { _redisClients.insert(client); } - inline void RemoveRedisClient(redis_client* client) { _redisClients.erase(client); } - inline bool HasRedisClient(redis_client* client) { return _redisClients.find(client) != _redisClients.end(); } + inline void AddRedisClient(ml_redis::redis_client* client) { _redisClients.insert(client); } + inline void RemoveRedisClient(ml_redis::redis_client* client) { _redisClients.erase(client); } + inline bool HasRedisClient(ml_redis::redis_client* client) { return _redisClients.find(client) != _redisClients.end(); } inline JobManager>& GetJobManager() { return _jobManager; } @@ -35,7 +35,7 @@ class Module ILuaModuleManager* _moduleManager; JobManager> _jobManager; std::unordered_set _luaStates; - std::unordered_set _redisClients; + std::unordered_set _redisClients; }; extern Module* g_Module; diff --git a/module/RedisClient.cpp b/module/RedisClient.cpp index f5394a0..2a768f4 100644 --- a/module/RedisClient.cpp +++ b/module/RedisClient.cpp @@ -1,112 +1,115 @@ #include "RedisClient.h" #include "Module.h" -redis_client::redis_client() +namespace ml_redis { - _client = new cpp_redis::client(); - _subscriber = new cpp_redis::subscriber(); + redis_client::redis_client() + { + _client = new cpp_redis::client(); + _subscriber = new cpp_redis::subscriber(); - g_Module->AddRedisClient(this); -} + g_Module->AddRedisClient(this); + } -redis_client::~redis_client() -{ - g_Module->RemoveRedisClient(this); + redis_client::~redis_client() + { + g_Module->RemoveRedisClient(this); - delete _client; - delete _subscriber; -} + delete _client; + delete _subscriber; + } -void redis_client::authenticate(const std::string& password, const cpp_redis::client::reply_callback_t& client_callback, - const cpp_redis::client::reply_callback_t& subscriber_callback) const -{ - _client->auth(password, client_callback); - _subscriber->auth(password, subscriber_callback); + void redis_client::authenticate(const std::string& password, const cpp_redis::client::reply_callback_t& client_callback, + const cpp_redis::client::reply_callback_t& subscriber_callback) const + { + _client->auth(password, client_callback); + _subscriber->auth(password, subscriber_callback); - _client->commit(); - _subscriber->commit(); -} + _client->commit(); + _subscriber->commit(); + } -cpp_redis::reply redis_client::set(const std::string& key, const std::string& value) const -{ - auto result = _client->set(key, value); - _client->commit(); + cpp_redis::reply redis_client::set(const std::string& key, const std::string& value) const + { + auto result = _client->set(key, value); + _client->commit(); - result.wait(); - return result.get(); -} + result.wait(); + return result.get(); + } -void redis_client::set(const std::map& pairs, const std::function& callback) const -{ - for(auto& [key, value] : pairs) + void redis_client::set(const std::map& pairs, const std::function& callback) const { - _client->set(key, value, [key, callback](cpp_redis::reply& reply) + for(auto& [key, value] : pairs) { - callback(key, reply); - }); + _client->set(key, value, [key, callback](cpp_redis::reply& reply) + { + callback(key, reply); + }); + } + _client->commit(); } - _client->commit(); -} -cpp_redis::reply redis_client::get(const std::string& key) const -{ - auto result = _client->get(key); - _client->commit(); + cpp_redis::reply redis_client::get(const std::string& key) const + { + auto result = _client->get(key); + _client->commit(); - result.wait(); - return result.get(); -} + result.wait(); + return result.get(); + } -void redis_client::get(const std::list& keys, const std::function& callback) const -{ - for (auto& key : keys) + void redis_client::get(const std::list& keys, const std::function& callback) const { - _client->get(key, [key, callback](cpp_redis::reply& reply) + for (auto& key : keys) { - callback(key, reply); - }); + _client->get(key, [key, callback](cpp_redis::reply& reply) + { + callback(key, reply); + }); + } + _client->commit(); } - _client->commit(); -} -void redis_client::subscribe(const std::list& channels, - const cpp_redis::subscriber::subscribe_callback_t& callback) const -{ - for (auto& channel : channels) + void redis_client::subscribe(const std::list& channels, + const cpp_redis::subscriber::subscribe_callback_t& callback) const { - _subscriber->subscribe(channel, callback); - } + for (auto& channel : channels) + { + _subscriber->subscribe(channel, callback); + } - _subscriber->commit(); -} + _subscriber->commit(); + } -void redis_client::unsubscribe(const std::list& channels) const -{ - for (auto& channel : channels) + void redis_client::unsubscribe(const std::list& channels) const { - _subscriber->unsubscribe(channel); + for (auto& channel : channels) + { + _subscriber->unsubscribe(channel); + } + _subscriber->commit(); } - _subscriber->commit(); -} -cpp_redis::reply redis_client::publish(const std::string& channel, const std::string& message) const -{ - auto result = _client->publish(channel, message); - _client->commit(); + cpp_redis::reply redis_client::publish(const std::string& channel, const std::string& message) const + { + auto result = _client->publish(channel, message); + _client->commit(); - result.wait(); - return result.get(); -} + result.wait(); + return result.get(); + } -void redis_client::publish(const std::map& pairs, - const std::function& callback) const -{ - for (auto& [channel, message] : pairs) + void redis_client::publish(const std::map& pairs, + const std::function& callback) const { - _client->publish(channel, message, [channel, callback](cpp_redis::reply& reply) + for (auto& [channel, message] : pairs) { - callback(channel, reply); - }); + _client->publish(channel, message, [channel, callback](cpp_redis::reply& reply) + { + callback(channel, reply); + }); + } + _client->commit(); } - _client->commit(); } diff --git a/module/premake5.lua b/module/premake5.lua index f42b066..f7484ae 100644 --- a/module/premake5.lua +++ b/module/premake5.lua @@ -7,6 +7,9 @@ project "module" includedirs { "include" } libdirs { "lib" } + dependson { "cpp_redis" } + links { "cpp_redis" } + vpaths { ["Headers/*"] = "**.h", ["Sources/*"] = "**.cpp", @@ -23,20 +26,12 @@ project "module" debugdir "../mta-server" filter { "system:windows", "platforms:x86" } - links { "lua5.1.lib" } - links { "tacopie.lib" } - links { "cpp_redis.lib" } debugcommand "../mta-server/MTA Server.exe" filter { "system:windows", "platforms:x64" } - links { "lua5.1_64.lib" } - links { "tacopie_64.lib" } - links { "cpp_redis_64.lib" } debugcommand "../mta-server/MTA Server64.exe" - filter "system:linux" - links { "tacopie" } - links { "cpp_redis" } + -- filter "system:linux" filter "system:not linux" excludes { "luaimports/luaimports.linux.h", "luaimports/luaimports.linux.cpp" } diff --git a/premake5.lua b/premake5.lua index 97a06c3..bafb914 100644 --- a/premake5.lua +++ b/premake5.lua @@ -20,4 +20,5 @@ solution "Redis" optimize "On" include "module" + include "cpp_redis/cpp_redis" --include "test"