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
impl RedisCacheDatabase
Sourcepub async fn new(
trader_id: TraderId,
instance_id: UUID4,
config: CacheConfig,
database: RedisCacheConfig,
) -> Result<Self>
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.
pub const fn get_encoding(&self) -> SerializationEncoding
pub fn get_trader_key(&self) -> &str
pub fn close(&mut self)
pub async fn flushdb(&mut self)
Sourcepub fn flushdb_sync(&self) -> Result<()>
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.
Sourcepub async fn keys(&mut self, pattern: &str) -> Result<Vec<String>>
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.
Sourcepub async fn read(&mut self, key: &str) -> Result<Vec<Bytes>>
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.
Sourcepub async fn read_bulk(&mut self, keys: &[String]) -> Result<Vec<Option<Bytes>>>
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.
Sourcepub fn load_custom_data(&self, data_type: &DataType) -> Result<Vec<CustomData>>
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.
Sourcepub fn insert(&self, key: String, payload: Option<Vec<Bytes>>) -> Result<()>
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.
Sourcepub fn add_custom_data(&self, data: &CustomData) -> Result<()>
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.
Sourcepub fn update(&mut self, key: String, payload: Option<Vec<Bytes>>) -> Result<()>
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.
Sourcepub fn delete(&mut self, key: String, payload: Option<Vec<Bytes>>) -> Result<()>
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.
Sourcepub fn delete_order(&self, client_order_id: &ClientOrderId) -> Result<()>
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.
Sourcepub fn delete_position(&self, position_id: &PositionId) -> Result<()>
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.
Sourcepub fn delete_account_event(
&self,
account_id: &AccountId,
event_id: &str,
) -> Result<()>
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§
Auto Trait Implementations§
impl !RefUnwindSafe for RedisCacheDatabase
impl !UnwindSafe for RedisCacheDatabase
impl Freeze for RedisCacheDatabase
impl Send for RedisCacheDatabase
impl Sync for RedisCacheDatabase
impl Unpin for RedisCacheDatabase
impl UnsafeUnpin for RedisCacheDatabase
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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