Skip to main content

RedisCacheDatabase

Struct RedisCacheDatabase 

Source
pub struct RedisCacheDatabase {
    pub con: ConnectionManager,
    pub trader_id: TraderId,
    pub trader_key: String,
    pub encoding: SerializationEncoding,
    pub bulk_read_batch_size: Option<usize>,
    /* private fields */
}

Fields§

§con: ConnectionManager§trader_id: TraderId§trader_key: String§encoding: SerializationEncoding§bulk_read_batch_size: Option<usize>

Implementations§

Source§

impl RedisCacheDatabase

Source

pub async fn new( trader_id: TraderId, instance_id: UUID4, config: CacheConfig, database: RedisCacheConfig, ) -> Result<Self>

Creates a Redis cache database from cache behavior and Redis connection settings.

§Errors

Returns an error if:

  • Establishing the Redis connection fails.
  • The command processing task cannot be spawned.
Source

pub const fn get_encoding(&self) -> SerializationEncoding

Source

pub fn get_trader_key(&self) -> &str

Source

pub fn close(&mut self)

Source

pub async fn flushdb(&mut self)

Source

pub fn flushdb_sync(&self) -> Result<()>

Sends a flush command through the background task channel and blocks until it completes. Safe to call from any runtime context.

§Errors

Returns an error if the command channel is closed or the reply is lost.

Source

pub async fn keys(&mut self, pattern: &str) -> Result<Vec<String>>

Retrieves all keys matching the given pattern from Redis for this trader.

§Errors

Returns an error if the underlying Redis scan operation fails.

Source

pub async fn read(&mut self, key: &str) -> Result<Vec<Bytes>>

Reads the value(s) associated with key for this trader from Redis.

§Errors

Returns an error if the underlying Redis read operation fails.

Source

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

Reads multiple values using bulk operations for efficiency.

§Errors

Returns an error if the underlying Redis read operation fails.

Source

pub fn load_custom_data(&self, data_type: &DataType) -> Result<Vec<CustomData>>

Loads custom data from Redis matching the given data_type (blocking).

Spawns the async query on the global Nautilus runtime and blocks until the result arrives via a channel. Safe from any thread context (Python, test runtimes, plain threads).

§Errors

Returns an error if the query fails or the reply channel is closed.

Source

pub fn insert(&self, key: String, payload: Option<Vec<Bytes>>) -> Result<()>

Sends an insert command for key with optional payload to Redis via the background task.

§Errors

Returns an error if the command cannot be sent to the background task channel.

Source

pub fn add_custom_data(&self, data: &CustomData) -> Result<()>

Stores custom data in Redis (key format: custom:<ts_init_020>:<uuid>, value: full JSON).

Uses the registered JSON format independently of cache encoding and timestamp options.

§Errors

Returns an error if serialization fails or the insert command cannot be sent.

Source

pub fn update(&mut self, key: String, payload: Option<Vec<Bytes>>) -> Result<()>

Sends an update command for key with optional payload to Redis via the background task.

§Errors

Returns an error if the command cannot be sent to the background task channel.

Source

pub fn delete(&mut self, key: String, payload: Option<Vec<Bytes>>) -> Result<()>

Sends a delete command for key with optional payload to Redis via the background task.

§Errors

Returns an error if the command cannot be sent to the background task channel.

Source

pub fn delete_order(&self, client_order_id: &ClientOrderId) -> Result<()>

Delete the given order from the database with full index cleanup.

§Errors

Returns an error if the command cannot be sent to the background task channel.

Source

pub fn delete_position(&self, position_id: &PositionId) -> Result<()>

Delete the given position from the database with full index cleanup.

§Errors

Returns an error if the command cannot be sent to the background task channel.

Source

pub fn delete_account_event( &self, account_id: &AccountId, event_id: &str, ) -> Result<()>

Logs an account-event deletion request and retains the full history for replay.

Always returns success.

Trait Implementations§

Source§

impl Debug for RedisCacheDatabase

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
§

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

§

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.

§

impl<T> Instrument for T

§

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

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

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
§

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

impl<T> Ungil for T
where T: Send,

§

impl<T> WithSubscriber for T

§

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
§

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

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