From 3281aec3357777845f3899d159c2282f07715073 Mon Sep 17 00:00:00 2001 From: JackyWoo Date: Thu, 25 May 2023 17:12:56 +0800 Subject: [PATCH] make some redis engine args optional --- src/Storages/StorageRedis.cpp | 30 +++++++++++++++++++++--------- src/Storages/StorageRedis.h | 2 +- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/Storages/StorageRedis.cpp b/src/Storages/StorageRedis.cpp index 819ab01d733..0cc0e566d5c 100644 --- a/src/Storages/StorageRedis.cpp +++ b/src/Storages/StorageRedis.cpp @@ -166,6 +166,10 @@ SinkToStoragePtr StorageRedis::write( RedisConfiguration StorageRedis::getConfiguration(ASTs engine_args, ContextPtr context) { RedisConfiguration configuration; + configuration.db_index = 0; + configuration.password = ""; + configuration.storage_type = RedisStorageType::SIMPLE; + configuration.pool_size = 10; if (auto named_collection = tryGetNamedCollectionWithOverrides(engine_args, context)) { @@ -175,11 +179,15 @@ RedisConfiguration StorageRedis::getConfiguration(ASTs engine_args, ContextPtr c {}); configuration.host = named_collection->getAny({"host", "hostname"}); - configuration.port = static_cast(named_collection->get("port")); - configuration.password = named_collection->get("password"); - configuration.db_index = static_cast(named_collection->get({"db_index"})); - configuration.storage_type = parseStorageType(named_collection->getOrDefault("storage_type", "")); - configuration.pool_size = static_cast(named_collection->get("pool_size")); + configuration.port = static_cast(named_collection->getOrDefault("port", 6379)); + if (engine_args.size() > 1) + configuration.password = named_collection->get("password"); + if (engine_args.size() > 2) + configuration.db_index = static_cast(named_collection->get("db_index")); + if (engine_args.size() > 3) + configuration.storage_type = parseStorageType(named_collection->get("storage_type")); + if (engine_args.size() > 4) + configuration.pool_size = static_cast(named_collection->get("pool_size")); } else { @@ -191,10 +199,14 @@ RedisConfiguration StorageRedis::getConfiguration(ASTs engine_args, ContextPtr c configuration.host = parsed_host_port.first; configuration.port = parsed_host_port.second; - configuration.db_index = static_cast(checkAndGetLiteralArgument(engine_args[1], "db_index")); - configuration.password = checkAndGetLiteralArgument(engine_args[2], "password"); - configuration.storage_type = parseStorageType(checkAndGetLiteralArgument(engine_args[3], "storage_type")); - configuration.pool_size = static_cast(checkAndGetLiteralArgument(engine_args[4], "pool_size")); + if (engine_args.size() > 1) + configuration.db_index = static_cast(checkAndGetLiteralArgument(engine_args[1], "db_index")); + if (engine_args.size() > 2) + configuration.password = checkAndGetLiteralArgument(engine_args[2], "password"); + if (engine_args.size() > 3) + configuration.storage_type = parseStorageType(checkAndGetLiteralArgument(engine_args[3], "storage_type")); + if (engine_args.size() > 4) + configuration.pool_size = static_cast(checkAndGetLiteralArgument(engine_args[4], "pool_size")); } if (configuration.storage_type == RedisStorageType::UNKNOWN) diff --git a/src/Storages/StorageRedis.h b/src/Storages/StorageRedis.h index 2c6c6193982..1ae90b2d1ba 100644 --- a/src/Storages/StorageRedis.h +++ b/src/Storages/StorageRedis.h @@ -7,7 +7,7 @@ namespace DB { /* Implements storage in the Redis. - * Use ENGINE = Redis(host:port, db_index, password, storage_type, conn_pool_size); + * Use ENGINE = Redis(host:port, db_index, password, storage_type, pool_size); * Read only. * * Note If storage_type is