From db23dcea3ff441f67504efdbb9a4744971166577 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Tue, 7 Jun 2016 23:13:24 +0100 Subject: [PATCH] Add missing implementation and fix crashes in redis backend. With this you can insert a new set (set only, no files) with dindexer-scan. --- src/backends/redis/CMakeLists.txt | 3 +- src/backends/redis/backend_redis.cpp | 59 +++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/src/backends/redis/CMakeLists.txt b/src/backends/redis/CMakeLists.txt index 8535712..634774d 100644 --- a/src/backends/redis/CMakeLists.txt +++ b/src/backends/redis/CMakeLists.txt @@ -21,4 +21,5 @@ install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION lib RUNTIME DESTINATION bin ARCHIVE DESTINATION lib/static -) \ No newline at end of file +) +ln_backend(${PROJECT_NAME}) diff --git a/src/backends/redis/backend_redis.cpp b/src/backends/redis/backend_redis.cpp index 8ddfb66..7c9ccc6 100644 --- a/src/backends/redis/backend_redis.cpp +++ b/src/backends/redis/backend_redis.cpp @@ -17,6 +17,8 @@ #include "backend_redis.hpp" #include "dindexer-machinery/recorddata.hpp" +#include "backends/exposed_functions.hpp" +#include "backends/backend_version.hpp" #include #include #include @@ -24,12 +26,42 @@ #include #include #include +#include namespace dindb { namespace { using RedisReply = std::unique_ptr; - } //unnamed namespace + struct RedisConnectionSettings { + std::string address; + uint16_t port; + }; + } //unnamed namespace +} //namespace dindb + +namespace YAML { + template<> + struct convert { + static Node encode (const dindb::RedisConnectionSettings& parSettings) { + Node node; + node["address"] = parSettings.address; + node["port"] = parSettings.port; + return node; + } + + static bool decode (const Node& parNode, dindb::RedisConnectionSettings& parSettings) { + if (not parNode.IsMap() or parNode.size() != 2) { + return false; + } + + parSettings.address = parNode["address"].as(); + parSettings.port = parNode["port"].as(); + return true; + } + }; +} //namespace YAML + +namespace dindb { BackendRedis::BackendRedis(std::string &&parAddress, uint16_t parPort, bool parConnect) : m_conn(nullptr, &redisFree), @@ -156,3 +188,28 @@ namespace dindb { return m_conn and not m_conn->err; } } //namespace dindb + +extern "C" dindb::Backend* dindexer_create_backend (const YAML::Node* parConfig) { + if (not parConfig) + return nullptr; + + auto config = parConfig->as(); + return new dindb::BackendRedis( + std::move(config.address), + config.port, + true + ); +} + +extern "C" void dindexer_destroy_backend (dindb::Backend* parDele) { + if (parDele) + delete parDele; +} + +extern "C" const char* dindexer_backend_name() { + return "redis"; +} + +extern "C" int dindexer_backend_iface_version() { + return dindb::g_current_iface_version; +}