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
18 changes: 9 additions & 9 deletions Light/src/Database/Cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void Cache::disconnect() {
if (context_) {
redisFree(context_);
context_ = nullptr;
std::cout << "Disconnected from Redis." << std::endl;
Logger::log("Disconnected from Redis.", "INFO");
}
}

Expand All @@ -69,8 +69,8 @@ void Cache::set(const std::string& key, const std::string& value, int expire_sec
}

if (reply == nullptr) {
Logger::log("Failed to execute Redis command.", "ERROR");
throw std::runtime_error("Failed to execute Redis command.");
Logger::log("Failed to execute SET command.", "ERROR");
throw std::runtime_error("Failed to execute SET command.");
}

freeReplyObject(reply);
Expand All @@ -85,8 +85,8 @@ std::string Cache::get(const std::string& key) {

redisReply* reply = (redisReply*)redisCommand(context_, "GET %s", key.c_str());
if (reply == nullptr) {
Logger::log("Failed to execute Redis command.", "ERROR");
throw std::runtime_error("Failed to execute Redis command.");
Logger::log("Failed to execute GET command.", "ERROR");
throw std::runtime_error("Failed to execute GET command.");
}

std::string result;
Expand Down Expand Up @@ -115,8 +115,8 @@ void Cache::del(const std::string& key) {

redisReply* reply = (redisReply*)redisCommand(context_, "DEL %s", key.c_str());
if (reply == nullptr) {
Logger::log("Failed to execute Redis command.", "ERROR");
throw std::runtime_error("Failed to execute Redis command.");
Logger::log("Failed to execute DEL command.", "ERROR");
throw std::runtime_error("Failed to execute DEL command.");
}

freeReplyObject(reply);
Expand All @@ -131,8 +131,8 @@ void Cache::expire(const std::string& key, int expire_seconds) {

redisReply* reply = (redisReply*)redisCommand(context_, "EXPIRE %s %d", key.c_str(), expire_seconds);
if (reply == nullptr) {
Logger::log("Failed to execute Redis command.", "ERROR");
throw std::runtime_error("Failed to execute Redis command.");
Logger::log("Failed to execute EXPIRE command.", "ERROR");
throw std::runtime_error("Failed to execute EXPIRE command.");
}

freeReplyObject(reply);
Expand Down
12 changes: 6 additions & 6 deletions Light/src/Database/Queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ void Queue::push(const std::string& queue_name, const std::string& value) {

redisReply* reply = (redisReply*)redisCommand(context_, "RPUSH %s %s", queue_name.c_str(), value.c_str());
if (reply == nullptr) {
Logger::log("Failed to execute Redis command.", "ERROR");
throw std::runtime_error("Failed to execute Redis command.");
Logger::log("Failed to execute RPUSH command.", "ERROR");
throw std::runtime_error("Failed to execute RPUSH command.");
}

freeReplyObject(reply);
Expand All @@ -78,8 +78,8 @@ std::string Queue::pop(const std::string& queue_name) {

redisReply* reply = (redisReply*)redisCommand(context_, "LPOP %s", queue_name.c_str());
if (reply == nullptr) {
Logger::log("Failed to execute Redis command.", "ERROR");
throw std::runtime_error("Failed to execute Redis command.");
Logger::log("Failed to execute LPOP command.", "ERROR");
throw std::runtime_error("Failed to execute LPOP command.");
}

std::string result;
Expand Down Expand Up @@ -108,8 +108,8 @@ int Queue::length(const std::string& queue_name) {

redisReply* reply = (redisReply*)redisCommand(context_, "LLEN %s", queue_name.c_str());
if (reply == nullptr) {
Logger::log("Failed to execute Redis command.", "ERROR");
throw std::runtime_error("Failed to execute Redis command.");
Logger::log("Failed to execute LLEN command.", "ERROR");
throw std::runtime_error("Failed to execute LLEN command.");
}

int len = reply->integer;
Expand Down