userver: userver/storages/redis/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 storages::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, formats::parse::To<WaitConnectedMode>);
26
27struct RedisWaitConnected {
28 WaitConnectedMode mode{WaitConnectedMode::kNoWait};
29 bool throw_on_fail{false};
30 std::chrono::milliseconds timeout{kRedisWaitConnectedDefaultTimeout};
31
32 RedisWaitConnected MergeWith(const testsuite::RedisControl& t) const;
33};
34
35} // namespace storages::redis
36
37#ifdef USERVER_FEATURE_LEGACY_REDIS_NAMESPACE
38namespace redis {
39using storages::redis::kRedisWaitConnectedDefaultTimeout;
40using storages::redis::RedisWaitConnected;
41using storages::redis::WaitConnectedMode;
42} // namespace redis
43#endif
44
45USERVER_NAMESPACE_END