Add operation_timeout and command_timeout storage backend options

This commit is contained in:
Tim Wojtulewicz 2025-04-30 12:36:02 -07:00
parent 507974a1d8
commit 824b91216f
5 changed files with 22 additions and 6 deletions

View file

@ -262,7 +262,8 @@ OperationResult Redis::DoOpen(OpenResultCallback* cb, RecordValPtr options) {
opt.options |= REDIS_OPT_PREFER_IPV4;
opt.options |= REDIS_OPT_NOAUTOFREEREPLIES;
struct timeval timeout = {5, 0};
auto connect_timeout_opt = options->GetField<IntervalVal>("connect_timeout")->Get();
struct timeval timeout = util::double_to_timeval(connect_timeout_opt);
opt.connect_timeout = &timeout;
// The connection request below should be operation #1.
@ -300,6 +301,10 @@ OperationResult Redis::DoOpen(OpenResultCallback* cb, RecordValPtr options) {
redisAsyncSetConnectCallback(async_ctx, redisOnConnect);
redisAsyncSetDisconnectCallback(async_ctx, redisOnDisconnect);
auto op_timeout_opt = options->GetField<IntervalVal>("operation_timeout")->Get();
struct timeval op_timeout = util::double_to_timeval(op_timeout_opt);
redisAsyncSetTimeout(async_ctx, op_timeout);
// redisAsyncSetConnectCallback sets the flag in the redisPollEvent for writing
// so we can add this to our loop as well.
zeek::iosource_mgr->RegisterFd(async_ctx->c.fd, this, zeek::iosource::IOSource::WRITE);