mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-07-12 15:44:13 +00:00
Load save and delete scripts upon connection to Redis.
This commit is contained in:
parent
0e31aa7ea0
commit
1aacca9e21
4 changed files with 40 additions and 2 deletions
|
@ -26,6 +26,7 @@
|
|||
#include <yaml-cpp/yaml.h>
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
|
||||
namespace dindb {
|
||||
namespace {
|
||||
|
@ -93,6 +94,23 @@ namespace dindb {
|
|||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
std::string read_script (const dincore::SearchPaths& parSearch, const char* parName) {
|
||||
const auto full_path = parSearch.first_hit(boost::string_ref(parName));
|
||||
if (full_path.empty()) {
|
||||
const std::string msg = std::string("Unable to locate and load Lua script \"") + parName + "\" from any of the given search paths";
|
||||
throw std::runtime_error(msg);
|
||||
}
|
||||
|
||||
std::ifstream script(full_path);
|
||||
std::string retval;
|
||||
script.seekg(0, std::ios::end);
|
||||
retval.reserve(script.tellg());
|
||||
script.seekg(0, std::ios::beg);
|
||||
retval.assign(std::istreambuf_iterator<char>(script), std::istreambuf_iterator<char>());
|
||||
|
||||
return retval;
|
||||
}
|
||||
} //unnamed namespace
|
||||
} //namespace dindb
|
||||
|
||||
|
@ -165,6 +183,9 @@ namespace dindb {
|
|||
oss << "Error connecting to Redis: " << m_redis.connection_error();
|
||||
throw std::runtime_error(oss.str());
|
||||
}
|
||||
|
||||
m_script_save = m_redis.make_script(read_script(m_lua_script_paths, "save.lua"));
|
||||
m_script_delete = m_redis.make_script(read_script(m_lua_script_paths, "delete.lua"));
|
||||
}
|
||||
|
||||
void BackendRedis::disconnect() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue