pub struct RedisClient { /* private fields */ }Expand description
Shared Redis client wrapping a deadpool_redis::Pool.
Provides typed helpers for common operations used across Pyra services: get/set with optional TTL, JSON serialization, MGET, SCAN, sets, hashes, streams, and distributed locks (SET NX).
Implementations§
Source§impl RedisClient
impl RedisClient
pub fn new(pool: Pool) -> Self
pub async fn get(&self, key: &str) -> RedisResult<Option<String>>
pub async fn set( &self, key: &str, value: &str, ttl_seconds: Option<u64>, ) -> RedisResult<()>
Sourcepub async fn set_nx(
&self,
key: &str,
value: &str,
ttl_seconds: u64,
) -> RedisResult<bool>
pub async fn set_nx( &self, key: &str, value: &str, ttl_seconds: u64, ) -> RedisResult<bool>
SET key value NX EX ttl — returns true if the key was set (lock acquired).
pub async fn delete(&self, key: &str) -> RedisResult<bool>
pub async fn exists(&self, key: &str) -> RedisResult<bool>
pub async fn expire(&self, key: &str, ttl_seconds: i64) -> RedisResult<bool>
pub async fn increment(&self, key: &str) -> RedisResult<i64>
Sourcepub async fn increment_by(&self, key: &str, amount: i64) -> RedisResult<i64>
pub async fn increment_by(&self, key: &str, amount: i64) -> RedisResult<i64>
INCRBY — increment key by a specific amount.
Sourcepub async fn decrement_by(&self, key: &str, amount: i64) -> RedisResult<i64>
pub async fn decrement_by(&self, key: &str, amount: i64) -> RedisResult<i64>
DECRBY — decrement key by a specific amount.
Sourcepub async fn ttl(&self, key: &str) -> RedisResult<i64>
pub async fn ttl(&self, key: &str) -> RedisResult<i64>
TTL — get remaining time-to-live in seconds. Returns -1 if no expiry, -2 if key doesn’t exist.
pub async fn set_json<T: Serialize>( &self, key: &str, value: &T, ttl_seconds: Option<u64>, ) -> RedisResult<()>
pub async fn get_json<T: DeserializeOwned>( &self, key: &str, ) -> RedisResult<Option<T>>
Sourcepub async fn set_multiple(&self, pairs: &[(String, String)]) -> RedisResult<()>
pub async fn set_multiple(&self, pairs: &[(String, String)]) -> RedisResult<()>
MSET — set multiple key-value pairs in a single round-trip.
Sourcepub async fn mget(&self, keys: &[String]) -> RedisResult<Vec<Option<String>>>
pub async fn mget(&self, keys: &[String]) -> RedisResult<Vec<Option<String>>>
MGET — fetch multiple keys in a single round-trip.
Sourcepub async fn scan_keys(&self, pattern: &str) -> RedisResult<Vec<String>>
pub async fn scan_keys(&self, pattern: &str) -> RedisResult<Vec<String>>
SCAN with a glob pattern. Returns deduplicated keys.
pub async fn set_add(&self, key: &str, members: &[String]) -> RedisResult<usize>
pub async fn set_members(&self, key: &str) -> RedisResult<Vec<String>>
pub async fn set_is_member(&self, key: &str, member: &str) -> RedisResult<bool>
pub async fn hash_set( &self, key: &str, field: &str, value: &str, ) -> RedisResult<()>
pub async fn hash_get( &self, key: &str, field: &str, ) -> RedisResult<Option<String>>
pub async fn hash_get_all( &self, key: &str, ) -> RedisResult<HashMap<String, String>>
Sourcepub async fn xadd(
&self,
key: &str,
max_len: usize,
fields: &[(&str, &str)],
) -> RedisResult<String>
pub async fn xadd( &self, key: &str, max_len: usize, fields: &[(&str, &str)], ) -> RedisResult<String>
XADD with approximate MAXLEN trimming.
Sourcepub async fn list_push(&self, key: &str, values: &[String]) -> RedisResult<i64>
pub async fn list_push(&self, key: &str, values: &[String]) -> RedisResult<i64>
RPUSH — append one or more values to a list.
pub async fn list_pop(&self, key: &str) -> RedisResult<Option<String>>
pub async fn list_length(&self, key: &str) -> RedisResult<i64>
Sourcepub async fn eval<T: FromRedisValue>(
&self,
script: &str,
keys: &[&str],
args: &[&str],
) -> RedisResult<T>
pub async fn eval<T: FromRedisValue>( &self, script: &str, keys: &[&str], args: &[&str], ) -> RedisResult<T>
Execute a Lua script via EVAL.
pub async fn ping(&self) -> RedisResult<bool>
Sourcepub async fn health_check(&self) -> bool
pub async fn health_check(&self) -> bool
Health check — attempts a GET and returns false on error.
Sourcepub fn available_connections(&self) -> usize
pub fn available_connections(&self) -> usize
Number of idle connections available for use.
Sourcepub fn waiting_connections(&self) -> usize
pub fn waiting_connections(&self) -> usize
Number of tasks waiting for a connection.
Source§impl RedisClient
impl RedisClient
Sourcepub async fn fetch_vault_position_data(
&self,
vault_address: &str,
asset_ids: &[AssetId],
) -> RedisResult<VaultPositionData>
pub async fn fetch_vault_position_data( &self, vault_address: &str, asset_ids: &[AssetId], ) -> RedisResult<VaultPositionData>
Fetch DriftUser, SpotMarkets, and prices for a vault via a single MGET.
Builds keys as: [drift_user, spot_market_0..N, price_0..N]
and parses the results into typed structures.
Returns NotFound if the DriftUser key is missing.
Sourcepub async fn fetch_all_drift_positions(
&self,
asset_ids: &[AssetId],
include_vault_owners: bool,
) -> RedisResult<AllDriftPositionsData>
pub async fn fetch_all_drift_positions( &self, asset_ids: &[AssetId], include_vault_owners: bool, ) -> RedisResult<AllDriftPositionsData>
Fetch ALL drift user positions from Redis via SCAN + MGET.
Scans every account:drift:user:* key and fetches all position data
in a single MGET round-trip.
When include_vault_owners is true, vault accounts are also fetched
to map vault_address → owner solana address.
Source§impl RedisClient
impl RedisClient
Sourcepub async fn fetch_drift_user(
&self,
authority: &Pubkey,
) -> RedisResult<Option<DriftUser>>
pub async fn fetch_drift_user( &self, authority: &Pubkey, ) -> RedisResult<Option<DriftUser>>
Fetch a Drift user account by the vault (authority) address.
Sourcepub async fn fetch_spot_market(
&self,
asset_id: AssetId,
) -> RedisResult<Option<SpotMarket>>
pub async fn fetch_spot_market( &self, asset_id: AssetId, ) -> RedisResult<Option<SpotMarket>>
Fetch a single Drift spot market by asset ID.
Sourcepub async fn fetch_spot_markets(
&self,
asset_ids: &[AssetId],
) -> RedisResult<HashMap<AssetId, SpotMarket>>
pub async fn fetch_spot_markets( &self, asset_ids: &[AssetId], ) -> RedisResult<HashMap<AssetId, SpotMarket>>
Fetch multiple spot markets by their asset IDs in a single MGET round-trip.
Returns only the markets that were found and successfully deserialized.
Sourcepub async fn fetch_all_spot_markets(
&self,
) -> RedisResult<HashMap<AssetId, SpotMarket>>
pub async fn fetch_all_spot_markets( &self, ) -> RedisResult<HashMap<AssetId, SpotMarket>>
Fetch all spot markets by scanning account:drift:spot_market:* keys.
Uses SCAN + MGET for efficiency. Returns asset_id -> SpotMarket. Only includes tokens known to pyra-tokens.
Source§impl RedisClient
impl RedisClient
Sourcepub async fn fetch_vault_kamino_position_data(
&self,
vault_address: &Pubkey,
lending_market: &Pubkey,
reserve_pubkeys: &[Pubkey],
) -> RedisResult<VaultKaminoPositionData>
pub async fn fetch_vault_kamino_position_data( &self, vault_address: &Pubkey, lending_market: &Pubkey, reserve_pubkeys: &[Pubkey], ) -> RedisResult<VaultKaminoPositionData>
Fetch KaminoObligation, reserves, and prices for a vault via MGET.
Builds keys as: [obligation, reserve_0..N] and extracts prices
from reserve.liquidity.market_price_sf.
Returns NotFound if the obligation key is missing.
Sourcepub async fn fetch_all_kamino_positions(
&self,
reserve_pubkeys: &[Pubkey],
) -> RedisResult<AllKaminoPositionsData>
pub async fn fetch_all_kamino_positions( &self, reserve_pubkeys: &[Pubkey], ) -> RedisResult<AllKaminoPositionsData>
Fetch ALL Kamino obligations from Redis via SCAN + MGET.
Scans every account:kamino:obligation:* key and fetches all
obligation data in a single MGET round-trip.
Source§impl RedisClient
impl RedisClient
Sourcepub async fn fetch_kamino_obligation(
&self,
vault_address: &Pubkey,
lending_market: &Pubkey,
) -> RedisResult<Option<KaminoObligation>>
pub async fn fetch_kamino_obligation( &self, vault_address: &Pubkey, lending_market: &Pubkey, ) -> RedisResult<Option<KaminoObligation>>
Fetch a Kamino obligation by the vault (authority) address and lending market.
Sourcepub async fn fetch_kamino_obligation_by_pubkey(
&self,
obligation_pubkey: &Pubkey,
) -> RedisResult<Pubkey>
pub async fn fetch_kamino_obligation_by_pubkey( &self, obligation_pubkey: &Pubkey, ) -> RedisResult<Pubkey>
Reverse lookup: Kamino Obligation account pubkey → vault authority (owner).
Sourcepub async fn fetch_kamino_reserve(
&self,
reserve_pubkey: &Pubkey,
) -> RedisResult<Option<KaminoReserve>>
pub async fn fetch_kamino_reserve( &self, reserve_pubkey: &Pubkey, ) -> RedisResult<Option<KaminoReserve>>
Fetch a single Kamino reserve by its pubkey.
Sourcepub async fn fetch_kamino_reserves(
&self,
pubkeys: &[Pubkey],
) -> RedisResult<HashMap<Pubkey, KaminoReserve>>
pub async fn fetch_kamino_reserves( &self, pubkeys: &[Pubkey], ) -> RedisResult<HashMap<Pubkey, KaminoReserve>>
Fetch multiple Kamino reserves by pubkey in a single MGET round-trip.
Returns only the reserves that were found and successfully deserialized.
Sourcepub async fn fetch_all_kamino_reserves(
&self,
) -> RedisResult<HashMap<Pubkey, KaminoReserve>>
pub async fn fetch_all_kamino_reserves( &self, ) -> RedisResult<HashMap<Pubkey, KaminoReserve>>
Fetch all Kamino reserves by scanning account:kamino:reserve:* keys.
Uses SCAN + MGET for efficiency. Returns reserve_pubkey -> KaminoReserve.
Source§impl RedisClient
impl RedisClient
Sourcepub async fn fetch_vault(&self, vault: &Pubkey) -> RedisResult<Option<Vault>>
pub async fn fetch_vault(&self, vault: &Pubkey) -> RedisResult<Option<Vault>>
Fetch a Pyra vault account by its PDA address.
Sourcepub async fn fetch_withdraw_order(
&self,
order: &Pubkey,
) -> RedisResult<Option<WithdrawOrderAccount>>
pub async fn fetch_withdraw_order( &self, order: &Pubkey, ) -> RedisResult<Option<WithdrawOrderAccount>>
Fetch a withdraw order account by its PDA address.
Sourcepub async fn fetch_spend_limits_order(
&self,
order: &Pubkey,
) -> RedisResult<Option<SpendLimitsOrderAccount>>
pub async fn fetch_spend_limits_order( &self, order: &Pubkey, ) -> RedisResult<Option<SpendLimitsOrderAccount>>
Fetch a spend limits order account by its PDA address.
Sourcepub async fn fetch_price(&self, asset_id: AssetId) -> RedisResult<Option<f64>>
pub async fn fetch_price(&self, asset_id: AssetId) -> RedisResult<Option<f64>>
Fetch the oracle price for an asset (stored as a plain f64 by the indexer).
Sourcepub async fn fetch_prices(
&self,
asset_ids: &[AssetId],
) -> RedisResult<HashMap<AssetId, f64>>
pub async fn fetch_prices( &self, asset_ids: &[AssetId], ) -> RedisResult<HashMap<AssetId, f64>>
Fetch prices for multiple assets in a single MGET round-trip.
Returns only assets that have a cached price.
Trait Implementations§
Source§impl Clone for RedisClient
impl Clone for RedisClient
Source§fn clone(&self) -> RedisClient
fn clone(&self) -> RedisClient
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more