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