ClickHouse/src/Storages/RedisCommon.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

79 lines
2.0 KiB
C++
Raw Normal View History

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>
2023-06-01 11:28:13 +00:00
#include <Poco/Types.h>
2023-05-20 03:48:57 +00:00
#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-30 12:31:23 +00:00
#include <Storages/StorageFactory.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
2023-05-24 10:06:42 +00:00
/// storage type to Redis key type
2023-05-25 04:33:07 +00:00
String storageTypeToKeyType(RedisStorageType type);
2023-05-24 10:06:42 +00:00
RedisStorageType parseStorageType(const String & storage_type_str);
String serializeStorageType(RedisStorageType storage_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;
};
2023-05-30 12:31:23 +00:00
static uint32_t DEFAULT_REDIS_DB_INDEX = 0;
static uint32_t DEFAULT_REDIS_POOL_SIZE = 16;
static String DEFAULT_REDIS_PASSWORD;
using RedisCommand = Poco::Redis::Command;
2023-05-20 03:48:57 +00:00
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 RedisBulkString = Poco::Redis::BulkString;
using RedisSimpleString = String;
2023-06-01 11:28:13 +00:00
using RedisInteger = Poco::Int64;
2023-05-20 03:48:57 +00:00
using RedisClientPtr = std::unique_ptr<Poco::Redis::Client>;
using RedisPool = BorrowedObjectPool<RedisClientPtr>;
using RedisPoolPtr = std::shared_ptr<RedisPool>;
2023-05-31 10:15:38 +00:00
/// Redis scan iterator
2023-05-30 12:31:23 +00:00
using RedisIterator = int64_t;
2023-05-20 03:48:57 +00:00
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
}