ClickHouse/src/Storages/StorageRedis.h

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

71 lines
2.2 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>
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*/,
ContextPtr context) 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, const uint64_t max_count);
RedisArray multiGet(const RedisArray & keys) const;
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;
2023-05-23 07:31:50 +00:00
Poco::Logger * 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
};
}