2023-05-20 03:48:57 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Poco/Redis/Client.h>
|
|
|
|
#include <Poco/Redis/Command.h>
|
|
|
|
#include <Poco/Redis/Array.h>
|
|
|
|
|
|
|
|
#include <Core/Defines.h>
|
|
|
|
#include <base/BorrowedObjectPool.h>
|
2023-05-23 08:42:46 +00:00
|
|
|
#include <Core/Names.h>
|
2023-05-23 12:54:26 +00:00
|
|
|
#include <Storages/ColumnsDescription.h>
|
2023-05-20 03:48:57 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
static constexpr size_t REDIS_MAX_BLOCK_SIZE = DEFAULT_BLOCK_SIZE;
|
|
|
|
static constexpr size_t REDIS_LOCK_ACQUIRE_TIMEOUT_MS = 5000;
|
|
|
|
|
|
|
|
enum class RedisStorageType
|
|
|
|
{
|
|
|
|
SIMPLE,
|
|
|
|
HASH_MAP,
|
|
|
|
UNKNOWN
|
|
|
|
};
|
|
|
|
|
2023-05-23 07:31:50 +00:00
|
|
|
enum class RedisColumnType
|
|
|
|
{
|
|
|
|
/// Redis key
|
|
|
|
KEY,
|
2023-05-23 08:42:46 +00:00
|
|
|
/// Redis hash field
|
2023-05-23 07:31:50 +00:00
|
|
|
FIELD,
|
|
|
|
/// Redis value
|
|
|
|
VALUE
|
|
|
|
};
|
|
|
|
|
|
|
|
using RedisColumnTypes = std::vector<RedisColumnType>;
|
|
|
|
|
|
|
|
extern RedisColumnTypes REDIS_HASH_MAP_COLUMN_TYPES;
|
|
|
|
extern RedisColumnTypes REDIS_SIMPLE_COLUMN_TYPES;
|
|
|
|
|
|
|
|
String storageTypeToKeyType(RedisStorageType storage_type);
|
|
|
|
RedisStorageType keyTypeToStorageType(const String & key_type);
|
2023-05-20 03:48:57 +00:00
|
|
|
|
|
|
|
struct RedisConfiguration
|
|
|
|
{
|
|
|
|
String host;
|
|
|
|
uint32_t port;
|
|
|
|
uint32_t db_index;
|
|
|
|
String password;
|
|
|
|
RedisStorageType storage_type;
|
|
|
|
uint32_t pool_size;
|
|
|
|
};
|
|
|
|
|
|
|
|
using RedisArray = Poco::Redis::Array;
|
2023-05-23 07:31:50 +00:00
|
|
|
using RedisArrayPtr = std::shared_ptr<RedisArray>;
|
2023-05-20 03:48:57 +00:00
|
|
|
using RedisCommand = Poco::Redis::Command;
|
|
|
|
using RedisBulkString = Poco::Redis::BulkString;
|
|
|
|
|
|
|
|
using RedisClientPtr = std::unique_ptr<Poco::Redis::Client>;
|
|
|
|
using RedisPool = BorrowedObjectPool<RedisClientPtr>;
|
|
|
|
using RedisPoolPtr = std::shared_ptr<RedisPool>;
|
|
|
|
|
|
|
|
struct RedisConnection
|
|
|
|
{
|
|
|
|
RedisConnection(RedisPoolPtr pool_, RedisClientPtr client_);
|
|
|
|
~RedisConnection();
|
|
|
|
|
|
|
|
RedisPoolPtr pool;
|
|
|
|
RedisClientPtr client;
|
|
|
|
};
|
|
|
|
|
|
|
|
using RedisConnectionPtr = std::unique_ptr<RedisConnection>;
|
|
|
|
|
2023-05-23 07:31:50 +00:00
|
|
|
RedisConnectionPtr getRedisConnection(RedisPoolPtr pool, const RedisConfiguration & configuration);
|
|
|
|
|
|
|
|
///get all redis hash key array
|
|
|
|
/// eg: keys -> [key1, key2] and get [[key1, field1, field2], [key2, field1, field2]]
|
|
|
|
RedisArrayPtr getRedisHashMapKeys(const RedisConnectionPtr & connection, RedisArray & keys);
|
2023-05-20 03:48:57 +00:00
|
|
|
|
2023-05-23 08:42:46 +00:00
|
|
|
/// Get RedisColumnType of a column, If storage_type is
|
2023-05-24 02:45:21 +00:00
|
|
|
/// SIMPLE: all_columns must have 2 items and the first one is Redis key the second one is value
|
|
|
|
/// HASH_MAP: all_columns must have 2 items and the first one is Redis key the second is field, the third is value.
|
2023-05-23 08:42:46 +00:00
|
|
|
RedisColumnType getRedisColumnType(RedisStorageType storage_type, const Names & all_columns, const String & column);
|
2023-05-23 12:54:26 +00:00
|
|
|
|
|
|
|
/// checking Redis table/table-function when creating
|
|
|
|
void checkRedisTableStructure(const ColumnsDescription & columns, const RedisConfiguration & configuration);
|
|
|
|
|
2023-05-20 03:48:57 +00:00
|
|
|
}
|