ClickHouse/src/Storages/RedisCommon.h

84 lines
1.9 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>
#include <Core/Defines.h>
#include <base/BorrowedObjectPool.h>
namespace DB
{
namespace ErrorCodes
{
extern const int NOT_IMPLEMENTED;
}
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,
/// Redis map field
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;
2023-05-23 07:31:50 +00:00
/// column name of redis key
String key;// TODO remove
2023-05-20 03:48:57 +00:00
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
}