use std::collections::HashMap;
use std::path::PathBuf;
use std::time::Duration;
use tokio::runtime::Runtime;
use crate::error::Result;
use crate::server::{AppendFsync, LogLevel, ReplDisklessLoad};
use crate::{cli, cluster, sentinel, server};
pub struct RedisCli {
inner: cli::RedisCli,
}
impl RedisCli {
pub fn new() -> Self {
Self {
inner: cli::RedisCli::new(),
}
}
pub fn bin(mut self, bin: impl Into<String>) -> Self {
self.inner = self.inner.bin(bin);
self
}
pub fn host(mut self, host: impl Into<String>) -> Self {
self.inner = self.inner.host(host);
self
}
pub fn port(mut self, port: u16) -> Self {
self.inner = self.inner.port(port);
self
}
pub fn password(mut self, password: impl Into<String>) -> Self {
self.inner = self.inner.password(password);
self
}
pub fn user(mut self, user: impl Into<String>) -> Self {
self.inner = self.inner.user(user);
self
}
pub fn db(mut self, db: u32) -> Self {
self.inner = self.inner.db(db);
self
}
pub fn unixsocket(mut self, path: impl Into<PathBuf>) -> Self {
self.inner = self.inner.unixsocket(path);
self
}
pub fn tls(mut self, enable: bool) -> Self {
self.inner = self.inner.tls(enable);
self
}
pub fn sni(mut self, hostname: impl Into<String>) -> Self {
self.inner = self.inner.sni(hostname);
self
}
pub fn cacert(mut self, path: impl Into<PathBuf>) -> Self {
self.inner = self.inner.cacert(path);
self
}
pub fn cacertdir(mut self, path: impl Into<PathBuf>) -> Self {
self.inner = self.inner.cacertdir(path);
self
}
pub fn cert(mut self, path: impl Into<PathBuf>) -> Self {
self.inner = self.inner.cert(path);
self
}
pub fn key(mut self, path: impl Into<PathBuf>) -> Self {
self.inner = self.inner.key(path);
self
}
pub fn insecure(mut self, enable: bool) -> Self {
self.inner = self.inner.insecure(enable);
self
}
pub fn tls_ciphers(mut self, ciphers: impl Into<String>) -> Self {
self.inner = self.inner.tls_ciphers(ciphers);
self
}
pub fn tls_ciphersuites(mut self, ciphersuites: impl Into<String>) -> Self {
self.inner = self.inner.tls_ciphersuites(ciphersuites);
self
}
pub fn resp(mut self, protocol: cli::RespProtocol) -> Self {
self.inner = self.inner.resp(protocol);
self
}
pub fn cluster_mode(mut self, enable: bool) -> Self {
self.inner = self.inner.cluster_mode(enable);
self
}
pub fn output_format(mut self, format: cli::OutputFormat) -> Self {
self.inner = self.inner.output_format(format);
self
}
pub fn no_auth_warning(mut self, suppress: bool) -> Self {
self.inner = self.inner.no_auth_warning(suppress);
self
}
pub fn uri(mut self, uri: impl Into<String>) -> Self {
self.inner = self.inner.uri(uri);
self
}
pub fn timeout(mut self, seconds: f64) -> Self {
self.inner = self.inner.timeout(seconds);
self
}
pub fn askpass(mut self, enable: bool) -> Self {
self.inner = self.inner.askpass(enable);
self
}
pub fn client_name(mut self, name: impl Into<String>) -> Self {
self.inner = self.inner.client_name(name);
self
}
pub fn ip_preference(mut self, preference: cli::IpPreference) -> Self {
self.inner = self.inner.ip_preference(preference);
self
}
pub fn repeat(mut self, count: u32) -> Self {
self.inner = self.inner.repeat(count);
self
}
pub fn interval(mut self, seconds: f64) -> Self {
self.inner = self.inner.interval(seconds);
self
}
pub fn stdin_last_arg(mut self, enable: bool) -> Self {
self.inner = self.inner.stdin_last_arg(enable);
self
}
pub fn stdin_tag_arg(mut self, enable: bool) -> Self {
self.inner = self.inner.stdin_tag_arg(enable);
self
}
pub fn multi_bulk_delimiter(mut self, delim: impl Into<String>) -> Self {
self.inner = self.inner.multi_bulk_delimiter(delim);
self
}
pub fn output_delimiter(mut self, delim: impl Into<String>) -> Self {
self.inner = self.inner.output_delimiter(delim);
self
}
pub fn exit_error_code(mut self, enable: bool) -> Self {
self.inner = self.inner.exit_error_code(enable);
self
}
pub fn no_raw(mut self, enable: bool) -> Self {
self.inner = self.inner.no_raw(enable);
self
}
pub fn quoted_input(mut self, enable: bool) -> Self {
self.inner = self.inner.quoted_input(enable);
self
}
pub fn show_pushes(mut self, enable: bool) -> Self {
self.inner = self.inner.show_pushes(enable);
self
}
pub fn stat(mut self, enable: bool) -> Self {
self.inner = self.inner.stat(enable);
self
}
pub fn latency(mut self, enable: bool) -> Self {
self.inner = self.inner.latency(enable);
self
}
pub fn latency_history(mut self, enable: bool) -> Self {
self.inner = self.inner.latency_history(enable);
self
}
pub fn latency_dist(mut self, enable: bool) -> Self {
self.inner = self.inner.latency_dist(enable);
self
}
pub fn bigkeys(mut self, enable: bool) -> Self {
self.inner = self.inner.bigkeys(enable);
self
}
pub fn memkeys(mut self, enable: bool) -> Self {
self.inner = self.inner.memkeys(enable);
self
}
pub fn memkeys_samples(mut self, n: u32) -> Self {
self.inner = self.inner.memkeys_samples(n);
self
}
pub fn keystats(mut self, enable: bool) -> Self {
self.inner = self.inner.keystats(enable);
self
}
pub fn keystats_samples(mut self, n: u32) -> Self {
self.inner = self.inner.keystats_samples(n);
self
}
pub fn hotkeys(mut self, enable: bool) -> Self {
self.inner = self.inner.hotkeys(enable);
self
}
pub fn scan(mut self, enable: bool) -> Self {
self.inner = self.inner.scan(enable);
self
}
pub fn pattern(mut self, pat: impl Into<String>) -> Self {
self.inner = self.inner.pattern(pat);
self
}
pub fn count(mut self, n: u32) -> Self {
self.inner = self.inner.count(n);
self
}
pub fn quoted_pattern(mut self, pat: impl Into<String>) -> Self {
self.inner = self.inner.quoted_pattern(pat);
self
}
pub fn cursor(mut self, n: u64) -> Self {
self.inner = self.inner.cursor(n);
self
}
pub fn top(mut self, n: u32) -> Self {
self.inner = self.inner.top(n);
self
}
pub fn intrinsic_latency(mut self, seconds: u32) -> Self {
self.inner = self.inner.intrinsic_latency(seconds);
self
}
pub fn lru_test(mut self, keys: u64) -> Self {
self.inner = self.inner.lru_test(keys);
self
}
pub fn verbose(mut self, enable: bool) -> Self {
self.inner = self.inner.verbose(enable);
self
}
pub fn eval_file(mut self, path: impl Into<PathBuf>) -> Self {
self.inner = self.inner.eval_file(path);
self
}
pub fn ldb(mut self, enable: bool) -> Self {
self.inner = self.inner.ldb(enable);
self
}
pub fn ldb_sync_mode(mut self, enable: bool) -> Self {
self.inner = self.inner.ldb_sync_mode(enable);
self
}
pub fn pipe(mut self, enable: bool) -> Self {
self.inner = self.inner.pipe(enable);
self
}
pub fn pipe_timeout(mut self, seconds: u32) -> Self {
self.inner = self.inner.pipe_timeout(seconds);
self
}
pub fn rdb(mut self, path: impl Into<PathBuf>) -> Self {
self.inner = self.inner.rdb(path);
self
}
pub fn functions_rdb(mut self, path: impl Into<PathBuf>) -> Self {
self.inner = self.inner.functions_rdb(path);
self
}
pub fn replica(mut self, enable: bool) -> Self {
self.inner = self.inner.replica(enable);
self
}
pub fn cluster_command(&self, command: &str, args: &[&str]) -> Result<String> {
Runtime::new()?.block_on(self.inner.cluster_command(command, args))
}
pub fn run(&self, args: &[&str]) -> Result<String> {
Runtime::new()?.block_on(self.inner.run(args))
}
pub fn ping(&self) -> bool {
Runtime::new()
.map(|rt| rt.block_on(self.inner.ping()))
.unwrap_or(false)
}
pub fn wait_for_ready(&self, timeout: Duration) -> Result<()> {
Runtime::new()?.block_on(self.inner.wait_for_ready(timeout))
}
}
impl Default for RedisCli {
fn default() -> Self {
Self::new()
}
}
pub struct RedisServer {
inner: server::RedisServer,
}
impl RedisServer {
pub fn new() -> Self {
Self {
inner: server::RedisServer::new(),
}
}
pub fn port(mut self, port: u16) -> Self {
self.inner = self.inner.port(port);
self
}
pub fn bind(mut self, bind: impl Into<String>) -> Self {
self.inner = self.inner.bind(bind);
self
}
pub fn protected_mode(mut self, protected: bool) -> Self {
self.inner = self.inner.protected_mode(protected);
self
}
pub fn tcp_backlog(mut self, backlog: u32) -> Self {
self.inner = self.inner.tcp_backlog(backlog);
self
}
pub fn unixsocket(mut self, path: impl Into<PathBuf>) -> Self {
self.inner = self.inner.unixsocket(path);
self
}
pub fn unixsocketperm(mut self, perm: u32) -> Self {
self.inner = self.inner.unixsocketperm(perm);
self
}
pub fn timeout(mut self, seconds: u32) -> Self {
self.inner = self.inner.timeout(seconds);
self
}
pub fn tcp_keepalive(mut self, seconds: u32) -> Self {
self.inner = self.inner.tcp_keepalive(seconds);
self
}
pub fn tls_port(mut self, port: u16) -> Self {
self.inner = self.inner.tls_port(port);
self
}
pub fn tls_cert_file(mut self, path: impl Into<PathBuf>) -> Self {
self.inner = self.inner.tls_cert_file(path);
self
}
pub fn tls_key_file(mut self, path: impl Into<PathBuf>) -> Self {
self.inner = self.inner.tls_key_file(path);
self
}
pub fn tls_ca_cert_file(mut self, path: impl Into<PathBuf>) -> Self {
self.inner = self.inner.tls_ca_cert_file(path);
self
}
pub fn tls_auth_clients(mut self, require: bool) -> Self {
self.inner = self.inner.tls_auth_clients(require);
self
}
pub fn tls_key_file_pass(mut self, pass: impl Into<String>) -> Self {
self.inner = self.inner.tls_key_file_pass(pass);
self
}
pub fn tls_ca_cert_dir(mut self, path: impl Into<PathBuf>) -> Self {
self.inner = self.inner.tls_ca_cert_dir(path);
self
}
pub fn tls_client_cert_file(mut self, path: impl Into<PathBuf>) -> Self {
self.inner = self.inner.tls_client_cert_file(path);
self
}
pub fn tls_client_key_file(mut self, path: impl Into<PathBuf>) -> Self {
self.inner = self.inner.tls_client_key_file(path);
self
}
pub fn tls_client_key_file_pass(mut self, pass: impl Into<String>) -> Self {
self.inner = self.inner.tls_client_key_file_pass(pass);
self
}
pub fn tls_dh_params_file(mut self, path: impl Into<PathBuf>) -> Self {
self.inner = self.inner.tls_dh_params_file(path);
self
}
pub fn tls_ciphers(mut self, ciphers: impl Into<String>) -> Self {
self.inner = self.inner.tls_ciphers(ciphers);
self
}
pub fn tls_ciphersuites(mut self, suites: impl Into<String>) -> Self {
self.inner = self.inner.tls_ciphersuites(suites);
self
}
pub fn tls_protocols(mut self, protocols: impl Into<String>) -> Self {
self.inner = self.inner.tls_protocols(protocols);
self
}
pub fn tls_prefer_server_ciphers(mut self, prefer: bool) -> Self {
self.inner = self.inner.tls_prefer_server_ciphers(prefer);
self
}
pub fn tls_session_caching(mut self, enable: bool) -> Self {
self.inner = self.inner.tls_session_caching(enable);
self
}
pub fn tls_session_cache_size(mut self, size: u32) -> Self {
self.inner = self.inner.tls_session_cache_size(size);
self
}
pub fn tls_session_cache_timeout(mut self, seconds: u32) -> Self {
self.inner = self.inner.tls_session_cache_timeout(seconds);
self
}
pub fn tls_replication(mut self, enable: bool) -> Self {
self.inner = self.inner.tls_replication(enable);
self
}
pub fn tls_cluster(mut self, enable: bool) -> Self {
self.inner = self.inner.tls_cluster(enable);
self
}
pub fn dir(mut self, dir: impl Into<PathBuf>) -> Self {
self.inner = self.inner.dir(dir);
self
}
pub fn loglevel(mut self, level: LogLevel) -> Self {
self.inner = self.inner.loglevel(level);
self
}
pub fn logfile(mut self, path: impl Into<String>) -> Self {
self.inner = self.inner.logfile(path);
self
}
pub fn databases(mut self, n: u32) -> Self {
self.inner = self.inner.databases(n);
self
}
pub fn maxmemory(mut self, limit: impl Into<String>) -> Self {
self.inner = self.inner.maxmemory(limit);
self
}
pub fn maxmemory_policy(mut self, policy: impl Into<String>) -> Self {
self.inner = self.inner.maxmemory_policy(policy);
self
}
pub fn maxclients(mut self, n: u32) -> Self {
self.inner = self.inner.maxclients(n);
self
}
pub fn save(mut self, save: bool) -> Self {
self.inner = self.inner.save(save);
self
}
pub fn save_schedule(mut self, schedule: Vec<(u64, u64)>) -> Self {
self.inner = self.inner.save_schedule(schedule);
self
}
pub fn appendonly(mut self, appendonly: bool) -> Self {
self.inner = self.inner.appendonly(appendonly);
self
}
pub fn appendfsync(mut self, policy: AppendFsync) -> Self {
self.inner = self.inner.appendfsync(policy);
self
}
pub fn appendfilename(mut self, name: impl Into<String>) -> Self {
self.inner = self.inner.appendfilename(name);
self
}
pub fn appenddirname(mut self, name: impl Into<PathBuf>) -> Self {
self.inner = self.inner.appenddirname(name);
self
}
pub fn aof_use_rdb_preamble(mut self, enable: bool) -> Self {
self.inner = self.inner.aof_use_rdb_preamble(enable);
self
}
pub fn aof_load_truncated(mut self, enable: bool) -> Self {
self.inner = self.inner.aof_load_truncated(enable);
self
}
pub fn aof_load_corrupt_tail_max_size(mut self, size: impl Into<String>) -> Self {
self.inner = self.inner.aof_load_corrupt_tail_max_size(size);
self
}
pub fn aof_rewrite_incremental_fsync(mut self, enable: bool) -> Self {
self.inner = self.inner.aof_rewrite_incremental_fsync(enable);
self
}
pub fn aof_timestamp_enabled(mut self, enable: bool) -> Self {
self.inner = self.inner.aof_timestamp_enabled(enable);
self
}
pub fn auto_aof_rewrite_percentage(mut self, pct: u32) -> Self {
self.inner = self.inner.auto_aof_rewrite_percentage(pct);
self
}
pub fn auto_aof_rewrite_min_size(mut self, size: impl Into<String>) -> Self {
self.inner = self.inner.auto_aof_rewrite_min_size(size);
self
}
pub fn no_appendfsync_on_rewrite(mut self, enable: bool) -> Self {
self.inner = self.inner.no_appendfsync_on_rewrite(enable);
self
}
pub fn replicaof(mut self, host: impl Into<String>, port: u16) -> Self {
self.inner = self.inner.replicaof(host, port);
self
}
pub fn masterauth(mut self, password: impl Into<String>) -> Self {
self.inner = self.inner.masterauth(password);
self
}
pub fn masteruser(mut self, user: impl Into<String>) -> Self {
self.inner = self.inner.masteruser(user);
self
}
pub fn repl_backlog_size(mut self, size: impl Into<String>) -> Self {
self.inner = self.inner.repl_backlog_size(size);
self
}
pub fn repl_backlog_ttl(mut self, seconds: u32) -> Self {
self.inner = self.inner.repl_backlog_ttl(seconds);
self
}
pub fn repl_disable_tcp_nodelay(mut self, disable: bool) -> Self {
self.inner = self.inner.repl_disable_tcp_nodelay(disable);
self
}
pub fn repl_diskless_load(mut self, policy: ReplDisklessLoad) -> Self {
self.inner = self.inner.repl_diskless_load(policy);
self
}
pub fn repl_diskless_sync(mut self, enable: bool) -> Self {
self.inner = self.inner.repl_diskless_sync(enable);
self
}
pub fn repl_diskless_sync_delay(mut self, seconds: u32) -> Self {
self.inner = self.inner.repl_diskless_sync_delay(seconds);
self
}
pub fn repl_diskless_sync_max_replicas(mut self, n: u32) -> Self {
self.inner = self.inner.repl_diskless_sync_max_replicas(n);
self
}
pub fn repl_ping_replica_period(mut self, seconds: u32) -> Self {
self.inner = self.inner.repl_ping_replica_period(seconds);
self
}
pub fn repl_timeout(mut self, seconds: u32) -> Self {
self.inner = self.inner.repl_timeout(seconds);
self
}
pub fn replica_announce_ip(mut self, ip: impl Into<String>) -> Self {
self.inner = self.inner.replica_announce_ip(ip);
self
}
pub fn replica_announce_port(mut self, port: u16) -> Self {
self.inner = self.inner.replica_announce_port(port);
self
}
pub fn replica_announced(mut self, announced: bool) -> Self {
self.inner = self.inner.replica_announced(announced);
self
}
pub fn replica_full_sync_buffer_limit(mut self, size: impl Into<String>) -> Self {
self.inner = self.inner.replica_full_sync_buffer_limit(size);
self
}
pub fn replica_ignore_disk_write_errors(mut self, ignore: bool) -> Self {
self.inner = self.inner.replica_ignore_disk_write_errors(ignore);
self
}
pub fn replica_ignore_maxmemory(mut self, ignore: bool) -> Self {
self.inner = self.inner.replica_ignore_maxmemory(ignore);
self
}
pub fn replica_lazy_flush(mut self, enable: bool) -> Self {
self.inner = self.inner.replica_lazy_flush(enable);
self
}
pub fn replica_priority(mut self, priority: u32) -> Self {
self.inner = self.inner.replica_priority(priority);
self
}
pub fn replica_read_only(mut self, read_only: bool) -> Self {
self.inner = self.inner.replica_read_only(read_only);
self
}
pub fn replica_serve_stale_data(mut self, serve: bool) -> Self {
self.inner = self.inner.replica_serve_stale_data(serve);
self
}
pub fn min_replicas_to_write(mut self, n: u32) -> Self {
self.inner = self.inner.min_replicas_to_write(n);
self
}
pub fn min_replicas_max_lag(mut self, seconds: u32) -> Self {
self.inner = self.inner.min_replicas_max_lag(seconds);
self
}
pub fn password(mut self, password: impl Into<String>) -> Self {
self.inner = self.inner.password(password);
self
}
pub fn acl_file(mut self, path: impl Into<PathBuf>) -> Self {
self.inner = self.inner.acl_file(path);
self
}
pub fn cluster_enabled(mut self, enabled: bool) -> Self {
self.inner = self.inner.cluster_enabled(enabled);
self
}
pub fn cluster_node_timeout(mut self, ms: u64) -> Self {
self.inner = self.inner.cluster_node_timeout(ms);
self
}
pub fn loadmodule(mut self, path: impl Into<PathBuf>) -> Self {
self.inner = self.inner.loadmodule(path);
self
}
pub fn hz(mut self, hz: u32) -> Self {
self.inner = self.inner.hz(hz);
self
}
pub fn io_threads(mut self, n: u32) -> Self {
self.inner = self.inner.io_threads(n);
self
}
pub fn io_threads_do_reads(mut self, enable: bool) -> Self {
self.inner = self.inner.io_threads_do_reads(enable);
self
}
pub fn notify_keyspace_events(mut self, events: impl Into<String>) -> Self {
self.inner = self.inner.notify_keyspace_events(events);
self
}
pub fn slowlog_log_slower_than(mut self, us: i64) -> Self {
self.inner = self.inner.slowlog_log_slower_than(us);
self
}
pub fn slowlog_max_len(mut self, n: u32) -> Self {
self.inner = self.inner.slowlog_max_len(n);
self
}
pub fn latency_monitor_threshold(mut self, ms: u64) -> Self {
self.inner = self.inner.latency_monitor_threshold(ms);
self
}
pub fn latency_tracking(mut self, enable: bool) -> Self {
self.inner = self.inner.latency_tracking(enable);
self
}
pub fn latency_tracking_info_percentiles(mut self, percentiles: impl Into<String>) -> Self {
self.inner = self.inner.latency_tracking_info_percentiles(percentiles);
self
}
pub fn activedefrag(mut self, enable: bool) -> Self {
self.inner = self.inner.activedefrag(enable);
self
}
pub fn active_defrag_ignore_bytes(mut self, bytes: impl Into<String>) -> Self {
self.inner = self.inner.active_defrag_ignore_bytes(bytes);
self
}
pub fn active_defrag_threshold_lower(mut self, pct: u32) -> Self {
self.inner = self.inner.active_defrag_threshold_lower(pct);
self
}
pub fn active_defrag_threshold_upper(mut self, pct: u32) -> Self {
self.inner = self.inner.active_defrag_threshold_upper(pct);
self
}
pub fn active_defrag_cycle_min(mut self, pct: u32) -> Self {
self.inner = self.inner.active_defrag_cycle_min(pct);
self
}
pub fn active_defrag_cycle_max(mut self, pct: u32) -> Self {
self.inner = self.inner.active_defrag_cycle_max(pct);
self
}
pub fn active_defrag_max_scan_fields(mut self, n: u32) -> Self {
self.inner = self.inner.active_defrag_max_scan_fields(n);
self
}
pub fn syslog_enabled(mut self, enable: bool) -> Self {
self.inner = self.inner.syslog_enabled(enable);
self
}
pub fn syslog_ident(mut self, ident: impl Into<String>) -> Self {
self.inner = self.inner.syslog_ident(ident);
self
}
pub fn syslog_facility(mut self, facility: impl Into<String>) -> Self {
self.inner = self.inner.syslog_facility(facility);
self
}
pub fn supervised(mut self, mode: impl Into<String>) -> Self {
self.inner = self.inner.supervised(mode);
self
}
pub fn always_show_logo(mut self, enable: bool) -> Self {
self.inner = self.inner.always_show_logo(enable);
self
}
pub fn set_proc_title(mut self, enable: bool) -> Self {
self.inner = self.inner.set_proc_title(enable);
self
}
pub fn proc_title_template(mut self, template: impl Into<String>) -> Self {
self.inner = self.inner.proc_title_template(template);
self
}
pub fn acl_pubsub_default(mut self, default: impl Into<String>) -> Self {
self.inner = self.inner.acl_pubsub_default(default);
self
}
pub fn acllog_max_len(mut self, n: u32) -> Self {
self.inner = self.inner.acllog_max_len(n);
self
}
pub fn enable_debug_command(mut self, mode: impl Into<String>) -> Self {
self.inner = self.inner.enable_debug_command(mode);
self
}
pub fn enable_module_command(mut self, mode: impl Into<String>) -> Self {
self.inner = self.inner.enable_module_command(mode);
self
}
pub fn enable_protected_configs(mut self, mode: impl Into<String>) -> Self {
self.inner = self.inner.enable_protected_configs(mode);
self
}
pub fn rename_command(
mut self,
command: impl Into<String>,
new_name: impl Into<String>,
) -> Self {
self.inner = self.inner.rename_command(command, new_name);
self
}
pub fn sanitize_dump_payload(mut self, mode: impl Into<String>) -> Self {
self.inner = self.inner.sanitize_dump_payload(mode);
self
}
pub fn hide_user_data_from_log(mut self, enable: bool) -> Self {
self.inner = self.inner.hide_user_data_from_log(enable);
self
}
pub fn bind_source_addr(mut self, addr: impl Into<String>) -> Self {
self.inner = self.inner.bind_source_addr(addr);
self
}
pub fn busy_reply_threshold(mut self, ms: u64) -> Self {
self.inner = self.inner.busy_reply_threshold(ms);
self
}
pub fn client_output_buffer_limit(mut self, limit: impl Into<String>) -> Self {
self.inner = self.inner.client_output_buffer_limit(limit);
self
}
pub fn client_query_buffer_limit(mut self, limit: impl Into<String>) -> Self {
self.inner = self.inner.client_query_buffer_limit(limit);
self
}
pub fn proto_max_bulk_len(mut self, len: impl Into<String>) -> Self {
self.inner = self.inner.proto_max_bulk_len(len);
self
}
pub fn max_new_connections_per_cycle(mut self, n: u32) -> Self {
self.inner = self.inner.max_new_connections_per_cycle(n);
self
}
pub fn max_new_tls_connections_per_cycle(mut self, n: u32) -> Self {
self.inner = self.inner.max_new_tls_connections_per_cycle(n);
self
}
pub fn socket_mark_id(mut self, id: u32) -> Self {
self.inner = self.inner.socket_mark_id(id);
self
}
pub fn dbfilename(mut self, name: impl Into<String>) -> Self {
self.inner = self.inner.dbfilename(name);
self
}
pub fn rdbcompression(mut self, enable: bool) -> Self {
self.inner = self.inner.rdbcompression(enable);
self
}
pub fn rdbchecksum(mut self, enable: bool) -> Self {
self.inner = self.inner.rdbchecksum(enable);
self
}
pub fn rdb_save_incremental_fsync(mut self, enable: bool) -> Self {
self.inner = self.inner.rdb_save_incremental_fsync(enable);
self
}
pub fn rdb_del_sync_files(mut self, enable: bool) -> Self {
self.inner = self.inner.rdb_del_sync_files(enable);
self
}
pub fn stop_writes_on_bgsave_error(mut self, enable: bool) -> Self {
self.inner = self.inner.stop_writes_on_bgsave_error(enable);
self
}
pub fn shutdown_on_sigint(mut self, behavior: impl Into<String>) -> Self {
self.inner = self.inner.shutdown_on_sigint(behavior);
self
}
pub fn shutdown_on_sigterm(mut self, behavior: impl Into<String>) -> Self {
self.inner = self.inner.shutdown_on_sigterm(behavior);
self
}
pub fn shutdown_timeout(mut self, seconds: u32) -> Self {
self.inner = self.inner.shutdown_timeout(seconds);
self
}
pub fn activerehashing(mut self, enable: bool) -> Self {
self.inner = self.inner.activerehashing(enable);
self
}
pub fn crash_log_enabled(mut self, enable: bool) -> Self {
self.inner = self.inner.crash_log_enabled(enable);
self
}
pub fn crash_memcheck_enabled(mut self, enable: bool) -> Self {
self.inner = self.inner.crash_memcheck_enabled(enable);
self
}
pub fn disable_thp(mut self, enable: bool) -> Self {
self.inner = self.inner.disable_thp(enable);
self
}
pub fn dynamic_hz(mut self, enable: bool) -> Self {
self.inner = self.inner.dynamic_hz(enable);
self
}
pub fn ignore_warnings(mut self, warning: impl Into<String>) -> Self {
self.inner = self.inner.ignore_warnings(warning);
self
}
pub fn include(mut self, path: impl Into<PathBuf>) -> Self {
self.inner = self.inner.include(path);
self
}
pub fn jemalloc_bg_thread(mut self, enable: bool) -> Self {
self.inner = self.inner.jemalloc_bg_thread(enable);
self
}
pub fn locale_collate(mut self, locale: impl Into<String>) -> Self {
self.inner = self.inner.locale_collate(locale);
self
}
pub fn lua_time_limit(mut self, ms: u64) -> Self {
self.inner = self.inner.lua_time_limit(ms);
self
}
pub fn oom_score_adj(mut self, mode: impl Into<String>) -> Self {
self.inner = self.inner.oom_score_adj(mode);
self
}
pub fn oom_score_adj_values(mut self, values: impl Into<String>) -> Self {
self.inner = self.inner.oom_score_adj_values(values);
self
}
pub fn propagation_error_behavior(mut self, behavior: impl Into<String>) -> Self {
self.inner = self.inner.propagation_error_behavior(behavior);
self
}
pub fn tracking_table_max_keys(mut self, n: u64) -> Self {
self.inner = self.inner.tracking_table_max_keys(n);
self
}
pub fn redis_server_bin(mut self, bin: impl Into<String>) -> Self {
self.inner = self.inner.redis_server_bin(bin);
self
}
pub fn redis_cli_bin(mut self, bin: impl Into<String>) -> Self {
self.inner = self.inner.redis_cli_bin(bin);
self
}
pub fn extra(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
self.inner = self.inner.extra(key, value);
self
}
pub fn start(self) -> Result<RedisServerHandle> {
let rt = Runtime::new()?;
let inner = rt.block_on(self.inner.start())?;
Ok(RedisServerHandle { inner, rt })
}
}
impl Default for RedisServer {
fn default() -> Self {
Self::new()
}
}
pub struct RedisServerHandle {
inner: server::RedisServerHandle,
rt: Runtime,
}
impl RedisServerHandle {
pub fn addr(&self) -> String {
self.inner.addr()
}
pub fn port(&self) -> u16 {
self.inner.port()
}
pub fn host(&self) -> &str {
self.inner.host()
}
pub fn pid(&self) -> u32 {
self.inner.pid()
}
pub fn is_alive(&self) -> bool {
self.rt.block_on(self.inner.is_alive())
}
pub fn run(&self, args: &[&str]) -> Result<String> {
self.rt.block_on(self.inner.run(args))
}
pub fn detach(self) {
self.inner.detach();
}
pub fn stop(&self) {
self.inner.stop();
}
pub fn wait_for_ready(&self, timeout: Duration) -> Result<()> {
self.rt.block_on(self.inner.wait_for_ready(timeout))
}
}
pub struct RedisCluster;
impl RedisCluster {
pub fn builder() -> RedisClusterBuilder {
RedisClusterBuilder {
inner: cluster::RedisCluster::builder(),
}
}
}
pub struct RedisClusterBuilder {
inner: cluster::RedisClusterBuilder,
}
impl RedisClusterBuilder {
pub fn masters(mut self, n: u16) -> Self {
self.inner = self.inner.masters(n);
self
}
pub fn replicas_per_master(mut self, n: u16) -> Self {
self.inner = self.inner.replicas_per_master(n);
self
}
pub fn base_port(mut self, port: u16) -> Self {
self.inner = self.inner.base_port(port);
self
}
pub fn bind(mut self, bind: impl Into<String>) -> Self {
self.inner = self.inner.bind(bind);
self
}
pub fn password(mut self, password: impl Into<String>) -> Self {
self.inner = self.inner.password(password);
self
}
pub fn logfile(mut self, path: impl Into<String>) -> Self {
self.inner = self.inner.logfile(path);
self
}
pub fn save(mut self, save: bool) -> Self {
self.inner = self.inner.save(save);
self
}
pub fn save_schedule(mut self, schedule: Vec<(u64, u64)>) -> Self {
self.inner = self.inner.save_schedule(schedule);
self
}
pub fn appendonly(mut self, appendonly: bool) -> Self {
self.inner = self.inner.appendonly(appendonly);
self
}
pub fn cluster_node_timeout(mut self, ms: u64) -> Self {
self.inner = self.inner.cluster_node_timeout(ms);
self
}
pub fn cluster_require_full_coverage(mut self, require: bool) -> Self {
self.inner = self.inner.cluster_require_full_coverage(require);
self
}
pub fn cluster_allow_reads_when_down(mut self, allow: bool) -> Self {
self.inner = self.inner.cluster_allow_reads_when_down(allow);
self
}
pub fn cluster_allow_pubsubshard_when_down(mut self, allow: bool) -> Self {
self.inner = self.inner.cluster_allow_pubsubshard_when_down(allow);
self
}
pub fn cluster_allow_replica_migration(mut self, allow: bool) -> Self {
self.inner = self.inner.cluster_allow_replica_migration(allow);
self
}
pub fn cluster_migration_barrier(mut self, barrier: u32) -> Self {
self.inner = self.inner.cluster_migration_barrier(barrier);
self
}
pub fn cluster_announce_hostname(mut self, hostname: impl Into<String>) -> Self {
self.inner = self.inner.cluster_announce_hostname(hostname);
self
}
pub fn cluster_announce_human_nodename(mut self, name: impl Into<String>) -> Self {
self.inner = self.inner.cluster_announce_human_nodename(name);
self
}
pub fn cluster_preferred_endpoint_type(mut self, endpoint_type: impl Into<String>) -> Self {
self.inner = self.inner.cluster_preferred_endpoint_type(endpoint_type);
self
}
pub fn cluster_replica_no_failover(mut self, no_failover: bool) -> Self {
self.inner = self.inner.cluster_replica_no_failover(no_failover);
self
}
pub fn cluster_replica_validity_factor(mut self, factor: u32) -> Self {
self.inner = self.inner.cluster_replica_validity_factor(factor);
self
}
pub fn cluster_announce_ip(mut self, ip: impl Into<String>) -> Self {
self.inner = self.inner.cluster_announce_ip(ip);
self
}
pub fn cluster_announce_port(mut self, port: u16) -> Self {
self.inner = self.inner.cluster_announce_port(port);
self
}
pub fn cluster_announce_bus_port(mut self, port: u16) -> Self {
self.inner = self.inner.cluster_announce_bus_port(port);
self
}
pub fn cluster_announce_tls_port(mut self, port: u16) -> Self {
self.inner = self.inner.cluster_announce_tls_port(port);
self
}
pub fn cluster_port(mut self, port: u16) -> Self {
self.inner = self.inner.cluster_port(port);
self
}
pub fn cluster_link_sendbuf_limit(mut self, limit: u64) -> Self {
self.inner = self.inner.cluster_link_sendbuf_limit(limit);
self
}
pub fn cluster_compatibility_sample_ratio(mut self, ratio: u32) -> Self {
self.inner = self.inner.cluster_compatibility_sample_ratio(ratio);
self
}
pub fn cluster_slot_migration_handoff_max_lag_bytes(mut self, bytes: u64) -> Self {
self.inner = self
.inner
.cluster_slot_migration_handoff_max_lag_bytes(bytes);
self
}
pub fn cluster_slot_migration_write_pause_timeout(mut self, ms: u64) -> Self {
self.inner = self.inner.cluster_slot_migration_write_pause_timeout(ms);
self
}
pub fn cluster_slot_stats_enabled(mut self, enable: bool) -> Self {
self.inner = self.inner.cluster_slot_stats_enabled(enable);
self
}
pub fn min_replicas_to_write(mut self, n: u32) -> Self {
self.inner = self.inner.min_replicas_to_write(n);
self
}
pub fn min_replicas_max_lag(mut self, seconds: u32) -> Self {
self.inner = self.inner.min_replicas_max_lag(seconds);
self
}
pub fn repl_diskless_sync(mut self, enable: bool) -> Self {
self.inner = self.inner.repl_diskless_sync(enable);
self
}
pub fn repl_diskless_sync_delay(mut self, seconds: u32) -> Self {
self.inner = self.inner.repl_diskless_sync_delay(seconds);
self
}
pub fn repl_ping_replica_period(mut self, seconds: u32) -> Self {
self.inner = self.inner.repl_ping_replica_period(seconds);
self
}
pub fn repl_timeout(mut self, seconds: u32) -> Self {
self.inner = self.inner.repl_timeout(seconds);
self
}
pub fn extra(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
self.inner = self.inner.extra(key, value);
self
}
pub fn redis_server_bin(mut self, bin: impl Into<String>) -> Self {
self.inner = self.inner.redis_server_bin(bin);
self
}
pub fn redis_cli_bin(mut self, bin: impl Into<String>) -> Self {
self.inner = self.inner.redis_cli_bin(bin);
self
}
pub fn start(self) -> Result<RedisClusterHandle> {
let rt = Runtime::new()?;
let inner = rt.block_on(self.inner.start())?;
Ok(RedisClusterHandle { inner, rt })
}
}
pub struct RedisClusterHandle {
inner: cluster::RedisClusterHandle,
rt: Runtime,
}
impl RedisClusterHandle {
pub fn addr(&self) -> String {
self.inner.addr()
}
pub fn node_addrs(&self) -> Vec<String> {
self.inner.node_addrs()
}
pub fn pids(&self) -> Vec<u32> {
self.inner.pids()
}
pub fn num_masters(&self) -> u16 {
self.inner.num_masters()
}
pub fn node_run(&self, index: usize, args: &[&str]) -> Result<String> {
self.rt.block_on(self.inner.node(index).run(args))
}
pub fn config_set_all(&self, key: &str, value: &str) -> Result<()> {
self.rt.block_on(self.inner.config_set_all(key, value))
}
pub fn config_set_masters(&self, key: &str, value: &str) -> Result<()> {
self.rt.block_on(self.inner.config_set_masters(key, value))
}
pub fn config_set_replicas(&self, key: &str, value: &str) -> Result<()> {
self.rt.block_on(self.inner.config_set_replicas(key, value))
}
pub fn all_alive(&self) -> bool {
self.rt.block_on(self.inner.all_alive())
}
pub fn is_healthy(&self) -> bool {
self.rt.block_on(self.inner.is_healthy())
}
pub fn wait_for_healthy(&self, timeout: Duration) -> Result<()> {
self.rt.block_on(self.inner.wait_for_healthy(timeout))
}
}
pub struct RedisSentinel;
impl RedisSentinel {
pub fn builder() -> RedisSentinelBuilder {
RedisSentinelBuilder {
inner: sentinel::RedisSentinel::builder(),
}
}
}
pub struct RedisSentinelBuilder {
inner: sentinel::RedisSentinelBuilder,
}
impl RedisSentinelBuilder {
pub fn master_name(mut self, name: impl Into<String>) -> Self {
self.inner = self.inner.master_name(name);
self
}
pub fn master_port(mut self, port: u16) -> Self {
self.inner = self.inner.master_port(port);
self
}
pub fn replicas(mut self, n: u16) -> Self {
self.inner = self.inner.replicas(n);
self
}
pub fn replica_base_port(mut self, port: u16) -> Self {
self.inner = self.inner.replica_base_port(port);
self
}
pub fn sentinels(mut self, n: u16) -> Self {
self.inner = self.inner.sentinels(n);
self
}
pub fn sentinel_base_port(mut self, port: u16) -> Self {
self.inner = self.inner.sentinel_base_port(port);
self
}
pub fn quorum(mut self, q: u16) -> Self {
self.inner = self.inner.quorum(q);
self
}
pub fn bind(mut self, bind: impl Into<String>) -> Self {
self.inner = self.inner.bind(bind);
self
}
pub fn logfile(mut self, path: impl Into<String>) -> Self {
self.inner = self.inner.logfile(path);
self
}
pub fn down_after_ms(mut self, ms: u64) -> Self {
self.inner = self.inner.down_after_ms(ms);
self
}
pub fn failover_timeout_ms(mut self, ms: u64) -> Self {
self.inner = self.inner.failover_timeout_ms(ms);
self
}
pub fn monitor(mut self, name: impl Into<String>, host: impl Into<String>, port: u16) -> Self {
self.inner = self.inner.monitor(name, host, port);
self
}
pub fn monitor_with_replicas(
mut self,
name: impl Into<String>,
host: impl Into<String>,
port: u16,
expected_replicas: u16,
) -> Self {
self.inner = self
.inner
.monitor_with_replicas(name, host, port, expected_replicas);
self
}
pub fn save(mut self, save: bool) -> Self {
self.inner = self.inner.save(save);
self
}
pub fn save_schedule(mut self, schedule: Vec<(u64, u64)>) -> Self {
self.inner = self.inner.save_schedule(schedule);
self
}
pub fn appendonly(mut self, appendonly: bool) -> Self {
self.inner = self.inner.appendonly(appendonly);
self
}
pub fn extra(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
self.inner = self.inner.extra(key, value);
self
}
pub fn redis_server_bin(mut self, bin: impl Into<String>) -> Self {
self.inner = self.inner.redis_server_bin(bin);
self
}
pub fn redis_cli_bin(mut self, bin: impl Into<String>) -> Self {
self.inner = self.inner.redis_cli_bin(bin);
self
}
pub fn start(self) -> Result<RedisSentinelHandle> {
let rt = Runtime::new()?;
let inner = rt.block_on(self.inner.start())?;
Ok(RedisSentinelHandle { inner, rt })
}
}
pub struct RedisSentinelHandle {
inner: sentinel::RedisSentinelHandle,
rt: Runtime,
}
impl RedisSentinelHandle {
pub fn master_addr(&self) -> String {
self.inner.master_addr()
}
pub fn monitored_master_names(&self) -> Vec<&str> {
self.inner.monitored_master_names()
}
pub fn monitored_master_addrs(&self) -> Vec<String> {
self.inner.monitored_master_addrs()
}
pub fn sentinel_addrs(&self) -> Vec<String> {
self.inner.sentinel_addrs()
}
pub fn pids(&self) -> Vec<u32> {
self.inner.pids()
}
pub fn master_name(&self) -> &str {
self.inner.master_name()
}
pub fn poke(&self) -> Result<HashMap<String, String>> {
self.rt.block_on(self.inner.poke())
}
pub fn poke_master(&self, master_name: &str) -> Result<HashMap<String, String>> {
self.rt.block_on(self.inner.poke_master(master_name))
}
pub fn is_healthy(&self) -> bool {
self.rt.block_on(self.inner.is_healthy())
}
pub fn wait_for_healthy(&self, timeout: Duration) -> Result<()> {
self.rt.block_on(self.inner.wait_for_healthy(timeout))
}
pub fn stop(&self) {
self.inner.stop();
}
}