Skip to content

Commit

Permalink
Add KeyDB to crud-bench benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiemh committed Sep 30, 2024
1 parent fc8a383 commit 9c94ab9
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ license = "Apache-2.0"
readme = "README.md"

[features]
default = ["redis", "redb", "rocksdb", "postgres", "mongodb", "surrealkv", "surrealdb"]
default = ["keydb", "redis", "redb", "rocksdb", "postgres", "mongodb", "surrealkv", "surrealdb"]
keydb = ["dep:redis"]
mongodb = ["dep:mongodb"]
postgres = ["dep:tokio-postgres"]
redb = ["dep:redb"]
Expand Down
60 changes: 60 additions & 0 deletions src/keydb.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#![cfg(feature = "keydb")]

use anyhow::Result;
use redis::aio::Connection;
use redis::{AsyncCommands, Client};

use crate::benchmark::{BenchmarkClient, BenchmarkEngine, Record};
use crate::docker::DockerParams;

pub(crate) const KEYDB_DOCKER_PARAMS: DockerParams = DockerParams {
image: "eqalpha/keydb",
pre_args: "",
post_args: "keydb-server --requirepass root",
};

#[derive(Default)]
pub(crate) struct KeydbClientProvider {}

impl BenchmarkEngine<KeydbClient> for KeydbClientProvider {
async fn create_client(&self, endpoint: Option<String>) -> Result<KeydbClient> {
let url = endpoint.unwrap_or("redis://:[email protected]:6379/".to_owned());
let client = Client::open(url)?;
let conn = client.get_async_connection().await?;
Ok(KeydbClient {
conn,
})
}
}

pub(crate) struct KeydbClient {
conn: Connection,
}

impl BenchmarkClient for KeydbClient {
#[allow(dependency_on_unit_never_type_fallback)]
async fn create(&mut self, key: i32, record: &Record) -> Result<()> {
let val = bincode::serialize(record)?;
self.conn.set(key, val).await?;
Ok(())
}

async fn read(&mut self, key: i32) -> Result<()> {
let val: Vec<u8> = self.conn.get(key).await?;
assert!(!val.is_empty());
Ok(())
}

#[allow(dependency_on_unit_never_type_fallback)]
async fn update(&mut self, key: i32, record: &Record) -> Result<()> {
let val = bincode::serialize(record)?;
self.conn.set(key, val).await?;
Ok(())
}

#[allow(dependency_on_unit_never_type_fallback)]
async fn delete(&mut self, key: i32) -> Result<()> {
self.conn.del(key).await?;
Ok(())
}
}
9 changes: 9 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use crate::benchmark::{Benchmark, BenchmarkResult};
use crate::docker::DockerContainer;
use crate::docker::DockerParams;
use crate::dry::DryClientProvider;
#[cfg(feature = "keydb")]
use crate::keydb::KeydbClientProvider;
#[cfg(feature = "mongodb")]
use crate::mongodb::MongoDBClientProvider;
#[cfg(feature = "postgres")]
Expand All @@ -26,6 +28,7 @@ use tokio::runtime::Builder;
mod benchmark;
mod docker;
mod dry;
mod keydb;
mod mongodb;
mod postgres;
mod redb;
Expand Down Expand Up @@ -88,6 +91,8 @@ pub(crate) enum Database {
Postgres,
#[cfg(feature = "redis")]
Redis,
#[cfg(feature = "keydb")]
Keydb,
}

impl Database {
Expand Down Expand Up @@ -116,6 +121,8 @@ impl Database {
Database::Postgres => postgres::POSTGRES_DOCKER_PARAMS,
#[cfg(feature = "redis")]
Database::Redis => redis::REDIS_DOCKER_PARAMS,
#[cfg(feature = "keydb")]
Database::Keydb => keydb::KEYDB_DOCKER_PARAMS,
};
let image = image.unwrap_or(params.image.to_string());
let container = DockerContainer::start(image, params.pre_args, params.post_args);
Expand Down Expand Up @@ -147,6 +154,8 @@ impl Database {
Database::Postgres => benchmark.run(PostgresClientProvider::default()).await,
#[cfg(feature = "redis")]
Database::Redis => benchmark.run(RedisClientProvider::default()).await,
#[cfg(feature = "keydb")]
Database::Keydb => benchmark.run(KeydbClientProvider::default()).await,
}
}
}
Expand Down

0 comments on commit 9c94ab9

Please sign in to comment.