userver: userver/storages/redis/base.hpp Source File
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
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
49struct Stat {
50 double tps = 0.0;
51 double queue = 0.0;
52 double inprogress = 0.0;
53 double timeouts = 0.0;
54};
55
56using ScanCursor = int64_t;
57
59 bool buffering_enabled{false};
60 size_t commands_buffering_threshold{0};
61 std::chrono::microseconds watch_command_timer_interval{0};
62
63 constexpr bool operator==(const CommandsBufferingSettings& o) const {
64 return buffering_enabled == o.buffering_enabled &&
65 commands_buffering_threshold == o.commands_buffering_threshold &&
66 watch_command_timer_interval == o.watch_command_timer_interval;
67 }
68};
69
70enum class ConnectionMode {
71 kCommands,
72 kSubscriber,
73};
74
76 enum class Level { kCluster, kShard, kInstance };
77
79 bool timings_enabled{true};
80 bool command_timings_enabled{false};
81 bool request_sizes_enabled{false};
82 bool reply_sizes_enabled{false};
83
84 constexpr bool operator==(const DynamicSettings& rhs) const {
85 return timings_enabled == rhs.timings_enabled && command_timings_enabled == rhs.command_timings_enabled &&
86 request_sizes_enabled == rhs.request_sizes_enabled && reply_sizes_enabled == rhs.reply_sizes_enabled;
87 }
88
89 constexpr bool operator!=(const DynamicSettings& rhs) const { return !(*this == rhs); }
90 };
91
93 Level level{Level::kInstance};
94
95 constexpr bool operator==(const StaticSettings& rhs) const { return level == rhs.level; }
96
97 constexpr bool operator!=(const StaticSettings& rhs) const { return !(*this == rhs); }
98 };
99
100 StaticSettings static_settings;
101 DynamicSettings dynamic_settings;
102
103 MetricsSettings(const DynamicSettings& dynamic_settings, const StaticSettings& static_settings)
104 : static_settings(static_settings), dynamic_settings(dynamic_settings) {}
105 MetricsSettings() = default;
106 MetricsSettings(const MetricsSettings&) = default;
107 MetricsSettings(MetricsSettings&&) = default;
108 MetricsSettings& operator=(const MetricsSettings&) = default;
109 MetricsSettings& operator=(MetricsSettings&&) = default;
110
111 constexpr bool operator==(const MetricsSettings& rhs) const {
112 return static_settings == rhs.static_settings && dynamic_settings == rhs.dynamic_settings;
113 }
114
115 constexpr bool operator!=(const MetricsSettings& rhs) const { return !(*this == rhs); }
116
117 Level GetMetricsLevel() const { return static_settings.level; }
118 bool IsTimingsEnabled() const { return dynamic_settings.timings_enabled; }
119 bool IsCommandTimingsEnabled() const { return dynamic_settings.command_timings_enabled; }
120 bool IsRequestSizesEnabled() const { return dynamic_settings.request_sizes_enabled; }
121 bool IsReplySizesEnabled() const { return dynamic_settings.reply_sizes_enabled; }
122};
123
125 bool per_shard_stats_enabled{true};
126
127 constexpr bool operator==(const PubsubMetricsSettings& rhs) const {
128 return per_shard_stats_enabled == rhs.per_shard_stats_enabled;
129 }
130
131 constexpr bool operator!=(const PubsubMetricsSettings& rhs) const { return !(*this == rhs); }
132};
133
135 bool enable_monitoring{false};
136 bool restrict_requests{false};
137};
138
140 size_t shard{0};
141 bool master{true};
143};
144
145} // namespace storages::redis
146
147USERVER_NAMESPACE_END