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
22/// @brief Redis node authentication credentials (ACL-aware).
23///
24/// When `username` is empty, the legacy `AUTH <password>` command is used.
25/// When `username` is non-empty, the ACL `AUTH <username> <password>` command
26/// is used (requires Redis 6+).
28 std::string username;
29 Password password;
30};
31
32enum class ConnectionSecurity { kNone, kTLS };
33
35 std::string host = "localhost";
36 int port = 26379;
37 Credentials credentials;
38 bool read_only = false;
39 ConnectionSecurity connection_security = ConnectionSecurity::kNone;
40 using HostVector = std::vector<std::string>;
41 std::size_t database_index = 0;
42
43 ConnectionInfo() = default;
44 ConnectionInfo(
45 std::string host,
46 int port,
47 Credentials credentials,
48 bool read_only = false,
49 ConnectionSecurity security = ConnectionSecurity::kNone,
50 std::size_t db_index = 0
51 )
52 : host{std::move(host)},
53 port{port},
54 credentials{std::move(credentials)},
55 read_only{read_only},
56 connection_security(security),
57 database_index(db_index)
58 {}
59};
60
61struct Stat {
62 double tps = 0.0;
63 double queue = 0.0;
64 double inprogress = 0.0;
65 double timeouts = 0.0;
66};
67
68using ScanCursor = int64_t;
69
71 bool buffering_enabled{false};
72 size_t commands_buffering_threshold{0};
73 std::chrono::microseconds watch_command_timer_interval{0};
74
75 constexpr bool operator==(const CommandsBufferingSettings& o) const {
76 return buffering_enabled == o.buffering_enabled &&
77 commands_buffering_threshold == o.commands_buffering_threshold &&
78 watch_command_timer_interval == o.watch_command_timer_interval;
79 }
80};
81
84 bool timings_enabled{true};
85 bool command_timings_enabled{false};
86 bool request_sizes_enabled{false};
87 bool reply_sizes_enabled{false};
88
89 constexpr bool operator==(const DynamicSettings& rhs) const {
90 return timings_enabled == rhs.timings_enabled && command_timings_enabled == rhs.command_timings_enabled &&
91 request_sizes_enabled == rhs.request_sizes_enabled && reply_sizes_enabled == rhs.reply_sizes_enabled;
92 }
93 };
94
95 DynamicSettings dynamic_settings;
96
97 MetricsSettings(const DynamicSettings& dynamic_settings)
98 : dynamic_settings(dynamic_settings)
99 {}
100 MetricsSettings() = default;
101 MetricsSettings(const MetricsSettings&) = default;
102 MetricsSettings(MetricsSettings&&) = default;
103 MetricsSettings& operator=(const MetricsSettings&) = default;
104 MetricsSettings& operator=(MetricsSettings&&) = default;
105
106 constexpr bool operator==(const MetricsSettings& rhs) const { return dynamic_settings == rhs.dynamic_settings; }
107
108 bool IsTimingsEnabled() const { return dynamic_settings.timings_enabled; }
109 bool IsCommandTimingsEnabled() const { return dynamic_settings.command_timings_enabled; }
110 bool IsRequestSizesEnabled() const { return dynamic_settings.request_sizes_enabled; }
111 bool IsReplySizesEnabled() const { return dynamic_settings.reply_sizes_enabled; }
112};
113
115 bool per_shard_stats_enabled{true};
116
117 constexpr bool operator==(const PubsubMetricsSettings& rhs) const {
118 return per_shard_stats_enabled == rhs.per_shard_stats_enabled;
119 }
120};
121
123 bool enable_monitoring{false};
124 bool restrict_requests{false};
125};
126
128 size_t shard{0};
129 bool master{true};
131};
132
133} // namespace storages::redis
134
135USERVER_NAMESPACE_END