userver: userver/storages/redis/base.hpp Source File
Loading...
Searching...
No Matches
base.hpp
1#pragma once
2
3#include <atomic>
4#include <chrono>
5#include <optional>
6#include <string>
7#include <vector>
8
9#include <userver/logging/fwd.hpp>
10#include <userver/utils/strong_typedef.hpp>
11
12#include <userver/storages/redis/command_control.hpp>
13#include <userver/storages/redis/fwd.hpp>
14
15USERVER_NAMESPACE_BEGIN
16
17namespace storages::redis {
18
19using Password = utils::NonLoggable<class PasswordTag, std::string>;
20
21enum class ConnectionSecurity { kNone, kTLS };
22
24 std::string host = "localhost";
25 int port = 26379;
26 Password password;
27 bool read_only = false;
28 ConnectionSecurity connection_security = ConnectionSecurity::kNone;
29 using HostVector = std::vector<std::string>;
30 std::size_t database_index = 0;
31
32 ConnectionInfo() = default;
33 ConnectionInfo(
34 std::string host,
35 int port,
36 Password password,
37 bool read_only = false,
38 ConnectionSecurity security = ConnectionSecurity::kNone,
39 std::size_t db_index = 0
40 )
41 : host{std::move(host)},
42 port{port},
43 password{std::move(password)},
44 read_only{read_only},
45 connection_security(security),
46 database_index(db_index)
47 {}
48};
49
50struct Stat {
51 double tps = 0.0;
52 double queue = 0.0;
53 double inprogress = 0.0;
54 double timeouts = 0.0;
55};
56
57using ScanCursor = int64_t;
58
60 bool buffering_enabled{false};
61 size_t commands_buffering_threshold{0};
62 std::chrono::microseconds watch_command_timer_interval{0};
63
64 constexpr bool operator==(const CommandsBufferingSettings& o) const {
65 return buffering_enabled == o.buffering_enabled &&
66 commands_buffering_threshold == o.commands_buffering_threshold &&
67 watch_command_timer_interval == o.watch_command_timer_interval;
68 }
69};
70
72 enum class Level { kCluster, kShard, kInstance };
73
75 bool timings_enabled{true};
76 bool command_timings_enabled{false};
77 bool request_sizes_enabled{false};
78 bool reply_sizes_enabled{false};
79
80 constexpr bool operator==(const DynamicSettings& rhs) const {
81 return timings_enabled == rhs.timings_enabled && command_timings_enabled == rhs.command_timings_enabled &&
82 request_sizes_enabled == rhs.request_sizes_enabled && reply_sizes_enabled == rhs.reply_sizes_enabled;
83 }
84
85 constexpr bool operator!=(const DynamicSettings& rhs) const { return !(*this == rhs); }
86 };
87
89 Level level{Level::kInstance};
90
91 constexpr bool operator==(const StaticSettings& rhs) const { return level == rhs.level; }
92
93 constexpr bool operator!=(const StaticSettings& rhs) const { return !(*this == rhs); }
94 };
95
96 StaticSettings static_settings;
97 DynamicSettings dynamic_settings;
98
99 MetricsSettings(const DynamicSettings& dynamic_settings, const StaticSettings& static_settings)
100 : static_settings(static_settings),
101 dynamic_settings(dynamic_settings)
102 {}
103 MetricsSettings() = default;
104 MetricsSettings(const MetricsSettings&) = default;
105 MetricsSettings(MetricsSettings&&) = default;
106 MetricsSettings& operator=(const MetricsSettings&) = default;
107 MetricsSettings& operator=(MetricsSettings&&) = default;
108
109 constexpr bool operator==(const MetricsSettings& rhs) const {
110 return static_settings == rhs.static_settings && dynamic_settings == rhs.dynamic_settings;
111 }
112
113 constexpr bool operator!=(const MetricsSettings& rhs) const { return !(*this == rhs); }
114
115 Level GetMetricsLevel() const { return static_settings.level; }
116 bool IsTimingsEnabled() const { return dynamic_settings.timings_enabled; }
117 bool IsCommandTimingsEnabled() const { return dynamic_settings.command_timings_enabled; }
118 bool IsRequestSizesEnabled() const { return dynamic_settings.request_sizes_enabled; }
119 bool IsReplySizesEnabled() const { return dynamic_settings.reply_sizes_enabled; }
120};
121
123 bool per_shard_stats_enabled{true};
124
125 constexpr bool operator==(const PubsubMetricsSettings& rhs) const {
126 return per_shard_stats_enabled == rhs.per_shard_stats_enabled;
127 }
128
129 constexpr bool operator!=(const PubsubMetricsSettings& rhs) const { return !(*this == rhs); }
130};
131
133 bool enable_monitoring{false};
134 bool restrict_requests{false};
135};
136
138 size_t shard{0};
139 bool master{true};
141};
142
143} // namespace storages::redis
144
145USERVER_NAMESPACE_END