3#include <userver/storages/redis/parse_reply.hpp>
4#include <userver/storages/redis/reply.hpp>
5#include <userver/storages/redis/request.hpp>
9namespace storages::
redis {
11template <
typename ScriptResult,
typename ReplyType = ScriptResult>
12class [[nodiscard]] RequestEvalSha
final {
14 class EvalShaResult
final {
16 bool IsNoScriptError()
const {
return no_script_error_; }
17 bool HasValue()
const {
return reply_.has_value(); }
18 const ReplyType& Get()
const {
return *reply_; }
19 ReplyType Extract() {
return std::move(*reply_); }
22 friend class RequestEvalSha;
23 EvalShaResult() =
default;
24 explicit EvalShaResult(
bool no_script) : no_script_error_{no_script} {}
25 EvalShaResult(ReplyType&& reply) : reply_(std::move(reply)) {}
26 std::optional<ReplyType> reply_;
27 bool no_script_error_ =
false;
30 explicit RequestEvalSha(RequestEvalShaCommon&& request) : request_(std::move(request)) {}
32 void Wait() { request_.Wait(); }
34 void IgnoreResult()
const { request_.IgnoreResult(); }
36 EvalShaResult
Get(
const std::string& request_description = {}) {
37 auto reply_ptr = request_.GetRaw();
38 const auto& reply_data = reply_ptr->data;
39 if (reply_data.IsError()) {
40 const auto& msg = reply_data.GetError();
41 if (msg.find(
"NOSCRIPT", 0) == 0) {
42 return EvalShaResult(
true);
46 return ParseReply<ScriptResult, ReplyType>(std::move(reply_ptr), request_description);
50 RequestEvalShaCommon request_;