oxcache 0.5.0-rc.7

A production-grade multi-level cache library for Rust: L1 memory (Moka/DashMap) + L2 distributed (Redis/Valkey/Dragonfly/Aerospike) + optional L3 disk (redb).
// Copyright (c) 2025-2026 Kirky.X🌠
// SPDX-License-Identifier: MIT
//! Redis error mapping utilities.
//!
//! Provides fine-grained mapping from `RedisError` to `OxCacheError` variants,
//! replacing the coarse `conn_err` / `op_err` binary mapping.

use crate::error::OxCacheError;
use redis::RedisError;

/// Map a `RedisError` to the most specific `OxCacheError` variant.
///
/// Priority: timeout → connection_dropped → connection_error → io_error → operation.
pub(crate) fn map_redis_error(e: RedisError) -> OxCacheError {
    if e.is_timeout() {
        OxCacheError::Timeout(e.to_string())
    } else if e.is_connection_dropped() || e.is_io_error() {
        OxCacheError::Connection(e.to_string())
    } else {
        OxCacheError::Operation(e.to_string())
    }
}

/// Check if a `RedisError` is a connection-level error.
///
/// Used in contexts where we need to distinguish connection errors from
/// operation errors (e.g. SCAN loop in `clear()`).
pub(crate) fn is_connection_error(e: &RedisError) -> bool {
    e.is_timeout() || e.is_io_error() || e.is_connection_dropped()
}