userver: userver/storages/redis/component.hpp Source File
Loading...
Searching...
No Matches
component.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <memory>
7#include <string>
8#include <unordered_map>
9
13#include <userver/rcu/rcu.hpp>
20
21USERVER_NAMESPACE_BEGIN
22
24namespace storages {}
25
27namespace storages::redis {
28
29class SubscribeClientImpl;
30
31namespace impl {
32class Sentinel;
33class ThreadPools;
34class HealthCheckManager;
35} // namespace impl
36} // namespace storages::redis
37
38namespace components {
39
135class Redis : public ComponentBase {
136public:
137 Redis(const ComponentConfig& config, const ComponentContext& component_context);
138
139 ~Redis() override;
140
143 static constexpr std::string_view kName = "redis";
144
146 std::shared_ptr<storages::redis::Client> GetClient(
147 const std::string& name,
148 storages::redis::RedisWaitConnected wait_connected = {}
149 ) const;
150
151 [[deprecated("use GetClient()")]] std::shared_ptr<storages::redis::impl::Sentinel> Client(const std::string& name
152 ) const;
153
155 std::shared_ptr<storages::redis::SubscribeClient> GetSubscribeClient(
156 const std::string& name,
157 storages::redis::RedisWaitConnected wait_connected = {}
158 ) const;
159
161
163
164private:
165 void OnConfigUpdate(const dynamic_config::Snapshot& cfg);
166 void OnSecdistUpdate(const storages::secdist::SecdistConfig& cfg);
167
168 void Connect(
169 const ComponentConfig& config,
170 const ComponentContext& component_context,
171 const testsuite::RedisControl& testsuite_redis_control
172 );
173
174 void WriteStatistics(utils::statistics::Writer& writer);
175 void WriteStatisticsPubsub(utils::statistics::Writer& writer);
176
177 std::shared_ptr<storages::redis::impl::ThreadPools> thread_pools_;
178 std::unordered_map<std::string, std::shared_ptr<storages::redis::impl::Sentinel>> sentinels_;
179 std::unordered_map<std::string, std::shared_ptr<storages::redis::Client>> clients_;
180 std::unordered_map<std::string, std::shared_ptr<storages::redis::SubscribeClientImpl>> subscribe_clients_;
181
182 std::unique_ptr<storages::redis::impl::HealthCheckManager> health_check_manager_;
183
185
188};
189
190template <>
191inline constexpr bool kHasValidate<Redis> = true;
192
193} // namespace components
194
195USERVER_NAMESPACE_END