Skip to main content

RedisError

Enum RedisError 

Source
pub enum RedisError {
Show 17 variants Connection { addr: Option<String>, source: Error, }, Protocol(ProtocolError), Redis(String), UnexpectedResponse { expected: &'static str, actual: String, }, ConnectionClosed, InvalidUrl(String), TransactionAborted, ConnectionInUse, TypeMismatch { expected: &'static str, }, IndexOutOfBounds { index: usize, len: usize, }, ReconnectFailed { attempts: usize, last_error: Arc<RedisError>, }, CircuitOpen, PoolAcquisitionTimeout { waited: Duration, pool_size: usize, }, QueueFull, ConnectTimeout, CommandTimeout, Json(Error),
}
Expand description

Errors returned by redis-tower operations.

Covers the full error surface: transport I/O, protocol framing, Redis server errors, type conversion mismatches, and reconnection failures. Use is_retryable and is_connection_error to classify errors for retry and reconnection logic.

Variants§

§

Connection

Connection-level I/O error.

When the error originates at a connect site, addr carries the address the connection attempt failed against (host:port, or a unix socket path), which is invaluable for diagnostics when a client manages several endpoints (pool, cluster, sentinel). For I/O errors that arise after a connection is established – or where no single address applies – addr is None.

The blanket From<std::io::Error> conversion used by ? produces addr: None; use RedisError::connection to attach an address, and read it back with RedisError::connection_addr.

Fields

§addr: Option<String>

The address the connection attempt was made against, if known.

§source: Error

The underlying I/O error.

§

Protocol(ProtocolError)

RESP protocol error (parsing or serialization).

§

Redis(String)

Redis server returned an error response.

§

UnexpectedResponse

Response frame did not match the expected type.

Fields

§expected: &'static str

The expected frame type name.

§actual: String

A debug representation of the actual frame received.

§

ConnectionClosed

Connection is closed.

§

InvalidUrl(String)

URL parsing error.

§

TransactionAborted

Transaction was aborted due to a WATCH violation.

§

ConnectionInUse

Failed to extract the connection because it has other references.

§

TypeMismatch

Type mismatch when extracting a pipeline/transaction result.

Fields

§expected: &'static str

The expected Rust type name.

§

IndexOutOfBounds

Index out of bounds when accessing a pipeline or transaction result.

Fields

§index: usize

The index that was out of bounds.

§len: usize

The length of the collection.

§

ReconnectFailed

Reconnection failed after exhausting all retries.

Fields

§attempts: usize

The number of reconnection attempts made.

§last_error: Arc<RedisError>

The shared structured cause from the final reconnect attempt.

This is reference-counted so every waiter released by the same failed reconnect campaign observes the identical error variant and metadata without reducing it to display text.

§

CircuitOpen

The circuit breaker is open; request rejected without touching the service.

§

PoolAcquisitionTimeout

Timed out waiting to acquire a connection from the pool.

Fields

§waited: Duration

How long the caller waited before the timeout fired.

§pool_size: usize

Number of connections in the pool.

§

QueueFull

A bounded command queue is full; the caller should shed load.

This can be returned by the auto-pipeline channel or an explicitly configured resilient-client offline queue.

§

ConnectTimeout

TCP connection attempt timed out before the OS completed the handshake.

Returned by crate::RedisConnection::connect_with_timeout and by ResilientConnection when a connect_timeout is configured on ReconnectConfig.

§

CommandTimeout

A command exceeded its configured duration or absolute deadline.

Returned when a command exceeds a configured timeout or an absolute deadline carried by WithDeadline.

§

Json(Error)

Available on crate feature serde only.

JSON serialization or deserialization error (serde_json).

Only present when the serde feature is enabled. Allows callers to distinguish serialization failures from network or server errors by matching on RedisError::Json(_).

Implementations§

Source§

impl RedisError

Source

pub fn connection(addr: impl Into<String>, source: Error) -> RedisError

Build a RedisError::Connection that records the address the connection attempt failed against.

Connect sites use this instead of the blanket ? conversion so that the resulting error carries the address (host:port or unix socket path) for diagnostics.

use redis_tower_core::RedisError;
use std::io::{Error, ErrorKind};

let err = RedisError::connection(
    "127.0.0.1:6379",
    Error::new(ErrorKind::ConnectionRefused, "refused"),
);
assert_eq!(err.connection_addr(), Some("127.0.0.1:6379"));
assert!(err.to_string().contains("127.0.0.1:6379"));
Source

pub fn connection_addr(&self) -> Option<&str>

Returns the address a connection error failed against, if it was recorded.

Returns None for non-connection errors and for connection errors that did not capture an address (for example I/O errors converted via the blanket ? conversion).

Source

pub fn is_retryable(&self) -> bool

Returns true if this error is transient and the operation is worth retrying.

Connection and protocol errors are retryable. Redis command errors (WRONGTYPE, NOSCRIPT, etc.) are not – they will fail the same way on retry.

Note: TransactionAborted is retryable at the transaction level (rebuild and re-execute) but not at the command level.

§Safety Warning

For connection errors (RedisError::Connection and RedisError::ConnectionClosed), the command may have been received and executed by Redis before the connection dropped. Retrying a non-idempotent write (INCR, LPUSH, ZADD, etc.) can silently duplicate data. Always check Command::idempotent before retrying on a connection error.

Source

pub fn is_wrongtype(&self) -> bool

Returns true if this is a WRONGTYPE error.

Source

pub fn is_noscript(&self) -> bool

Returns true if this is a NOSCRIPT error.

Source

pub fn is_moved(&self) -> bool

Returns true if this is a MOVED redirect (cluster).

Source

pub fn is_ask(&self) -> bool

Returns true if this is an ASK redirect (cluster).

Source

pub fn is_tryagain(&self) -> bool

Returns true if this is a TRYAGAIN error (cluster).

Redis returns TRYAGAIN for a multi-key command whose keys span a slot that is partway through migration. It is transient: retrying shortly usually succeeds once the slot settles.

Source

pub fn is_clusterdown(&self) -> bool

Returns true if this is a CLUSTERDOWN error (cluster).

The cluster cannot currently serve the request – typically a master election window, or a hash slot that no node is serving. It is transient: a topology refresh plus a bounded retry usually recovers.

Source

pub fn is_loading(&self) -> bool

Returns true if this is a LOADING error.

The node is still loading its dataset into memory (for example just after a restart or a full resync). It is transient: retrying shortly, or against another node, usually succeeds.

Source

pub fn is_busy(&self) -> bool

Returns true if this is a BUSY error (script in progress).

Source

pub fn is_oom(&self) -> bool

Returns true if this is an OOM error.

Source

pub fn is_readonly(&self) -> bool

Returns true if this is a READONLY error (writing to replica).

Source

pub fn server_error_prefix(&self) -> Option<&str>

Returns the Redis error prefix (e.g., “WRONGTYPE”, “NOSCRIPT”, “ERR”).

Source

pub fn is_connection_error(&self) -> bool

Returns true if the connection is broken and needs to be replaced.

Trait Implementations§

Source§

impl Debug for RedisError

Source§

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

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

impl Display for RedisError

Source§

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

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

impl Error for RedisError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Error> for RedisError

Source§

fn from(source: Error) -> RedisError

Converts to this type from the input type.
Source§

impl From<Error> for RedisError

The blanket conversion used by ?. Produces a RedisError::Connection with no address; use RedisError::connection at connect sites to record the address the attempt failed against.

Source§

fn from(source: Error) -> RedisError

Converts to this type from the input type.
Source§

impl From<ProtocolError> for RedisError

Source§

fn from(source: ProtocolError) -> RedisError

Converts to this type from the input type.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more