Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions core/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 12 additions & 19 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,11 @@ services-pcloud = ["dep:opendal-service-pcloud"]
services-persy = ["dep:opendal-service-persy"]
services-postgresql = ["dep:opendal-service-postgresql"]
services-redb = ["dep:opendal-service-redb"]
services-redis = ["opendal-core/services-redis"]
services-redis-native-tls = ["opendal-core/services-redis-native-tls"]
services-redis = ["dep:opendal-service-redis", "opendal-service-redis?/rustls"]
services-redis-native-tls = [
"dep:opendal-service-redis",
"opendal-service-redis?/native-tls",
]
services-rocksdb = ["dep:opendal-service-rocksdb"]
services-s3 = ["dep:opendal-service-s3"]
services-seafile = ["dep:opendal-service-seafile"]
Expand Down Expand Up @@ -266,6 +269,7 @@ opendal-service-pcloud = { path = "services/pcloud", version = "0.55.0", optiona
opendal-service-persy = { path = "services/persy", version = "0.55.0", optional = true, default-features = false }
opendal-service-postgresql = { path = "services/postgresql", version = "0.55.0", optional = true, default-features = false }
opendal-service-redb = { path = "services/redb", version = "0.55.0", optional = true, default-features = false }
opendal-service-redis = { path = "services/redis", version = "0.55.0", optional = true, default-features = false }
opendal-service-rocksdb = { path = "services/rocksdb", version = "0.55.0", optional = true, default-features = false }
opendal-service-s3 = { path = "services/s3", version = "0.55.0", optional = true, default-features = false }
opendal-service-seafile = { path = "services/seafile", version = "0.55.0", optional = true, default-features = false }
Expand All @@ -283,35 +287,24 @@ opendal-service-webhdfs = { path = "services/webhdfs", version = "0.55.0", optio
opendal-service-yandex-disk = { path = "services/yandex-disk", version = "0.55.0", optional = true, default-features = false }
opendal-testkit = { path = "testkit", version = "0.55.0", optional = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
opendal-service-opfs = { path = "services/opfs", version = "0.55.0", optional = true, default-features = false }

[dev-dependencies]
anyhow = { version = "1.0.100", features = ["std"] }
anyhow = "1.0"
bytes = { workspace = true }
criterion = { version = "0.7", features = ["async", "async_tokio"] }
divan = { version = "0.1" }
dotenvy = "0.15"
fastrace = { version = "0.7", features = ["enable"] }
fastrace-jaeger = "0.7"
divan = "0.1"
futures = { workspace = true, default-features = true }
http = { workspace = true }
libtest-mimic = "0.8"
log = { workspace = true }
opentelemetry = { version = "0.31.0", default-features = false, features = [
"trace",
] }
opentelemetry-otlp = { version = "0.31.0", features = ["grpc-tonic"] }
opentelemetry_sdk = { version = "0.31.0", features = ["rt-tokio"] }
pretty_assertions = "1"
rand = { workspace = true }
reqwest = { version = "0.12.24" }
reqwest = "0.12.24"
sha2 = { workspace = true }
size = "0.5"
tokio = { workspace = true, features = ["fs", "macros", "rt-multi-thread"] }
tracing-opentelemetry = "0.32.0"
tracing-subscriber = { version = "0.3", features = [
"env-filter",
"tracing-log",
] }
uuid = { workspace = true, features = ["serde", "v4"] }

[target.'cfg(target_arch = "wasm32")'.dependencies]
opendal-service-opfs = { path = "services/opfs", version = "0.55.0", optional = true, default-features = false }
22 changes: 1 addition & 21 deletions core/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ internal-tokio-rt = ["tokio/rt-multi-thread"]
executors-tokio = ["tokio/rt"]

services-memory = []
services-redis = ["dep:redis", "dep:fastpool", "redis?/tokio-rustls-comp"]
services-redis-native-tls = ["services-redis", "redis?/tokio-native-tls-comp"]

[lib]
bench = false
Expand Down Expand Up @@ -87,27 +85,9 @@ url = "2.5"
uuid = { workspace = true, features = ["serde", "v4"] }

# Optional dependencies

# Services
# general dependencies.
fastpool = { version = "1.0.2", optional = true }
sha2 = { workspace = true, optional = true }

# For http based services.
reqsign = { workspace = true, features = ["reqwest_request"], optional = true }

# for services-moka
moka = { version = "0.12", optional = true, features = ["future", "sync"] }
# for services-redis
redis = { version = "1.0", features = [
"cluster-async",
"tokio-comp",
"connection-manager",
], optional = true }
moka = { version = "0.12", optional = true, features = ["sync"] }

[target.'cfg(target_arch = "wasm32")'.dependencies]
backon = { version = "1.6", features = ["gloo-timers-sleep"] }
getrandom = { version = "0.2", features = ["js"] }
jiff = { version = "0.2.15", features = ["serde", "js"] }
tokio = { workspace = true, features = ["time"] }
uuid = { workspace = true, features = ["serde", "v4", "js"] }
Expand Down
5 changes: 0 additions & 5 deletions core/core/src/services/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,3 @@
mod memory;
#[cfg(feature = "services-memory")]
pub use self::memory::*;

#[cfg(feature = "services-redis")]
mod redis;
#[cfg(feature = "services-redis")]
pub use self::redis::*;
53 changes: 53 additions & 0 deletions core/services/redis/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

[package]
description = "Apache OpenDAL Redis service implementation"
name = "opendal-service-redis"

authors = { workspace = true }
edition = { workspace = true }
homepage = { workspace = true }
license = { workspace = true }
repository = { workspace = true }
rust-version = { workspace = true }
version = { workspace = true }

[package.metadata.docs.rs]
all-features = true

[features]
default = ["rustls"]
native-tls = ["redis/tokio-native-tls-comp"]
rustls = ["redis/tokio-rustls-comp"]

[dependencies]
bytes = { workspace = true }
ctor = { workspace = true }
fastpool = "1.0.2"
http = { workspace = true }
opendal-core = { path = "../../core", version = "0.55.0", default-features = false }
redis = { version = "1.0", features = [
"cluster-async",
"tokio-comp",
"connection-manager",
] }
serde = { workspace = true, features = ["derive"] }
tokio = { workspace = true, features = ["macros", "time"] }

[dev-dependencies]
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ use std::path::PathBuf;
use std::sync::Arc;

use http::Uri;
use opendal_core::raw::*;
use opendal_core::*;
use redis::Client;
use redis::ConnectionAddr;
use redis::ConnectionInfo;
Expand All @@ -32,8 +34,6 @@ use super::config::RedisConfig;
use super::core::*;
use super::delete::RedisDeleter;
use super::writer::RedisWriter;
use crate::raw::*;
use crate::*;

const DEFAULT_REDIS_ENDPOINT: &str = "tcp://127.0.0.1:6379";
const DEFAULT_REDIS_PORT: u16 = 6379;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@

use std::fmt::Debug;

use opendal_core::raw::*;
use opendal_core::*;
use serde::Deserialize;
use serde::Serialize;

use super::REDIS_SCHEME;
use super::backend::RedisBuilder;
use crate::raw::*;

/// Config for Redis services support.
#[derive(Default, Serialize, Deserialize, Clone, PartialEq, Eq)]
Expand Down Expand Up @@ -74,18 +75,18 @@ impl Debug for RedisConfig {
}
}

impl crate::Configurator for RedisConfig {
impl Configurator for RedisConfig {
type Builder = RedisBuilder;

fn from_uri(uri: &crate::types::OperatorUri) -> crate::Result<Self> {
fn from_uri(uri: &OperatorUri) -> Result<Self> {
let mut map = uri.options().clone();

if let Some(authority) = uri.authority() {
map.entry("endpoint".to_string())
.or_insert_with(|| format!("redis://{authority}"));
} else if !map.contains_key("endpoint") && !map.contains_key("cluster_endpoints") {
return Err(crate::Error::new(
crate::ErrorKind::ConfigInvalid,
return Err(Error::new(
ErrorKind::ConfigInvalid,
"endpoint or cluster_endpoints is required",
)
.with_context("service", REDIS_SCHEME));
Expand Down Expand Up @@ -126,35 +127,33 @@ impl crate::Configurator for RedisConfig {
#[cfg(test)]
mod tests {
use super::*;
use crate::Configurator;
use crate::types::OperatorUri;

#[test]
fn from_uri_sets_endpoint_db_and_root() {
fn from_uri_sets_endpoint_db_and_root() -> Result<()> {
let uri = OperatorUri::new(
"redis://localhost:6379/2/cache",
Vec::<(String, String)>::new(),
)
.unwrap();
)?;

let cfg = RedisConfig::from_uri(&uri).unwrap();
let cfg = RedisConfig::from_uri(&uri)?;
assert_eq!(cfg.endpoint.as_deref(), Some("redis://localhost:6379"));
assert_eq!(cfg.db, 2);
assert_eq!(cfg.root.as_deref(), Some("cache"));
Ok(())
}

#[test]
fn from_uri_treats_non_numeric_path_as_root() {
fn from_uri_treats_non_numeric_path_as_root() -> Result<()> {
let uri = OperatorUri::new(
"redis://localhost:6379/app/data",
Vec::<(String, String)>::new(),
)
.unwrap();
)?;

let cfg = RedisConfig::from_uri(&uri).unwrap();
let cfg = RedisConfig::from_uri(&uri)?;
assert_eq!(cfg.endpoint.as_deref(), Some("redis://localhost:6379"));
assert_eq!(cfg.db, 0);
assert_eq!(cfg.root.as_deref(), Some("app/data"));
Ok(())
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ use redis::aio::ConnectionManager;
use redis::cluster::ClusterClient;
use redis::cluster_async::ClusterConnection;

use crate::raw::*;
use crate::*;
use opendal_core::raw::*;
use opendal_core::*;

#[derive(Clone)]
pub enum RedisConnection {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@
// specific language governing permissions and limitations
// under the License.

use std::sync::Arc;

use opendal_core::raw::*;
use opendal_core::*;

use super::core::RedisCore;
use crate::raw::oio;
use crate::raw::*;
use crate::*;

pub struct RedisDeleter {
core: std::sync::Arc<RedisCore>,
core: Arc<RedisCore>,
root: String,
}

impl RedisDeleter {
pub fn new(core: std::sync::Arc<RedisCore>, root: String) -> Self {
pub fn new(core: Arc<RedisCore>, root: String) -> Self {
Self { core, root }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ You can refer to [`RedisBuilder`]'s docs for more information
### Via Builder

```rust,no_run
use anyhow::Result;
use opendal_core::services::Redis;
use opendal_core::Operator;
use opendal_core::Result;
use opendal_service_redis::Redis;

#[tokio::main]
async fn main() -> Result<()> {
Expand Down
Loading
Loading