Skip to content

Commit

Permalink
feat(service/dashmap): op scan
Browse files Browse the repository at this point in the history
Signed-off-by: suyanhanx <[email protected]>
  • Loading branch information
suyanhanx committed Mar 7, 2023
1 parent c9a5522 commit a789435
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/services/dashmap/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use crate::*;
/// - [x] read
/// - [x] write
/// - [ ] ~~list~~
/// - [ ] ~~scan~~
/// - [x] scan
/// - [ ] ~~presign~~
/// - [x] blocking
#[derive(Default)]
Expand Down Expand Up @@ -66,7 +66,7 @@ impl kv::Adapter for Adapter {
kv::Metadata::new(
Scheme::Dashmap,
&format!("{:?}", &self.inner as *const _),
AccessorCapability::Read | AccessorCapability::Write,
AccessorCapability::Read | AccessorCapability::Write | AccessorCapability::Scan,
)
}

Expand Down Expand Up @@ -100,6 +100,19 @@ impl kv::Adapter for Adapter {

Ok(())
}

async fn scan(&self, path: &str) -> Result<Vec<String>> {
self.blocking_scan(path)
}

fn blocking_scan(&self, path: &str) -> Result<Vec<String>> {
let keys = self.inner.iter().map(|kv| kv.key().to_string());
if path.is_empty() {
Ok(keys.collect())
} else {
Ok(keys.filter(|k| k.starts_with(path)).collect())
}
}
}

#[cfg(test)]
Expand Down

0 comments on commit a789435

Please sign in to comment.