///|
/// Connection and runtime options for `Client`.
///
/// The default configuration connects to `127.0.0.1:6379`, authenticates as the
/// Redis `default` user when a password is provided, uses database `0`, and
/// retries reconnects with exponential backoff.
///
/// Example:
/// ```moonbit nocheck
/// let config = @redis.ClientConfig(host="127.0.0.1", port=6379, password="secret")
///
/// let client = @redis.Client(config~)
/// ```
pub struct ClientConfig {
/// Optional client name sent with `CLIENT SETNAME` after connecting.
name : String?
/// Redis server host.
host : String
/// Redis server TCP port.
port : Int
/// ACL username used when `password` is set.
username : String
/// Optional password used during connection handshake.
password : String?
/// Redis logical database selected after connecting.
database : Int
/// Read buffer size in bytes.
read_buffer_size : Int
/// Write buffer size in bytes.
write_buffer_size : Int
/// Maximum nested Redis response depth accepted by the client.
resp_max_depth : Int
/// TCP connect timeout in seconds.
connect_timeout : Double
/// Reconnect policy used by `Client::work`.
reconnect_strategy : @async.RetryMethod
/// Optional maximum number of commands waiting to be processed.
command_queue_max_length : Int?
}
///|
/// Creates a `ClientConfig`, using Redis-compatible local defaults for omitted
/// options.
///
/// Example:
/// ```moonbit nocheck
/// let config = @redis.ClientConfig(database=1, name="worker-1")
/// ```
pub fn ClientConfig::ClientConfig(
name? : String,
host? : String = "127.0.0.1",
port? : Int = 6379,
username? : String = "default",
password? : String,
database? : Int = 0,
read_buffer_size? : Int = 4096,
write_buffer_size? : Int = 4096,
resp_max_depth? : Int = 128,
connect_timeout? : Double = 5.0,
reconnect_strategy? : @async.RetryMethod = ExponentialDelay(
initial=100,
factor=2.0,
maximum=2000,
),
command_queue_max_length? : Int,
) -> ClientConfig {
{
name,
host,
port,
username,
password,
database,
read_buffer_size,
write_buffer_size,
resp_max_depth,
connect_timeout,
reconnect_strategy,
command_queue_max_length,
}
}