Skip to content

Timeouts and Reconnect Strategy

Valkey GLIDE allows you to configure timeout settings and reconnect strategies. These configurations can be applied through the client configuration parameters.

Configuration SettingDescriptionDefault Value
Request TimeoutThis specified timeout duration represents the period during which the client will await the completion of a request. This includes the process of sending the request, waiting for a response from the node(s), and any necessary reconnection or retry attempts. If a pending request exceeds the specified timeout, it will trigger a timeout error. If no timeout value is explicitly set, a default value will be employed.250 milliseconds
Connection TimeoutThe duration in milliseconds to wait for a TCP/TLS connection to complete. This applies both during initial client creation and any reconnection that may occur during request processing. A high connection timeout may lead to prolonged blocking of the entire command pipeline. This is configured via the advanced client configuration.2000 milliseconds
Reconnect StrategyThe reconnection strategy defines how and when reconnection attempts are made in the event of connection failures.Exponential backoff

Setting Request Timeout for Long-Running Commands

Section titled “Setting Request Timeout for Long-Running Commands”
import glide.api.GlideClusterClient;
import glide.api.models.configuration.GlideClusterClientConfiguration;
import glide.api.models.configuration.NodeAddress;
GlideClusterClientConfiguration config = GlideClusterClientConfiguration.builder()
.address(NodeAddress.builder()
.host("address.example.com")
.port(6379).build())
.requestTimeout(500)
.build();
GlideClusterClient client = GlideClusterClient.createClient(config).get();

The connection timeout controls how long the client waits for a TCP/TLS connection to establish. This is separate from the request timeout and is configured via the advanced configuration.

import glide.api.GlideClusterClient;
import glide.api.models.configuration.AdvancedGlideClusterClientConfiguration;
import glide.api.models.configuration.GlideClusterClientConfiguration;
import glide.api.models.configuration.NodeAddress;
GlideClusterClientConfiguration config = GlideClusterClientConfiguration.builder()
.address(NodeAddress.builder()
.host("address.example.com")
.port(6379).build())
.advancedConfiguration(AdvancedGlideClusterClientConfiguration.builder()
.connectionTimeout(5000)
.build())
.build();
GlideClusterClient client = GlideClusterClient.createClient(config).get();

Reconnect delays use exponential backoff with optional jitter. numOfRetries, factor, and exponentBase must be non-negative 32-bit integers, and jitterPercent must be between 0 and 100. Invalid values fail client creation instead of being clamped. A factor or exponent base of zero uses the core default, while zero retries disables the finite retry phase. Jitter randomizes each calculated delay by up to the configured percentage, which helps prevent many clients from reconnecting at the same instant.

import glide.api.GlideClusterClient;
import glide.api.models.configuration.BackoffStrategy;
import glide.api.models.configuration.GlideClusterClientConfiguration;
import glide.api.models.configuration.NodeAddress;
GlideClusterClientConfiguration config = GlideClusterClientConfiguration.builder()
.address(NodeAddress.builder()
.host("address.example.com")
.port(6379).build())
.reconnectStrategy(BackoffStrategy.builder()
.numOfRetries(3)
.factor(2)
.exponentBase(2)
.jitterPercent(20)
.build())
.build();
GlideClusterClient client = GlideClusterClient.createClient(config).get();