Skip to content

Commit

Permalink
feat redis: hide implementation details in src directory
Browse files Browse the repository at this point in the history
Tests: протестировано CI
commit_hash:1f5d2c06fd90653564f6314ee474abc2ab9f321d
  • Loading branch information
apolukhin committed Dec 14, 2024
1 parent 55c4808 commit 7d3ad47
Show file tree
Hide file tree
Showing 30 changed files with 248 additions and 306 deletions.
8 changes: 4 additions & 4 deletions .mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -2943,9 +2943,7 @@
"redis/include/userver/storages/redis/hedged_request.hpp":"taxi/uservices/userver/redis/include/userver/storages/redis/hedged_request.hpp",
"redis/include/userver/storages/redis/impl/base.hpp":"taxi/uservices/userver/redis/include/userver/storages/redis/impl/base.hpp",
"redis/include/userver/storages/redis/impl/keyshard.hpp":"taxi/uservices/userver/redis/include/userver/storages/redis/impl/keyshard.hpp",
"redis/include/userver/storages/redis/impl/request.hpp":"taxi/uservices/userver/redis/include/userver/storages/redis/impl/request.hpp",
"redis/include/userver/storages/redis/impl/secdist_redis.hpp":"taxi/uservices/userver/redis/include/userver/storages/redis/impl/secdist_redis.hpp",
"redis/include/userver/storages/redis/impl/thread_pools.hpp":"taxi/uservices/userver/redis/include/userver/storages/redis/impl/thread_pools.hpp",
"redis/include/userver/storages/redis/impl/transaction_subrequest_data.hpp":"taxi/uservices/userver/redis/include/userver/storages/redis/impl/transaction_subrequest_data.hpp",
"redis/include/userver/storages/redis/key_type.hpp":"taxi/uservices/userver/redis/include/userver/storages/redis/key_type.hpp",
"redis/include/userver/storages/redis/parse_reply.hpp":"taxi/uservices/userver/redis/include/userver/storages/redis/parse_reply.hpp",
Expand Down Expand Up @@ -2978,14 +2976,12 @@
"redis/src/storages/redis/client_redistest.hpp":"taxi/uservices/userver/redis/src/storages/redis/client_redistest.hpp",
"redis/src/storages/redis/client_scan_redistest.cpp":"taxi/uservices/userver/redis/src/storages/redis/client_scan_redistest.cpp",
"redis/src/storages/redis/command_control.cpp":"taxi/uservices/userver/redis/src/storages/redis/command_control.cpp",
"redis/src/storages/redis/command_options.cpp":"taxi/uservices/userver/redis/src/storages/redis/command_options.cpp",
"redis/src/storages/redis/component.cpp":"taxi/uservices/userver/redis/src/storages/redis/component.cpp",
"redis/src/storages/redis/dynamic_config.cpp":"taxi/uservices/userver/redis/src/storages/redis/dynamic_config.cpp",
"redis/src/storages/redis/dynamic_config.hpp":"taxi/uservices/userver/redis/src/storages/redis/dynamic_config.hpp",
"redis/src/storages/redis/exception.cpp":"taxi/uservices/userver/redis/src/storages/redis/exception.cpp",
"redis/src/storages/redis/expire_reply.cpp":"taxi/uservices/userver/redis/src/storages/redis/expire_reply.cpp",
"redis/src/storages/redis/hedged_request_redistest.cpp":"taxi/uservices/userver/redis/src/storages/redis/hedged_request_redistest.cpp",
"redis/src/storages/redis/impl/base.cpp":"taxi/uservices/userver/redis/src/storages/redis/impl/base.cpp",
"redis/src/storages/redis/impl/cluster_sentinel_impl.cpp":"taxi/uservices/userver/redis/src/storages/redis/impl/cluster_sentinel_impl.cpp",
"redis/src/storages/redis/impl/cluster_sentinel_impl.hpp":"taxi/uservices/userver/redis/src/storages/redis/impl/cluster_sentinel_impl.hpp",
"redis/src/storages/redis/impl/cluster_shard.cpp":"taxi/uservices/userver/redis/src/storages/redis/impl/cluster_shard.cpp",
Expand All @@ -2996,6 +2992,8 @@
"redis/src/storages/redis/impl/cluster_subscription_storage_test.cpp":"taxi/uservices/userver/redis/src/storages/redis/impl/cluster_subscription_storage_test.cpp",
"redis/src/storages/redis/impl/cluster_topology.cpp":"taxi/uservices/userver/redis/src/storages/redis/impl/cluster_topology.cpp",
"redis/src/storages/redis/impl/cluster_topology.hpp":"taxi/uservices/userver/redis/src/storages/redis/impl/cluster_topology.hpp",
"redis/src/storages/redis/impl/cmd_args.cpp":"taxi/uservices/userver/redis/src/storages/redis/impl/cmd_args.cpp",
"redis/src/storages/redis/impl/cmd_args.hpp":"taxi/uservices/userver/redis/src/storages/redis/impl/cmd_args.hpp",
"redis/src/storages/redis/impl/command.cpp":"taxi/uservices/userver/redis/src/storages/redis/impl/command.cpp",
"redis/src/storages/redis/impl/command.hpp":"taxi/uservices/userver/redis/src/storages/redis/impl/command.hpp",
"redis/src/storages/redis/impl/command_control_impl.cpp":"taxi/uservices/userver/redis/src/storages/redis/impl/command_control_impl.cpp",
Expand Down Expand Up @@ -3027,6 +3025,7 @@
"redis/src/storages/redis/impl/reply_status_strings.hpp":"taxi/uservices/userver/redis/src/storages/redis/impl/reply_status_strings.hpp",
"redis/src/storages/redis/impl/reply_test.cpp":"taxi/uservices/userver/redis/src/storages/redis/impl/reply_test.cpp",
"redis/src/storages/redis/impl/request.cpp":"taxi/uservices/userver/redis/src/storages/redis/impl/request.cpp",
"redis/src/storages/redis/impl/request.hpp":"taxi/uservices/userver/redis/src/storages/redis/impl/request.hpp",
"redis/src/storages/redis/impl/sentinel.cpp":"taxi/uservices/userver/redis/src/storages/redis/impl/sentinel.cpp",
"redis/src/storages/redis/impl/sentinel.hpp":"taxi/uservices/userver/redis/src/storages/redis/impl/sentinel.hpp",
"redis/src/storages/redis/impl/sentinel_impl.cpp":"taxi/uservices/userver/redis/src/storages/redis/impl/sentinel_impl.cpp",
Expand Down Expand Up @@ -3055,6 +3054,7 @@
"redis/src/storages/redis/impl/tcp_socket.cpp":"taxi/uservices/userver/redis/src/storages/redis/impl/tcp_socket.cpp",
"redis/src/storages/redis/impl/tcp_socket.hpp":"taxi/uservices/userver/redis/src/storages/redis/impl/tcp_socket.hpp",
"redis/src/storages/redis/impl/thread_pools.cpp":"taxi/uservices/userver/redis/src/storages/redis/impl/thread_pools.cpp",
"redis/src/storages/redis/impl/thread_pools.hpp":"taxi/uservices/userver/redis/src/storages/redis/impl/thread_pools.hpp",
"redis/src/storages/redis/impl/transaction_subrequest_data.cpp":"taxi/uservices/userver/redis/src/storages/redis/impl/transaction_subrequest_data.cpp",
"redis/src/storages/redis/key_type.cpp":"taxi/uservices/userver/redis/src/storages/redis/key_type.cpp",
"redis/src/storages/redis/parse_reply.cpp":"taxi/uservices/userver/redis/src/storages/redis/parse_reply.cpp",
Expand Down
2 changes: 1 addition & 1 deletion redis/benchmark/redis_fixture.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "redis_fixture.hpp"

#include <storages/redis/impl/thread_pools.hpp>
#include <userver/dynamic_config/storage_mock.hpp>
#include <userver/engine/run_standalone.hpp>
#include <userver/engine/task/task.hpp>
#include <userver/storages/redis/impl/thread_pools.hpp>

#include <storages/redis/client_impl.hpp>
#include <storages/redis/impl/sentinel.hpp>
Expand Down
59 changes: 0 additions & 59 deletions redis/include/userver/storages/redis/base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,67 +50,8 @@ struct Stat {
double timeouts = 0.0;
};

class CmdArgs { // TODO: move to impl
public:
using CmdArgsArray = std::vector<std::string>;
using CmdArgsChain = std::vector<CmdArgsArray>;

CmdArgs() = default;

template <typename... Args>
CmdArgs(Args&&... _args) {
Then(std::forward<Args>(_args)...);
}

CmdArgs(const CmdArgs& o) = delete;
CmdArgs(CmdArgs&& o) = default;

CmdArgs& operator=(const CmdArgs& o) = delete;
CmdArgs& operator=(CmdArgs&& o) = default;

template <typename... Args>
CmdArgs& Then(Args&&... _args);

CmdArgs Clone() const {
CmdArgs r;
r.args = args;
return r;
}

CmdArgsChain args;
};

logging::LogHelper& operator<<(logging::LogHelper& os, const CmdArgs& v);

using ScanCursor = int64_t;

template <typename Arg>
typename std::enable_if<std::is_arithmetic<Arg>::value, void>::type
PutArg(CmdArgs::CmdArgsArray& args_, const Arg& arg) {
args_.emplace_back(std::to_string(arg));
}

void PutArg(CmdArgs::CmdArgsArray& args_, const char* arg);

void PutArg(CmdArgs::CmdArgsArray& args_, const std::string& arg);

void PutArg(CmdArgs::CmdArgsArray& args_, std::string&& arg);

void PutArg(CmdArgs::CmdArgsArray& args_, const std::vector<std::string>& arg);

void PutArg(CmdArgs::CmdArgsArray& args_, const std::vector<std::pair<std::string, std::string>>& arg);

void PutArg(CmdArgs::CmdArgsArray& args_, const std::vector<std::pair<double, std::string>>& arg);

template <typename... Args>
CmdArgs& CmdArgs::Then(Args&&... _args) {
args.emplace_back();
auto& new_args = args.back();
new_args.reserve(sizeof...(Args));
(PutArg(new_args, std::forward<Args>(_args)), ...);
return *this;
}

struct CommandsBufferingSettings {
bool buffering_enabled{false};
size_t commands_buffering_threshold{0};
Expand Down
26 changes: 9 additions & 17 deletions redis/include/userver/storages/redis/command_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,21 @@ struct ZaddOptions {
enum class ReturnValue { kAddedCount, kChangedCount };

ZaddOptions() = default;
ZaddOptions(Exist exist, ReturnValue return_value = ReturnValue::kAddedCount)
constexpr ZaddOptions(Exist exist, ReturnValue return_value = ReturnValue::kAddedCount)
: exist(exist), return_value(return_value) {}
constexpr ZaddOptions(ReturnValue return_value, Exist exist = Exist::kAddAlways)
: exist(exist), return_value(return_value) {}
ZaddOptions(ReturnValue return_value, Exist exist = Exist::kAddAlways) : exist(exist), return_value(return_value) {}

Exist exist = Exist::kAddAlways;
ReturnValue return_value = ReturnValue::kAddedCount;
};

ZaddOptions operator|(ZaddOptions::Exist exist, ZaddOptions::ReturnValue return_value);
ZaddOptions operator|(ZaddOptions::ReturnValue return_value, ZaddOptions::Exist exist);
constexpr ZaddOptions operator|(ZaddOptions::Exist exist, ZaddOptions::ReturnValue return_value) {
return {exist, return_value};
}
constexpr ZaddOptions operator|(ZaddOptions::ReturnValue return_value, ZaddOptions::Exist exist) {
return {exist, return_value};
}

class ScanOptionsBase {
public:
Expand Down Expand Up @@ -151,19 +156,6 @@ struct RangeScoreOptions {
RangeOptions range_options;
};

void PutArg(CmdArgs::CmdArgsArray& args_, std::optional<ScanOptionsBase::Match> arg);
void PutArg(CmdArgs::CmdArgsArray& args_, std::optional<ScanOptionsBase::Count> arg);
void PutArg(CmdArgs::CmdArgsArray& args_, GeoaddArg arg);
void PutArg(CmdArgs::CmdArgsArray& args_, std::vector<GeoaddArg> arg);
void PutArg(CmdArgs::CmdArgsArray& args_, const GeoradiusOptions& arg);
void PutArg(CmdArgs::CmdArgsArray& args_, const GeosearchOptions& arg);
void PutArg(CmdArgs::CmdArgsArray& args_, const SetOptions& arg);
void PutArg(CmdArgs::CmdArgsArray& args_, const ZaddOptions& arg);
void PutArg(CmdArgs::CmdArgsArray& args_, const ScanOptions& arg);
void PutArg(CmdArgs::CmdArgsArray& args_, const ScoreOptions& arg);
void PutArg(CmdArgs::CmdArgsArray& args_, const RangeOptions& arg);
void PutArg(CmdArgs::CmdArgsArray& args_, const RangeScoreOptions& arg);

} // namespace storages::redis

USERVER_NAMESPACE_END
2 changes: 1 addition & 1 deletion redis/include/userver/storages/redis/fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ReplyData;

struct CommandControl;

template <typename Result, typename ReplyType = Result>
template <typename ResultType, typename ReplyType = ResultType>
class [[nodiscard]] Request;

using ReplyPtr = std::shared_ptr<Reply>;
Expand Down
1 change: 0 additions & 1 deletion redis/include/userver/storages/redis/impl/base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

USERVER_NAMESPACE_BEGIN
namespace redis {
using storages::redis::CmdArgs; // TODO: move to impl
using storages::redis::CommandsBufferingSettings;
using storages::redis::ConnectionInfo;
using storages::redis::ConnectionSecurity;
Expand Down
3 changes: 2 additions & 1 deletion redis/include/userver/storages/redis/request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ namespace storages::redis {
template <ScanTag scan_tag>
class RequestScanData;

template <typename Result, typename ReplyType>
template <typename ResultType, typename ReplyType>
class [[nodiscard]] Request final {
public:
using Result = ResultType;
using Reply = ReplyType;

explicit Request(std::unique_ptr<RequestDataBase<ReplyType>>&& impl) : impl_(std::move(impl)) {}
Expand Down
1 change: 1 addition & 0 deletions redis/src/storages/redis/client_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ USERVER_NAMESPACE_BEGIN

namespace storages::redis {

using impl::CmdArgs;
using impl::CommandControlImpl;

namespace {
Expand Down
5 changes: 3 additions & 2 deletions redis/src/storages/redis/client_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#include <string>
#include <vector>

#include <storages/redis/impl/request.hpp>
#include <userver/storages/redis/base.hpp>
#include <userver/storages/redis/command_options.hpp>
#include <userver/storages/redis/impl/request.hpp>

#include <userver/storages/redis/client.hpp>
#include <userver/storages/redis/transaction.hpp>
Expand All @@ -18,6 +18,7 @@
USERVER_NAMESPACE_BEGIN

namespace storages::redis::impl {
class CmdArgs;
class Sentinel;
} // namespace storages::redis::impl

Expand Down Expand Up @@ -431,7 +432,7 @@ class ClientImpl final : public Client, public std::enable_shared_from_this<Clie

private:
impl::Request MakeRequest(
CmdArgs&& args,
impl::CmdArgs&& args,
size_t shard,
bool master,
const CommandControl& command_control,
Expand Down
2 changes: 1 addition & 1 deletion redis/src/storages/redis/component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
#include <fmt/ranges.h>

#include <engine/ev/thread_pool.hpp>
#include <storages/redis/impl/thread_pools.hpp>
#include <userver/components/component.hpp>
#include <userver/components/statistics_storage.hpp>
#include <userver/dynamic_config/storage/component.hpp>
#include <userver/formats/json/value_builder.hpp>
#include <userver/logging/log.hpp>
#include <userver/storages/redis/impl/thread_pools.hpp>
#include <userver/storages/redis/reply.hpp>
#include <userver/storages/secdist/component.hpp>
#include <userver/storages/secdist/exceptions.hpp>
Expand Down
86 changes: 0 additions & 86 deletions redis/src/storages/redis/impl/base.cpp

This file was deleted.

Loading

0 comments on commit 7d3ad47

Please sign in to comment.