From 95cc1f8ebd739e76323403cac771b4777243904e Mon Sep 17 00:00:00 2001 From: Chojan Shang Date: Mon, 8 May 2023 11:48:02 +0800 Subject: [PATCH 1/2] feat(services/memory): migrate service memory Signed-off-by: Chojan Shang --- core/src/services/memory/backend.rs | 42 +++++++++++++---------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/core/src/services/memory/backend.rs b/core/src/services/memory/backend.rs index 34c773503c2..c745e2883cb 100644 --- a/core/src/services/memory/backend.rs +++ b/core/src/services/memory/backend.rs @@ -22,7 +22,7 @@ use std::sync::Arc; use async_trait::async_trait; use parking_lot::Mutex; -use crate::raw::adapters::kv; +use crate::raw::adapters::typed_kv; use crate::*; /// In memory service support. (BTreeMap Based) @@ -31,12 +31,10 @@ use crate::*; /// /// This service can be used to: /// -/// - [x] read -/// - [x] write -/// - [ ] ~~list~~ +/// - [x] get +/// - [x] set +/// - [x] delete /// - [x] scan -/// - [ ] ~~presign~~ -/// - [x] blocking #[derive(Default)] pub struct MemoryBuilder { root: Option, @@ -72,47 +70,45 @@ impl Builder for MemoryBuilder { } /// Backend is used to serve `Accessor` support in memory. -pub type MemoryBackend = kv::Backend; +pub type MemoryBackend = typed_kv::Backend; #[derive(Debug, Clone)] pub struct Adapter { - inner: Arc>>>, + inner: Arc>>, } #[async_trait] -impl kv::Adapter for Adapter { - fn metadata(&self) -> kv::Metadata { - kv::Metadata::new( +impl typed_kv::Adapter for Adapter { + fn info(&self) -> typed_kv::Info { + typed_kv::Info::new( Scheme::Memory, &format!("{:?}", &self.inner as *const _), - Capability { - read: true, - write: true, - create_dir: true, + typed_kv::Capability { + get: true, + set: true, + delete: true, scan: true, - - ..Default::default() }, ) } - async fn get(&self, path: &str) -> Result>> { + async fn get(&self, path: &str) -> Result> { self.blocking_get(path) } - fn blocking_get(&self, path: &str) -> Result>> { + fn blocking_get(&self, path: &str) -> Result> { match self.inner.lock().get(path) { None => Ok(None), - Some(bs) => Ok(Some(bs.to_vec())), + Some(bs) => Ok(Some(bs.to_owned())), } } - async fn set(&self, path: &str, value: &[u8]) -> Result<()> { + async fn set(&self, path: &str, value: typed_kv::Value) -> Result<()> { self.blocking_set(path, value) } - fn blocking_set(&self, path: &str, value: &[u8]) -> Result<()> { - self.inner.lock().insert(path.to_string(), value.to_vec()); + fn blocking_set(&self, path: &str, value: typed_kv::Value) -> Result<()> { + self.inner.lock().insert(path.to_string(), value); Ok(()) } From 97ea82cbdae81e6d7cd71b8b6634a531a2e92d9d Mon Sep 17 00:00:00 2001 From: Chojan Shang Date: Mon, 8 May 2023 11:49:09 +0800 Subject: [PATCH 2/2] docs(typed_kv): update capabilities Signed-off-by: Chojan Shang --- core/src/services/dashmap/backend.rs | 8 +++----- core/src/services/moka/backend.rs | 10 ++++------ 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/core/src/services/dashmap/backend.rs b/core/src/services/dashmap/backend.rs index 0411dde70cd..18a4694b71d 100644 --- a/core/src/services/dashmap/backend.rs +++ b/core/src/services/dashmap/backend.rs @@ -30,12 +30,10 @@ use crate::*; /// /// This service can be used to: /// -/// - [x] read -/// - [x] write -/// - [ ] ~~list~~ +/// - [x] get +/// - [x] set +/// - [x] delete /// - [x] scan -/// - [ ] ~~presign~~ -/// - [x] blocking #[derive(Default)] pub struct DashmapBuilder { root: Option, diff --git a/core/src/services/moka/backend.rs b/core/src/services/moka/backend.rs index ee40bc9234c..381d8e72e0d 100644 --- a/core/src/services/moka/backend.rs +++ b/core/src/services/moka/backend.rs @@ -33,12 +33,10 @@ use crate::*; /// /// This service can be used to: /// -/// - [x] read -/// - [x] write -/// - [ ] ~~list~~ -/// - [ ] ~~scan~~ -/// - [ ] ~~presign~~ -/// - [x] blocking +/// - [x] get +/// - [x] set +/// - [x] delete +/// - [ ] ~~ scan ~~ #[derive(Default, Debug)] pub struct MokaBuilder { /// Name for this cache instance.