mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-07-16 16:24:12 +00:00
Restore adding sets into Redis using the new run() method.
Partial implementation - not for use in real world cases.
This commit is contained in:
parent
f7a7015c65
commit
49a8e81fed
4 changed files with 156 additions and 8 deletions
|
@ -18,16 +18,46 @@
|
|||
#ifndef idD83EEBFC927840C6B9F32D61A1D1E582
|
||||
#define idD83EEBFC927840C6B9F32D61A1D1E582
|
||||
|
||||
#include "arg_to_bin_safe.hpp"
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
#include <cassert>
|
||||
#include <boost/variant/variant.hpp>
|
||||
#include <boost/variant/recursive_wrapper.hpp>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
|
||||
struct redisContext;
|
||||
|
||||
namespace redis {
|
||||
class RedisReplyType;
|
||||
|
||||
namespace implem {
|
||||
using RedisVariantType = boost::variant<
|
||||
long long,
|
||||
std::string,
|
||||
boost::recursive_wrapper<std::vector<RedisReplyType>>
|
||||
>;
|
||||
enum RedisVariantTypes {
|
||||
RedisVariantType_Integer = 0,
|
||||
RedisVariantType_String,
|
||||
RedisVariantType_Array
|
||||
};
|
||||
} //namespace implem
|
||||
|
||||
struct RedisReplyType : implem::RedisVariantType {
|
||||
using base_class = implem::RedisVariantType;
|
||||
|
||||
RedisReplyType ( void ) = default;
|
||||
RedisReplyType ( long long parVal ) : base_class(parVal) {}
|
||||
RedisReplyType ( std::string&& parVal ) : base_class(std::move(parVal)) {}
|
||||
RedisReplyType ( std::vector<RedisReplyType>&& parVal ) : base_class(std::move(parVal)) {}
|
||||
~RedisReplyType ( void ) noexcept = default;
|
||||
};
|
||||
|
||||
class Command {
|
||||
public:
|
||||
Command ( std::string&& parAddress, uint16_t parPort, bool parConnect );
|
||||
|
@ -39,12 +69,12 @@ namespace redis {
|
|||
bool is_connected ( void ) const;
|
||||
|
||||
template <typename... Args>
|
||||
void run ( const char* parCommand, Args&&... parArgs );
|
||||
RedisReplyType run ( const char* parCommand, Args&&... parArgs );
|
||||
|
||||
private:
|
||||
using RedisConnection = std::unique_ptr<redisContext, void(*)(redisContext*)>;
|
||||
|
||||
void run ( const char* parCommand, int parArgc, const char** parArgv, std::size_t* parLengths );
|
||||
RedisReplyType run_pvt ( const char* parCommand, int parArgc, const char** parArgv, std::size_t* parLengths );
|
||||
|
||||
RedisConnection m_conn;
|
||||
std::string m_address;
|
||||
|
@ -52,7 +82,7 @@ namespace redis {
|
|||
};
|
||||
|
||||
template <typename... Args>
|
||||
void Command::run (const char* parCommand, Args&&... parArgs) {
|
||||
RedisReplyType Command::run (const char* parCommand, Args&&... parArgs) {
|
||||
constexpr const std::size_t arg_count = sizeof...(Args);
|
||||
using CharPointerArray = std::array<const char*, arg_count>;
|
||||
using LengthArray = std::array<std::size_t, arg_count>;
|
||||
|
@ -61,13 +91,17 @@ namespace redis {
|
|||
LengthArray lengths;
|
||||
assert(false); //TODO write implementation
|
||||
|
||||
this->run(
|
||||
return this->run_pvt(
|
||||
parCommand,
|
||||
static_cast<int>(arg_count),
|
||||
arguments.data(),
|
||||
lengths.data()
|
||||
CharPointerArray{ implem::arg_to_bin_safe_char(std::forward<Args>(parArgs))... }.data(),
|
||||
LengthArray{ implem::arg_to_bin_safe_length(std::forward<Args>(parArgs))... }.data()
|
||||
);
|
||||
}
|
||||
|
||||
long long get_integer ( const RedisReplyType& parReply );
|
||||
std::string get_string ( const RedisReplyType& parReply );
|
||||
std::vector<RedisReplyType> get_array ( const RedisReplyType& parReply );
|
||||
} //namespace redis
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue