Skip to content

Commit

Permalink
feat(service/dashmap): scan op
Browse files Browse the repository at this point in the history
Signed-off-by: suyanhanx <[email protected]>
  • Loading branch information
suyanhanx committed Mar 6, 2023
1 parent 046acca commit 10cc17b
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/services/dashmap/backend.rs
Original file line number Diff line number Diff line change
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 10cc17b

Please sign in to comment.