Skip to main content

RedisCli

Struct RedisCli 

Source
pub struct RedisCli { /* private fields */ }
Expand description

Builder for executing redis-cli commands.

Implementations§

Source§

impl RedisCli

Source

pub fn new() -> Self

Create a new redis-cli builder with defaults (localhost:6379).

Source

pub fn bin(self, bin: impl Into<String>) -> Self

Set the redis-cli binary path.

Source

pub fn host(self, host: impl Into<String>) -> Self

Set the host to connect to.

Source

pub fn port(self, port: u16) -> Self

Set the port to connect to.

Source

pub fn password(self, password: impl Into<String>) -> Self

Set the password for AUTH.

Source

pub fn user(self, user: impl Into<String>) -> Self

Set the ACL username for AUTH.

Source

pub fn db(self, db: u32) -> Self

Select a database number.

Source

pub fn unixsocket(self, path: impl Into<PathBuf>) -> Self

Connect via a Unix socket instead of TCP.

Source

pub fn tls(self, enable: bool) -> Self

Enable TLS for the connection.

Source

pub fn sni(self, hostname: impl Into<String>) -> Self

Set the SNI hostname for TLS.

Source

pub fn cacert(self, path: impl Into<PathBuf>) -> Self

Set the CA certificate file for TLS verification.

Source

pub fn cert(self, path: impl Into<PathBuf>) -> Self

Set the client certificate file for TLS.

Source

pub fn key(self, path: impl Into<PathBuf>) -> Self

Set the client private key file for TLS.

Source

pub fn cacertdir(self, path: impl Into<PathBuf>) -> Self

Set the CA certificate directory for TLS verification.

Source

pub fn insecure(self, enable: bool) -> Self

Skip TLS certificate verification (--insecure).

Source

pub fn tls_ciphers(self, ciphers: impl Into<String>) -> Self

Set the allowed TLS 1.2 ciphers (--tls-ciphers).

Source

pub fn tls_ciphersuites(self, ciphersuites: impl Into<String>) -> Self

Set the allowed TLS 1.3 ciphersuites (--tls-ciphersuites).

Source

pub fn uri(self, uri: impl Into<String>) -> Self

Set the server URI (-u), e.g. redis://user:pass@host:port/db.

Source

pub fn timeout(self, seconds: f64) -> Self

Set the connection timeout in seconds (-t).

Source

pub fn askpass(self, enable: bool) -> Self

Prompt for password from stdin (--askpass).

Source

pub fn client_name(self, name: impl Into<String>) -> Self

Set the client connection name (--name).

Source

pub fn ip_preference(self, preference: IpPreference) -> Self

Set IP version preference for connections.

Source

pub fn repeat(self, count: u32) -> Self

Execute the command N times (-r).

Source

pub fn interval(self, seconds: f64) -> Self

Set interval in seconds between repeated commands (-i).

Source

pub fn resp(self, protocol: RespProtocol) -> Self

Set the RESP protocol version.

Source

pub fn cluster_mode(self, enable: bool) -> Self

Enable cluster mode (-c flag) for following redirects.

Source

pub fn output_format(self, format: OutputFormat) -> Self

Set the output format.

Source

pub fn no_auth_warning(self, suppress: bool) -> Self

Suppress the AUTH password warning.

Source

pub fn stdin_last_arg(self, enable: bool) -> Self

Read last argument from stdin (-x).

Source

pub fn stdin_tag_arg(self, enable: bool) -> Self

Read tag argument from stdin (-X).

Source

pub fn multi_bulk_delimiter(self, delim: impl Into<String>) -> Self

Set the multi-bulk delimiter (-d).

Source

pub fn output_delimiter(self, delim: impl Into<String>) -> Self

Set the output delimiter between responses (-D).

Source

pub fn exit_error_code(self, enable: bool) -> Self

Return exit error code on server errors (-e).

Source

pub fn no_raw(self, enable: bool) -> Self

Force formatted output even with pipe (--no-raw).

Source

pub fn quoted_input(self, enable: bool) -> Self

Force input to be processed as quoted strings (--quoted-input).

Source

pub fn show_pushes(self, enable: bool) -> Self

Show or hide push messages (--show-pushes).

Source

pub fn stat(self, enable: bool) -> Self

Enable continuous stat mode (--stat).

Source

pub fn latency(self, enable: bool) -> Self

Enable latency mode (--latency).

Source

pub fn latency_history(self, enable: bool) -> Self

Enable latency history mode (--latency-history).

Source

pub fn latency_dist(self, enable: bool) -> Self

Enable latency distribution mode (--latency-dist).

Source

pub fn bigkeys(self, enable: bool) -> Self

Scan for big keys (--bigkeys).

Source

pub fn memkeys(self, enable: bool) -> Self

Scan for keys by memory usage (--memkeys).

Source

pub fn memkeys_samples(self, n: u32) -> Self

Set the sample count for memkeys (--memkeys-samples).

Source

pub fn keystats(self, enable: bool) -> Self

Enable key statistics (--keystats).

Source

pub fn keystats_samples(self, n: u32) -> Self

Set the sample count for keystats (--keystats-samples).

Source

pub fn hotkeys(self, enable: bool) -> Self

Scan for hot keys (--hotkeys).

Source

pub fn scan(self, enable: bool) -> Self

Enable scan mode (--scan).

Source

pub fn pattern(self, pat: impl Into<String>) -> Self

Set a pattern filter for scan (--pattern).

Source

pub fn count(self, n: u32) -> Self

Set a count hint for scan (--count).

Source

pub fn quoted_pattern(self, pat: impl Into<String>) -> Self

Set a quoted pattern for scan (--quoted-pattern).

Source

pub fn cursor(self, n: u64) -> Self

Set the starting cursor for scan (--cursor).

Source

pub fn top(self, n: u32) -> Self

Set the top N for keystats (--top).

Source

pub fn intrinsic_latency(self, seconds: u32) -> Self

Measure intrinsic system latency for the given number of seconds.

Source

pub fn lru_test(self, keys: u64) -> Self

Run LRU simulation test with the given number of keys.

Source

pub fn verbose(self, enable: bool) -> Self

Enable verbose mode (--verbose).

Source

pub fn eval_file(self, path: impl Into<PathBuf>) -> Self

Evaluate a Lua script file (--eval).

Source

pub fn ldb(self, enable: bool) -> Self

Enable Lua debugger (--ldb).

Source

pub fn ldb_sync_mode(self, enable: bool) -> Self

Enable Lua debugger in synchronous mode (--ldb-sync-mode).

Source

pub fn pipe(self, enable: bool) -> Self

Enable pipe mode for mass-insert (--pipe).

Source

pub fn pipe_timeout(self, seconds: u32) -> Self

Set the pipe mode timeout in seconds (--pipe-timeout).

Source

pub fn rdb(self, path: impl Into<PathBuf>) -> Self

Transfer an RDB dump to a file (--rdb).

Source

pub fn functions_rdb(self, path: impl Into<PathBuf>) -> Self

Transfer a functions-only RDB dump (--functions-rdb).

Source

pub fn replica(self, enable: bool) -> Self

Simulate a replica for replication stream (--replica).

Source

pub async fn cluster_command( &self, command: &str, args: &[&str], ) -> Result<String>

Run a redis-cli --cluster <command> subcommand.

This is a general-purpose method for all cluster subcommands beyond create (which has the dedicated cluster_create method). Pass the subcommand and any additional arguments.

§Example
use redis_server_wrapper::RedisCli;

let cli = RedisCli::new().host("127.0.0.1").port(7000);
let info = cli.cluster_command("info", &["127.0.0.1:7000"]).await.unwrap();
Source

pub async fn run(&self, args: &[&str]) -> Result<String>

Run a command and return stdout on success.

Source

pub fn fire_and_forget(&self, args: &[&str])

Run a command, ignoring output. Used for fire-and-forget (SHUTDOWN).

Source

pub async fn ping(&self) -> bool

Send PING and return true if PONG is received.

Source

pub fn shutdown(&self)

Send SHUTDOWN NOSAVE. Best-effort.

Source

pub async fn wait_for_ready(&self, timeout: Duration) -> Result<()>

Wait until the server responds to PING or timeout expires.

Source

pub async fn cluster_create( &self, node_addrs: &[String], replicas_per_master: u16, ) -> Result<()>

Run redis-cli --cluster create ... to form a cluster.

Trait Implementations§

Source§

impl Clone for RedisCli

Source§

fn clone(&self) -> RedisCli

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RedisCli

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for RedisCli

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.