mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-02-17 11:45:50 +00:00
Load Lua script search paths into a SearchPaths.
This commit is contained in:
parent
cc943791ef
commit
afae0b6d11
4 changed files with 35 additions and 5 deletions
|
@ -1,5 +1,7 @@
|
|||
project(${bare_name}-backend-redis CXX)
|
||||
|
||||
set(DINDEXER_REDIS_SCRIPTS_PATH "${CMAKE_INSTALL_PREFIX}/${bare_name}/redis" CACHE STRING "Path where Lua scripts for Redis are stored")
|
||||
|
||||
find_package(hiredis 0.11.0 REQUIRED)
|
||||
find_package(CryptoPP 5.6)
|
||||
find_package(libev 4.0 REQUIRED)
|
||||
|
@ -27,7 +29,7 @@ target_include_directories(${PROJECT_NAME}
|
|||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
PRIVATE ${bare_name}-inc
|
||||
PRIVATE ${bare_name}-pq
|
||||
PUBLIC ${bare_name}-core
|
||||
PRIVATE ${HIREDIS_LIBRARIES}
|
||||
PRIVATE ${LIBEV_LIBRARIES}
|
||||
)
|
||||
|
@ -48,10 +50,26 @@ configure_file(
|
|||
redisConfig.h.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/redisConfig.h
|
||||
)
|
||||
set(LUA_SCRIPTS
|
||||
"${CMAKE_SOURCE_DIR}/lib/ohm-scripts/save.lua"
|
||||
"${CMAKE_SOURCE_DIR}/lib/ohm-scripts/delete.lua"
|
||||
)
|
||||
|
||||
install(TARGETS ${PROJECT_NAME}
|
||||
LIBRARY DESTINATION lib
|
||||
RUNTIME DESTINATION bin
|
||||
ARCHIVE DESTINATION lib/static
|
||||
)
|
||||
|
||||
set(lua_script_list "")
|
||||
foreach (lua_script ${LUA_SCRIPTS})
|
||||
get_filename_component(lua_script_basename "${lua_script}" NAME)
|
||||
configure_file("${lua_script}" "${CMAKE_CURRENT_BINARY_DIR}/lua/${lua_script_basename}" COPYONLY)
|
||||
list(APPEND lua_script_list "${CMAKE_CURRENT_BINARY_DIR}/lua/${lua_script_basename}")
|
||||
endforeach()
|
||||
unset(lua_script)
|
||||
unset(lua_script_basename)
|
||||
install(FILES ${lua_script_list} DESTINATION "${DINDEXER_REDIS_SCRIPTS_PATH}")
|
||||
unset(lua_script_list)
|
||||
|
||||
ln_backend(${PROJECT_NAME})
|
||||
|
|
|
@ -137,8 +137,9 @@ namespace YAML {
|
|||
//}
|
||||
|
||||
namespace dindb {
|
||||
BackendRedis::BackendRedis(std::string &&parAddress, uint16_t parPort, uint16_t parDatabase, bool parConnect) :
|
||||
BackendRedis::BackendRedis(std::string&& parAddress, uint16_t parPort, uint16_t parDatabase, bool parConnect, dincore::SearchPaths&& parLuaPaths) :
|
||||
m_redis(std::move(parAddress), parPort),
|
||||
m_lua_script_paths(std::move(parLuaPaths)),
|
||||
m_database(parDatabase)
|
||||
{
|
||||
if (parConnect)
|
||||
|
@ -290,12 +291,19 @@ extern "C" dindb::Backend* dindexer_create_backend (const YAML::Node* parConfig)
|
|||
if (not parConfig)
|
||||
return nullptr;
|
||||
|
||||
auto config = parConfig->as<dindb::RedisConnectionSettings>();
|
||||
auto& config_node = *parConfig;
|
||||
auto config = config_node["connection"].as<dindb::RedisConnectionSettings>();
|
||||
|
||||
auto vec = (config_node["script_paths"] ? config_node["script_paths"].as<std::vector<std::string>>() : std::vector<std::string>());
|
||||
dincore::SearchPaths lua_paths(std::move(vec));
|
||||
lua_paths.add_path(REDIS_SCRIPTS_PATH);
|
||||
|
||||
return new dindb::BackendRedis(
|
||||
std::move(config.address),
|
||||
config.port,
|
||||
config.database,
|
||||
true
|
||||
true,
|
||||
std::move(lua_paths)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include "backends/db_backend.hpp"
|
||||
#include "command.hpp"
|
||||
#include "dindexer-core/searchpaths.hpp"
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
|
||||
|
@ -27,7 +28,7 @@ namespace dindb {
|
|||
class BackendRedis : public Backend {
|
||||
public:
|
||||
BackendRedis ( BackendRedis&& ) = default;
|
||||
BackendRedis ( std::string&& parAddress, uint16_t parPort, uint16_t parDatabase, bool parConnect );
|
||||
BackendRedis ( std::string&& parAddress, uint16_t parPort, uint16_t parDatabase, bool parConnect, dincore::SearchPaths&& parLuaPaths );
|
||||
virtual ~BackendRedis ( void ) noexcept;
|
||||
|
||||
virtual void connect ( void ) override;
|
||||
|
@ -57,6 +58,7 @@ namespace dindb {
|
|||
|
||||
private:
|
||||
redis::Command m_redis;
|
||||
dincore::SearchPaths m_lua_script_paths;
|
||||
uint16_t m_database;
|
||||
};
|
||||
} //namespace dindb
|
||||
|
|
|
@ -24,4 +24,6 @@
|
|||
# define WITH_CRYPTOPP
|
||||
#endif
|
||||
|
||||
#define REDIS_SCRIPTS_PATH "@DINDEXER_REDIS_SCRIPTS_PATH@"
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue