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
23struct ConnectionInfo {
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
31 ConnectionInfo() = default;
32 ConnectionInfo(
33 std::string host,
34 int port,
35 Password password,
36 bool read_only = false,
37 ConnectionSecurity security = ConnectionSecurity::kNone
38 )
39 : host{std::move(host)},
40 port{port},
41 password{std::move(password)},
42 read_only{read_only},
43 connection_security(security) {}
44};
45
46struct Stat {
47 double tps = 0.0;
48 double queue = 0.0;
49 double inprogress = 0.0;
50 double timeouts = 0.0;
51};
52
53using ScanCursor = int64_t;
54
56 bool buffering_enabled{false};
57 size_t commands_buffering_threshold{0};
58 std::chrono::microseconds watch_command_timer_interval{0};
59
60 constexpr bool operator==(const CommandsBufferingSettings& o) const {
61 return buffering_enabled == o.buffering_enabled &&
62 commands_buffering_threshold == o.commands_buffering_threshold &&
63 watch_command_timer_interval == o.watch_command_timer_interval;
64 }
65};
66
67enum class ConnectionMode {
68 kCommands,
69 kSubscriber,
70};
71
72struct MetricsSettings {
73 enum class Level { kCluster, kShard, kInstance };
74
75 struct DynamicSettings {
76 bool timings_enabled{true};
77 bool command_timings_enabled{false};
78 bool request_sizes_enabled{false};
79 bool reply_sizes_enabled{false};
80
81 constexpr bool operator==(const DynamicSettings& rhs) const {
82 return timings_enabled == rhs.timings_enabled && command_timings_enabled == rhs.command_timings_enabled &&
83 request_sizes_enabled == rhs.request_sizes_enabled && reply_sizes_enabled == rhs.reply_sizes_enabled;
84 }
85
86 constexpr bool operator!=(const DynamicSettings& rhs) const { return !(*this == rhs); }
87 };
88
89 struct StaticSettings {
90 Level level{Level::kInstance};
91
92 constexpr bool operator==(const StaticSettings& rhs) const { return level == rhs.level; }
93
94 constexpr bool operator!=(const StaticSettings& rhs) const { return !(*this == rhs); }
95 };
96
97 StaticSettings static_settings;
98 DynamicSettings dynamic_settings;
99
100 MetricsSettings(const DynamicSettings& dynamic_settings, const StaticSettings& static_settings)
101 : static_settings(static_settings), dynamic_settings(dynamic_settings) {}
102 MetricsSettings() = default;
103 MetricsSettings(const MetricsSettings&) = default;
104 MetricsSettings(MetricsSettings&&) = default;
105 MetricsSettings& operator=(const MetricsSettings&) = default;
106 MetricsSettings& operator=(MetricsSettings&&) = default;
107
108 constexpr bool operator==(const MetricsSettings& rhs) const {
109 return static_settings == rhs.static_settings && dynamic_settings == rhs.dynamic_settings;
110 }
111
112 constexpr bool operator!=(const MetricsSettings& rhs) const { return !(*this == rhs); }
113
114 Level GetMetricsLevel() const { return static_settings.level; }
115 bool IsTimingsEnabled() const { return dynamic_settings.timings_enabled; }
116 bool IsCommandTimingsEnabled() const { return dynamic_settings.command_timings_enabled; }
117 bool IsRequestSizesEnabled() const { return dynamic_settings.request_sizes_enabled; }
118 bool IsReplySizesEnabled() const { return dynamic_settings.reply_sizes_enabled; }
119};
120
122 bool per_shard_stats_enabled{true};
123
124 constexpr bool operator==(const PubsubMetricsSettings& rhs) const {
125 return per_shard_stats_enabled == rhs.per_shard_stats_enabled;
126 }
127
128 constexpr bool operator!=(const PubsubMetricsSettings& rhs) const { return !(*this == rhs); }
129};
130
132 bool enable_monitoring{false};
133 bool restrict_requests{false};
134};
135
136struct PublishSettings {
137 size_t shard{0};
138 bool master{true};
140};
141
142} // namespace storages::redis
143
144USERVER_NAMESPACE_END