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

Implement zrangebyscore().

This commit is contained in:
King_DuckZ 2016-07-13 01:47:38 +01:00
parent a9b979dd03
commit 9a84f63e54
4 changed files with 34 additions and 0 deletions

View file

@ -119,6 +119,13 @@ namespace redis {
return optional_string_list(m_command.run("SMEMBERS", parKey));
}
auto IncRedis::zrangebyscore (boost::string_ref parKey, double parMin, bool parMinIncl, double parMax, bool parMaxIncl, bool parWithScores) -> opt_string_list {
auto batch = make_batch();
batch.zrangebyscore(parKey, parMin, parMinIncl, parMax, parMaxIncl, parWithScores);
assert(batch.replies().size() == 1);
return optional_string_list(batch.replies().front());
}
bool IncRedis::script_flush() {
const auto ret = get<StatusString>(m_command.run("SCRIPT", "FLUSH"));
return ret.is_ok();

View file

@ -76,6 +76,9 @@ namespace redis {
opt_string srandmember ( boost::string_ref parKey );
opt_string_list smembers ( boost::string_ref parKey );
//Sorted set
opt_string_list zrangebyscore ( boost::string_ref parKey, double parMin, bool parMinIncl, double parMax, bool parMaxIncl, bool parWithScores );
//Script
bool script_flush ( void );

View file

@ -17,9 +17,21 @@
#include "incredis_batch.hpp"
#include "helpers/lexical_cast.hpp"
#include <sstream>
#include <utility>
#include <ciso646>
namespace redis {
namespace {
std::string make_boundary (double parValue, bool parExclude) {
std::ostringstream oss;
if (parExclude)
oss << '(';
oss << parValue;
return oss.str();
}
} //unnamed namespace
IncRedisBatch::IncRedisBatch (Batch&& parBatch) :
m_batch(std::move(parBatch))
{
@ -62,6 +74,17 @@ namespace redis {
return *this;
}
IncRedisBatch& IncRedisBatch::zrangebyscore (boost::string_ref parKey, double parMin, bool parMinIncl, double parMax, bool parMaxIncl, bool parWithScores) {
auto lower_bound = make_boundary(parMin, not parMinIncl);
auto upper_bound = make_boundary(parMax, not parMaxIncl);
if (parWithScores)
m_batch.run("ZRANGEBYSCORE", parKey, lower_bound, upper_bound, "WITHSCORES");
else
m_batch.run("ZRANGEBYSCORE", parKey, lower_bound, upper_bound);
return *this;
}
IncRedisBatch& IncRedisBatch::script_flush() {
m_batch.run("SCRIPT", "FLUSH");
return *this;

View file

@ -67,6 +67,7 @@ namespace redis {
//Sorted set
template <typename... Args>
IncRedisBatch& zadd ( boost::string_ref parKey, ZADD_Mode parMode, bool parChange, Args&&... parArgs );
IncRedisBatch& zrangebyscore ( boost::string_ref parKey, double parMin, bool parMinIncl, double parMax, bool parMaxIncl, bool parWithScores );
//Script
IncRedisBatch& script_flush ( void );