1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2024-11-25 00:53:43 +00:00

Fix SCAN iteration.

This commit is contained in:
King_DuckZ 2016-06-13 10:57:42 +01:00
parent c1e79c435b
commit e0a82cce2d
7 changed files with 54 additions and 12 deletions

View file

@ -54,6 +54,8 @@ namespace YAML {
parSettings.port = parNode["port"].as<uint16_t>();
if (parNode["database"])
parSettings.database = parNode["database"].as<uint16_t>();
else
parSettings.database = 0;
return true;
}
};
@ -90,7 +92,7 @@ namespace dindb {
void BackendRedis::tag_files (const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, GroupIDType parSet) {
for (const auto& file_path : m_redis.scan()) {
std::cout << file_path << '\n';
//std::cout << file_path << '\n';
}
}

View file

@ -84,8 +84,8 @@ namespace redis {
m_conn.reset();
}
RedisReplyType Command::run_pvt (const char* parCommand, int parArgc, const char** parArgv, std::size_t* parLengths) {
assert(parCommand);
RedisReplyType Command::run_pvt (int parArgc, const char** parArgv, std::size_t* parLengths) {
assert(parArgc >= 1);
assert(parArgv);
assert(parLengths); //This /could/ be null, but I don't see why it should
assert(is_connected());

View file

@ -56,7 +56,7 @@ namespace redis {
private:
using RedisConnection = std::unique_ptr<redisContext, void(*)(redisContext*)>;
RedisReplyType run_pvt ( const char* parCommand, int parArgc, const char** parArgv, std::size_t* parLengths );
RedisReplyType run_pvt ( int parArgc, const char** parArgv, std::size_t* parLengths );
RedisConnection m_conn;
std::string m_address;
@ -65,15 +65,17 @@ namespace redis {
template <typename... Args>
RedisReplyType Command::run (const char* parCommand, Args&&... parArgs) {
constexpr const std::size_t arg_count = sizeof...(Args);
constexpr const std::size_t arg_count = sizeof...(Args) + 1;
using CharPointerArray = std::array<const char*, arg_count>;
using LengthArray = std::array<std::size_t, arg_count>;
using implem::arg_to_bin_safe_char;
using implem::arg_to_bin_safe_length;
using boost::string_ref;
return this->run_pvt(
parCommand,
static_cast<int>(arg_count),
CharPointerArray{ implem::arg_to_bin_safe_char(std::forward<Args>(parArgs))... }.data(),
LengthArray{ implem::arg_to_bin_safe_length(std::forward<Args>(parArgs))... }.data()
CharPointerArray{ arg_to_bin_safe_char(string_ref(parCommand)), arg_to_bin_safe_char(std::forward<Args>(parArgs))... }.data(),
LengthArray{ arg_to_bin_safe_length(string_ref(parCommand)), arg_to_bin_safe_length(std::forward<Args>(parArgs))... }.data()
);
}
} //namespace redis

View file

@ -17,6 +17,7 @@
#include "reply.hpp"
#include <boost/variant/get.hpp>
#include <boost/lexical_cast.hpp>
namespace redis {
const long long& get_integer (const RedisReplyType& parReply) {
@ -27,6 +28,21 @@ namespace redis {
return boost::get<std::string>(parReply);
}
long long get_integer_autoconv_if_str (const RedisReplyType &parReply) {
using boost::lexical_cast;
const auto type = parReply.which();
switch (type) {
case implem::RedisVariantType_Integer:
return get_integer(parReply);
case implem::RedisVariantType_String:
return lexical_cast<long long>(get_string(parReply));
default:
assert(false);
return 0;
}
}
const std::vector<RedisReplyType>& get_array (const RedisReplyType& parReply) {
return boost::get<std::vector<RedisReplyType>>(parReply);
}

View file

@ -50,6 +50,7 @@ namespace redis {
};
const long long& get_integer ( const RedisReplyType& parReply );
long long get_integer_autoconv_if_str ( const RedisReplyType& parReply );
const std::string& get_string ( const RedisReplyType& parReply );
const std::vector<RedisReplyType>& get_array ( const RedisReplyType& parReply );

View file

@ -71,6 +71,7 @@ namespace redis {
RedisReplyType forward_scan_command ( typename std::enable_if<HasScanTargetMethod<T>::value, int>::type parDummy );
template <typename T>
RedisReplyType forward_scan_command ( typename std::enable_if<not HasScanTargetMethod<T>::value, int>::type parDummy );
bool is_end ( void ) const;
void increment ( void );
bool equal ( const ScanIterator& parOther ) const;

View file

@ -30,16 +30,33 @@ namespace redis {
m_scan_context(0),
m_curr_index(0)
{
if (not parEnd)
if (not parEnd) {
m_curr_index = 1; //Some arbitrary value so is_end()==false
assert(not is_end());
this->increment();
}
else {
assert(is_end());
}
}
template <typename V, typename ValueFetch>
bool ScanIterator<V, ValueFetch>::is_end() const {
return not m_curr_index and m_reply.empty() and not m_scan_context;
}
template <typename V, typename ValueFetch>
void ScanIterator<V, ValueFetch>::increment() {
assert(not is_end());
static_assert(ValueFetch::step > 0, "Can't have an increase step of 0");
if (m_curr_index + ValueFetch::step < m_reply.size()) {
m_curr_index += ValueFetch::step;
}
else if (m_curr_index + ValueFetch::step == m_reply.size() and not m_scan_context) {
m_reply.clear();
m_curr_index = 0;
}
else {
std::vector<RedisReplyType> array_reply;
long long new_context;
@ -50,7 +67,7 @@ namespace redis {
array_reply = get_array(whole_reply);
assert(2 == array_reply.size());
assert(array_reply.size() % ValueFetch::step == 0);
new_context = get_integer(array_reply[0]);
new_context = get_integer_autoconv_if_str(array_reply[0]);
} while (new_context and array_reply.empty());
m_reply = get_array(array_reply[1]);
@ -63,15 +80,18 @@ namespace redis {
bool ScanIterator<V, ValueFetch>::equal (const ScanIterator& parOther) const {
return
(&parOther == this) or
(is_end() and parOther.is_end()) or
(
not (is_end() or parOther.is_end()) and
implem::ScanIteratorBaseClass::is_equal(parOther) and
(m_scan_context == parOther.m_scan_context)
(m_scan_context == parOther.m_scan_context) and
(m_curr_index == parOther.m_curr_index) and
(m_reply.size() == parOther.m_reply.size())
);
}
template <typename V, typename ValueFetch>
const V& ScanIterator<V, ValueFetch>::dereference() const {
assert(m_scan_context);
assert(not m_reply.empty());
assert(m_curr_index < m_reply.size());