Skip to content

Commit

Permalink
async zrevrangebyscore api (#603)
Browse files Browse the repository at this point in the history
* add zrevrangebyscore

* add zrevrangebyscore

* Update async_redis.h
  • Loading branch information
BeyondWUXF authored Oct 12, 2024
1 parent 4ee6aac commit 55f23c0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/sw/redis++/async_redis.h
Original file line number Diff line number Diff line change
Expand Up @@ -1453,7 +1453,7 @@ class AsyncRedis {

template <typename Output, typename Interval>
Future<Output> zrangebyscore(const StringView &key, const Interval &interval) {
return zrangebyscore(key, interval, {});
return zrangebyscore<Output>(key, interval, {});
}

template <typename Output, typename Interval, typename Callback>
Expand Down Expand Up @@ -1565,6 +1565,32 @@ class AsyncRedis {
return zrevrangebylex<Output, Interval, Callback>(key, interval, {}, std::forward<Callback>(cb));
}

// TODO: withscores parameter
template <typename Output, typename Interval>
Future<Output> zrevrangebyscore(const StringView &key,
const Interval &interval,
const LimitOptions &opts) {
return _command<Output>(fmt::zrevrangebyscore<Interval>,
key, interval, opts);
}

template <typename Output, typename Interval, typename Callback>
auto zrevrangebyscore(const StringView &key, const Interval &interval, const LimitOptions &opts, Callback &&cb)
-> typename std::enable_if<IsInvocable<typename std::decay<Callback>::type, Future<Output> &&>::value, void>::type {
_callback_fmt_command<Output>(std::forward<Callback>(cb), fmt::zrevrangebyscore<Interval>, key, interval, opts);
}

template <typename Output, typename Interval>
Future<Output> zrevrangebyscore(const StringView &key, const Interval &interval) {
return zrevrangebyscore<Output>(key, interval, {});
}

template <typename Output, typename Interval, typename Callback>
auto zrevrangebyscore(const StringView &key, const Interval &interval, Callback &&cb)
-> typename std::enable_if<IsInvocable<typename std::decay<Callback>::type, Future<Output> &&>::value, void>::type {
return zrevrangebyscore<Output>(key, interval, {}, std::forward<Callback>(cb));
}

Future<OptionalLongLong> zrevrank(const StringView &key, const StringView &member) {
return _command<OptionalLongLong>(fmt::zrevrank, key, member);
}
Expand Down
15 changes: 15 additions & 0 deletions src/sw/redis++/cmd_formatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,21 @@ FormattedCommand zrevrangebylex(const StringView &key,
opts.count);
}

template <typename Interval>
FormattedCommand zrevrangebyscore(const StringView &key,
const Interval &interval,
const LimitOptions &opts) {
const auto &min = interval.lower();
const auto &max = interval.upper();

return format_cmd("ZREVRANGEBYSCORE %b %b %b LIMIT %lld %lld",
key.data(), key.size(),
max.data(), max.size(),
min.data(), min.size(),
opts.offset,
opts.count);
}

inline FormattedCommand zrevrank(const StringView &key, const StringView &member) {
return format_cmd("ZREVRANK %b %b", key.data(), key.size(), member.data(), member.size());
}
Expand Down

0 comments on commit 55f23c0

Please sign in to comment.