Skip to content

Commit

Permalink
Add len(..) and db_size(..)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmqtt committed Mar 1, 2024
1 parent ef9f1ce commit 13c9715
Show file tree
Hide file tree
Showing 3 changed files with 410 additions and 36 deletions.
16 changes: 14 additions & 2 deletions src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ pub trait StorageDB: Send + Sync {

async fn contains_key<K: AsRef<[u8]> + Sync + Send>(&self, key: K) -> Result<bool>;

async fn db_size(&self) -> Result<i64>;
#[cfg(feature = "len")]
async fn len(&self) -> Result<usize>;

async fn db_size(&self) -> Result<usize>;

#[cfg(feature = "ttl")]
async fn expire_at<K>(&self, key: K, at: TimestampMillis) -> Result<bool>
Expand Down Expand Up @@ -431,7 +434,16 @@ impl DefaultStorageDB {
}

#[inline]
pub async fn db_size(&self) -> Result<i64> {
#[cfg(feature = "len")]
pub async fn len(&self) -> Result<usize> {
match self {
DefaultStorageDB::Sled(db) => db.len().await,
DefaultStorageDB::Redis(db) => db.len().await,
}
}

#[inline]
pub async fn db_size(&self) -> Result<usize> {
match self {
DefaultStorageDB::Sled(db) => db.db_size().await,
DefaultStorageDB::Redis(db) => db.db_size().await,
Expand Down
Loading

0 comments on commit 13c9715

Please sign in to comment.