ClickHouse/src/Storages/StorageRedis.h

84 lines
2.7 KiB
C++
Raw Normal View History

2023-05-17 02:42:52 +00:00
#pragma once
#include <Poco/Redis/Redis.h>
#include <Storages/IStorage.h>
2023-05-30 12:31:23 +00:00
#include <Storages/RedisCommon.h>
#include <Interpreters/IKeyValueEntity.h>
#include <Interpreters/Context_fwd.h>
#include <Storages/MutationCommands.h>
2023-05-17 02:42:52 +00:00
namespace DB
{
/* Implements storage in the Redis.
2023-05-30 12:31:23 +00:00
* Use ENGINE = Redis(host:port[, db_index[, password[, pool_size]]]) PRIMARY KEY(key);
2023-05-17 02:42:52 +00:00
*/
2023-05-30 12:31:23 +00:00
class StorageRedis : public IStorage, public IKeyValueEntity, WithContext
2023-05-17 02:42:52 +00:00
{
public:
StorageRedis(
const StorageID & table_id_,
2023-05-20 03:48:57 +00:00
const RedisConfiguration & configuration_,
2023-05-30 12:31:23 +00:00
ContextPtr context_,
const StorageInMemoryMetadata & storage_metadata,
const String & primary_key_);
2023-05-17 02:42:52 +00:00
std::string getName() const override { return "Redis"; }
Pipe read(
const Names & column_names,
const StorageSnapshotPtr & storage_snapshot,
SelectQueryInfo & query_info,
2023-05-30 12:31:23 +00:00
ContextPtr context_,
2023-05-17 02:42:52 +00:00
QueryProcessingStage::Enum processed_stage,
size_t max_block_size,
size_t num_streams) override;
SinkToStoragePtr write(
const ASTPtr & query,
const StorageMetadataPtr & /*metadata_snapshot*/,
2023-06-12 02:15:32 +00:00
ContextPtr context,
bool /*async_insert*/) override;
2023-05-17 02:42:52 +00:00
void truncate(const ASTPtr &,
const StorageMetadataPtr & metadata_snapshot,
ContextPtr,
TableExclusiveLockHolder &) override;
void checkMutationIsPossible(const MutationCommands & commands, const Settings & settings) const override;
void mutate(const MutationCommands &, ContextPtr) override;
2023-05-30 12:31:23 +00:00
Names getPrimaryKey() const override { return {primary_key}; }
/// Return chunk with data for given serialized keys.
/// If out_null_map is passed, fill it with 1/0 depending on key was/wasn't found. Result chunk may contain default values.
/// If out_null_map is not passed. Not found rows excluded from result chunk.
Chunk getBySerializedKeys(
const std::vector<std::string> & keys,
PaddedPODArray<UInt8> * out_null_map) const;
Chunk getBySerializedKeys(
const RedisArray & keys,
PaddedPODArray<UInt8> * out_null_map) const;
std::pair<RedisIterator, RedisArray> scan(RedisIterator iterator, const String & pattern, uint64_t max_count);
2023-05-30 12:31:23 +00:00
RedisArray multiGet(const RedisArray & keys) const;
void multiSet(const RedisArray & data) const;
RedisInteger multiDelete(const RedisArray & keys) const;
2023-05-30 12:31:23 +00:00
Chunk getByKeys(const ColumnsWithTypeAndName & keys, PaddedPODArray<UInt8> & null_map, const Names &) const override;
Block getSampleBlock(const Names &) const override;
2023-05-17 02:42:52 +00:00
private:
StorageID table_id;
2023-05-20 03:48:57 +00:00
RedisConfiguration configuration;
2024-01-23 17:04:50 +00:00
LoggerPtr log;
2023-05-20 03:48:57 +00:00
RedisPoolPtr pool;
2023-05-30 12:31:23 +00:00
const String primary_key;
2023-05-17 02:42:52 +00:00
};
}