-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Stefan Kürzeder
committed
Sep 11, 2019
1 parent
91e50ae
commit c2fe822
Showing
5 changed files
with
91 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<std::string, std::string>& pairs, const std::function<void(const std::string&, cpp_redis::reply&)>& callback) const | ||
{ | ||
for(auto& [key, value] : pairs) | ||
void redis_client::set(const std::map<std::string, std::string>& pairs, const std::function<void(const std::string&, cpp_redis::reply&)>& 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<std::string>& keys, const std::function<void(const std::string&, cpp_redis::reply &)>& callback) const | ||
{ | ||
for (auto& key : keys) | ||
void redis_client::get(const std::list<std::string>& keys, const std::function<void(const std::string&, cpp_redis::reply &)>& 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<std::string>& channels, | ||
const cpp_redis::subscriber::subscribe_callback_t& callback) const | ||
{ | ||
for (auto& channel : channels) | ||
void redis_client::subscribe(const std::list<std::string>& 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<std::string>& channels) const | ||
{ | ||
for (auto& channel : channels) | ||
void redis_client::unsubscribe(const std::list<std::string>& 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<std::string, std::string>& pairs, | ||
const std::function<void(const std::string&, cpp_redis::reply&)>& callback) const | ||
{ | ||
for (auto& [channel, message] : pairs) | ||
void redis_client::publish(const std::map<std::string, std::string>& pairs, | ||
const std::function<void(const std::string&, cpp_redis::reply&)>& 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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,4 +20,5 @@ solution "Redis" | |
optimize "On" | ||
|
||
include "module" | ||
include "cpp_redis/cpp_redis" | ||
--include "test" |