make some redis engine args optional

This commit is contained in:
JackyWoo 2023-05-25 17:12:56 +08:00
parent 412d9ba259
commit 3281aec335
2 changed files with 22 additions and 10 deletions

View File

@ -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,10 +179,14 @@ RedisConfiguration StorageRedis::getConfiguration(ASTs engine_args, ContextPtr c
{});
configuration.host = named_collection->getAny<String>({"host", "hostname"});
configuration.port = static_cast<uint32_t>(named_collection->get<UInt64>("port"));
configuration.port = static_cast<uint32_t>(named_collection->getOrDefault<UInt64>("port", 6379));
if (engine_args.size() > 1)
configuration.password = named_collection->get<String>("password");
configuration.db_index = static_cast<uint32_t>(named_collection->get<UInt64>({"db_index"}));
configuration.storage_type = parseStorageType(named_collection->getOrDefault<String>("storage_type", ""));
if (engine_args.size() > 2)
configuration.db_index = static_cast<uint32_t>(named_collection->get<UInt64>("db_index"));
if (engine_args.size() > 3)
configuration.storage_type = parseStorageType(named_collection->get<String>("storage_type"));
if (engine_args.size() > 4)
configuration.pool_size = static_cast<uint32_t>(named_collection->get<UInt64>("pool_size"));
}
else
@ -191,9 +199,13 @@ RedisConfiguration StorageRedis::getConfiguration(ASTs engine_args, ContextPtr c
configuration.host = parsed_host_port.first;
configuration.port = parsed_host_port.second;
if (engine_args.size() > 1)
configuration.db_index = static_cast<uint32_t>(checkAndGetLiteralArgument<UInt64>(engine_args[1], "db_index"));
if (engine_args.size() > 2)
configuration.password = checkAndGetLiteralArgument<String>(engine_args[2], "password");
if (engine_args.size() > 3)
configuration.storage_type = parseStorageType(checkAndGetLiteralArgument<String>(engine_args[3], "storage_type"));
if (engine_args.size() > 4)
configuration.pool_size = static_cast<uint32_t>(checkAndGetLiteralArgument<UInt64>(engine_args[4], "pool_size"));
}

View File

@ -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