This commit is contained in:
10
rediska/common/CMakeLists.txt
Normal file
10
rediska/common/CMakeLists.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
add_library(common STATIC
|
||||
tmp.cpp
|
||||
)
|
||||
|
||||
find_package(concurrentqueue REQUIRED)
|
||||
|
||||
target_link_libraries(common
|
||||
PUBLIC
|
||||
spdlog::spdlog
|
||||
)
|
||||
46
rediska/common/MessageArguments.hpp
Normal file
46
rediska/common/MessageArguments.hpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include <variant>
|
||||
#include "rediska/common/types.hpp"
|
||||
|
||||
struct PrimitiveSetArgs {
|
||||
CacheValue value;
|
||||
TTL ttl_seconds;
|
||||
};
|
||||
|
||||
struct ListCreateArgs {
|
||||
CacheValueId element_kind;
|
||||
TTL ttl_seconds;
|
||||
};
|
||||
|
||||
struct ListIndexArgs {
|
||||
int64_t index;
|
||||
};
|
||||
|
||||
struct ListSetArgs {
|
||||
int64_t index;
|
||||
CacheValue value;
|
||||
};
|
||||
|
||||
struct ListInsertArgs {
|
||||
int64_t index;
|
||||
CacheValue value;
|
||||
};
|
||||
|
||||
struct ListPushBackArgs {
|
||||
CacheValue value;
|
||||
};
|
||||
|
||||
struct ListPushManyArgs {
|
||||
std::vector<CacheValue> values;
|
||||
bool replace_entire_list = false; // true => overwrite entire list, false => append
|
||||
};
|
||||
|
||||
using MessageArguments = std::variant<std::monostate,
|
||||
PrimitiveSetArgs,
|
||||
ListCreateArgs,
|
||||
ListIndexArgs,
|
||||
ListSetArgs,
|
||||
ListInsertArgs,
|
||||
ListPushBackArgs,
|
||||
ListPushManyArgs>;
|
||||
42
rediska/common/QueueMessage.hpp
Normal file
42
rediska/common/QueueMessage.hpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
#include "rediska/common/enums.hpp"
|
||||
#include "rediska/common/types.hpp"
|
||||
#include "rediska/common/MessageArguments.hpp"
|
||||
#include <grpcpp/grpcpp.h>
|
||||
#include <grpcpp/support/async_stream.h> // for ServerAsyncStreamingInterface completeness
|
||||
|
||||
// TODO: get rid of forward declaration somehow maybe
|
||||
struct BaseRequestManager;
|
||||
|
||||
struct RequestEvent {
|
||||
BaseRequestManager& manager;
|
||||
};
|
||||
|
||||
// This just leaves the responder for you to delete.
|
||||
struct FinishEvent {
|
||||
std::unique_ptr<grpc::internal::ServerAsyncStreamingInterface> responder;
|
||||
};
|
||||
|
||||
using EventVariant = std::variant<RequestEvent, FinishEvent>;
|
||||
|
||||
struct QueueMessage {
|
||||
CacheValueId type;
|
||||
CacheKey key;
|
||||
OperationId operation;
|
||||
MessageArguments arguments;
|
||||
std::unique_ptr<grpc::internal::ServerAsyncStreamingInterface> responder;
|
||||
|
||||
template<typename ResponseT>
|
||||
void respond(ResponseT response) {
|
||||
if (auto* writer = dynamic_cast<grpc::ServerAsyncResponseWriter<ResponseT>*>(responder.get())) {
|
||||
writer->Finish(response, grpc::Status::OK, std::make_unique<EventVariant>(FinishEvent { std::move(responder) }).release());
|
||||
responder = nullptr;
|
||||
} else {
|
||||
throw std::runtime_error("Invalid responder type in QueueMessage::respond");
|
||||
}
|
||||
}
|
||||
};
|
||||
13
rediska/common/enums.hpp
Normal file
13
rediska/common/enums.hpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
enum class OperationId {
|
||||
GET,
|
||||
SET,
|
||||
DELETE,
|
||||
LIST_PUSH_BACK,
|
||||
LIST_POP_BACK,
|
||||
LIST_INSERT,
|
||||
LIST_ERASE,
|
||||
OBJECT_GET_FIELD,
|
||||
OBJECT_SET_FIELD,
|
||||
};
|
||||
0
rediska/common/tmp.cpp
Normal file
0
rediska/common/tmp.cpp
Normal file
30
rediska/common/types.hpp
Normal file
30
rediska/common/types.hpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <variant>
|
||||
#include <chrono>
|
||||
#include "rediska/data-structures/impl/ListDataStructure.hpp"
|
||||
|
||||
using CacheKey = std::string;
|
||||
|
||||
// Definition order of `CacheValue` and `TypeId` MUST match!
|
||||
using CacheValue = std::variant<bool, int64_t, double, std::string, std::shared_ptr<ListDataStructure>>;
|
||||
|
||||
enum class CacheValueId { BOOLEAN = 0, INT, FLOAT, STRING, ARRAY }; // TODO: Object
|
||||
|
||||
enum class RediskaReturnCode {
|
||||
OK,
|
||||
INCOMPATIBLE_OPERATION,
|
||||
NOT_FOUND,
|
||||
KEY_EXPIRED,
|
||||
UNKNOWN_ERROR,
|
||||
DS_EMPTY,
|
||||
DS_OUT_OF_RANGE,
|
||||
DS_UNKNOWN_ERROR
|
||||
};
|
||||
|
||||
using TTL = uint32_t;
|
||||
|
||||
using Timestamp = std::chrono::steady_clock::time_point;
|
||||
24
rediska/common/utils.hpp
Normal file
24
rediska/common/utils.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <type_traits>
|
||||
#include "rediska/common/types.hpp"
|
||||
|
||||
template<typename T, typename... Ts>
|
||||
constexpr bool is_any_of_v = (std::is_same_v<T, Ts> || ...);
|
||||
|
||||
inline RediskaReturnCode DSReturnCodeToRediskaReturnCode(DSReturnCode code) {
|
||||
switch (code) {
|
||||
case DSReturnCode::OK:
|
||||
return RediskaReturnCode::OK;
|
||||
case DSReturnCode::NOT_FOUND:
|
||||
return RediskaReturnCode::NOT_FOUND;
|
||||
case DSReturnCode::INCOMPATIBLE_OPERATION:
|
||||
return RediskaReturnCode::INCOMPATIBLE_OPERATION;
|
||||
case DSReturnCode::EMPTY:
|
||||
return RediskaReturnCode::DS_EMPTY;
|
||||
case DSReturnCode::OUT_OF_RANGE:
|
||||
return RediskaReturnCode::DS_OUT_OF_RANGE;
|
||||
default:
|
||||
return RediskaReturnCode::UNKNOWN_ERROR;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user