userver: userver/storages/redis/impl/wait_connected_mode.hpp Source File
Loading...
Searching...
No Matches
wait_connected_mode.hpp
1#pragma once
2
3#include <chrono>
4#include <string>
5
6#include <userver/formats/parse/to.hpp>
7#include <userver/testsuite/redis_control.hpp>
8
9USERVER_NAMESPACE_BEGIN
10
11namespace redis {
12
13const auto kRedisWaitConnectedDefaultTimeout = std::chrono::seconds(11);
14
15enum class WaitConnectedMode {
16 kNoWait, // Do not wait.
17 kMaster, // If we need to write to redis.
18 kMasterOrSlave, // Enough for reading data from redis.
19 kSlave, // It may be no slaves on unstable. Waiting can always fail.
20 kMasterAndSlave, // It may be no slaves on unstable.
21};
22
23std::string ToString(WaitConnectedMode mode);
24
25WaitConnectedMode Parse(const std::string& str,
26 formats::parse::To<WaitConnectedMode>);
27
28struct RedisWaitConnected {
29 WaitConnectedMode mode{WaitConnectedMode::kNoWait};
30 bool throw_on_fail{false};
31 std::chrono::milliseconds timeout{kRedisWaitConnectedDefaultTimeout};
32
33 RedisWaitConnected MergeWith(const testsuite::RedisControl& t) const;
34};
35
36} // namespace redis
37
38USERVER_NAMESPACE_END