Trait RedisRepository

Source
pub trait RedisRepository {
    // Provided methods
    fn serialize_entity<T, F>(
        &self,
        entity: &T,
        id_extractor: F,
        entity_type: &str,
    ) -> Result<String, RepositoryError>
       where T: Serialize,
             F: Fn(&T) -> &str { ... }
    fn deserialize_entity<T>(
        &self,
        json: &str,
        entity_id: &str,
        entity_type: &str,
    ) -> Result<T, RepositoryError>
       where T: for<'de> Deserialize<'de> { ... }
    fn map_redis_error(
        &self,
        error: RedisError,
        context: &str,
    ) -> RepositoryError { ... }
    fn map_pool_error(&self, error: PoolError, context: &str) -> RepositoryError { ... }
    async fn get_connection(
        &self,
        pool: &Arc<Pool>,
        context: &str,
    ) -> Result<Connection, RepositoryError> { ... }
}
Expand description

Base trait for Redis repositories providing common functionality

Provided Methods§

Source

fn serialize_entity<T, F>( &self, entity: &T, id_extractor: F, entity_type: &str, ) -> Result<String, RepositoryError>
where T: Serialize, F: Fn(&T) -> &str,

Source

fn deserialize_entity<T>( &self, json: &str, entity_id: &str, entity_type: &str, ) -> Result<T, RepositoryError>
where T: for<'de> Deserialize<'de>,

Deserialize entity with detailed error context Default implementation that works for any Deserialize type

Source

fn map_redis_error(&self, error: RedisError, context: &str) -> RepositoryError

Convert Redis errors to appropriate RepositoryError types

Source

fn map_pool_error(&self, error: PoolError, context: &str) -> RepositoryError

Convert deadpool Pool errors to appropriate RepositoryError types

Source

async fn get_connection( &self, pool: &Arc<Pool>, context: &str, ) -> Result<Connection, RepositoryError>

Get a connection from the Redis pool with error handling

§Arguments
  • pool - Reference to the Redis connection pool
  • context - Context string for error messages (e.g., “get_by_id”, “create”)
§Returns

A connection from the pool, or a RepositoryError if getting the connection fails

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§