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