Skip to main content

StorageLayer

Struct StorageLayer 

Source
pub struct StorageLayer {
    pub database: Arc<Database>,
    pub redis: Arc<RedisPool>,
    pub files: Arc<FileStorage>,
    pub vector: Option<Arc<VectorStoreBackend>>,
    pub redis_status: DependencyStatus,
    pub vector_status: DependencyStatus,
}
Expand description

Main storage layer that orchestrates all storage backends

Fields§

§database: Arc<Database>

Database connection pool

§redis: Arc<RedisPool>

Redis connection pool

§files: Arc<FileStorage>

File storage backend

§vector: Option<Arc<VectorStoreBackend>>

Vector database client (optional) Note: Using concrete type instead of trait object for now

§redis_status: DependencyStatus

Status of the Redis dependency after init.

§vector_status: DependencyStatus

Status of the vector DB dependency after init.

Implementations§

Source§

impl StorageLayer

Source

pub async fn new(config: &StorageConfig) -> Result<Self>

Create a new storage layer.

For each optional dependency:

  • if enabled is false (or the section is absent), the dependency is treated as Disabled and a no-op fallback is used,
  • if enabled is true and init succeeds, status is Healthy,
  • if enabled is true, init fails, and allow_degraded is false, the call returns Err so startup fails loudly,
  • if enabled is true, init fails, and allow_degraded is true, the error is logged at error! level and the dependency status is set to Degraded while the gateway keeps running.
Source

pub async fn migrate(&self) -> Result<()>

Run database migrations

Source

pub async fn health_check(&self) -> Result<StorageHealthStatus>

Health check for all storage backends

Source

pub async fn close(&self) -> Result<()>

Close all connections

Source

pub fn db(&self) -> &Database

Get database pool

Source

pub fn redis(&self) -> &RedisPool

Get Redis pool

Source

pub fn files(&self) -> &FileStorage

Get file storage

Source

pub fn vector(&self) -> Option<&VectorStoreBackend>

Get vector store (if available)

Source

pub async fn redis_conn(&self) -> Result<RedisConnection>

Get a Redis connection

Source

pub async fn store_file(&self, filename: &str, content: &[u8]) -> Result<String>

Store file and return file ID

Source

pub async fn get_file(&self, file_id: &str) -> Result<Vec<u8>>

Retrieve file content

Source

pub async fn delete_file(&self, file_id: &str) -> Result<()>

Delete file

Source

pub async fn store_embeddings( &self, id: &str, embeddings: &[f32], metadata: Option<Value>, ) -> Result<()>

Store vector embeddings

Source

pub async fn search_similar( &self, query_vector: &[f32], limit: usize, threshold: Option<f32>, ) -> Result<Vec<SearchResult>>

Search similar vectors

Source

pub async fn cache_get(&self, key: &str) -> Result<Option<String>>

Cache operations

Source

pub async fn cache_set( &self, key: &str, value: &str, ttl: Option<u64>, ) -> Result<()>

Set cache value with optional TTL

Source

pub async fn cache_delete(&self, key: &str) -> Result<()>

Delete cache key

Source

pub async fn cache_exists(&self, key: &str) -> Result<bool>

Check if cache key exists

Source

pub async fn cache_mget(&self, keys: &[String]) -> Result<Vec<Option<String>>>

Batch cache operations

Source

pub async fn cache_mset( &self, pairs: &[(String, String)], ttl: Option<u64>, ) -> Result<()>

Set multiple cache values with optional TTL

Source

pub async fn list_push(&self, key: &str, value: &str) -> Result<()>

List operations Push value to list

Source

pub async fn list_pop(&self, key: &str) -> Result<Option<String>>

Pop value from list

Source

pub async fn list_length(&self, key: &str) -> Result<usize>

Get list length

Source

pub async fn set_add(&self, key: &str, member: &str) -> Result<()>

Set operations Add member to set

Source

pub async fn set_remove(&self, key: &str, member: &str) -> Result<()>

Remove member from set

Source

pub async fn set_members(&self, key: &str) -> Result<Vec<String>>

Get all members of set

Source

pub async fn hash_set(&self, key: &str, field: &str, value: &str) -> Result<()>

Hash operations Set hash field value

Source

pub async fn hash_get(&self, key: &str, field: &str) -> Result<Option<String>>

Get hash field value

Source

pub async fn hash_delete(&self, key: &str, field: &str) -> Result<()>

Delete hash field

Source

pub async fn hash_get_all(&self, key: &str) -> Result<HashMap<String, String>>

Get all hash fields and values

Source

pub async fn publish(&self, channel: &str, message: &str) -> Result<()>

Pub/Sub operations

Source

pub async fn subscribe(&self, channels: &[String]) -> Result<Subscription>

Subscribe to Redis channels Subscribe to Redis channels for pub/sub messaging

Trait Implementations§

Source§

impl Clone for StorageLayer

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for StorageLayer

Source§

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

Formats the value using the given formatter. 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> BudgetAwareRouting for T

Source§

fn filter_by_budget( &self, providers: Vec<String>, budget_router: &BudgetAwareRouter, ) -> Vec<String>

Filter providers based on budget availability
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> 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> 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<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SharedResource for T
where T: Send + Sync + 'static,

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 = !

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