Skip to main content

Redis

Redis services support.

Capabilities

This service can be used to:

  • stat
  • read
  • write
  • create_dir
  • delete
  • copy
  • rename
  • list
  • scan
  • presign
  • blocking

Configuration

  • root: Set the working directory of OpenDAL
  • endpoint: Set the network address of redis server
  • cluster_endpoints: Set the network address of redis cluster server. This parameter is mutually exclusive with the endpoint parameter.
  • username: Set the username of Redis
  • password: Set the password for authentication
  • db: Set the DB of redis

You can refer to [RedisBuilder]'s docs for more information

Example

Via Builder

use anyhow::Result;
use opendal::services::Redis;
use opendal::Operator;

#[tokio::main]
async fn main() -> Result<()> {
let mut builder = Redis::default();

// this will build a Operator accessing Redis which runs on tcp://localhost:6379
let op: Operator = Operator::new(builder)?.finish();
Ok(())
}

Via Config

use anyhow::Result;
use opendal::Operator;
use opendal::Scheme;
use std::collections::HashMap;

#[tokio::main]
async fn main() -> Result<()> {
let mut map = HashMap::new();
map.insert("root".to_string(), "/path/to/dir".to_string());
map.insert("endpoint".to_string(), "tcp://127.0.0.1:6379".to_string());
map.insert("username".to_string(), "your_username".to_string());
map.insert("password".to_string(), "your_password".to_string());
map.insert("db".to_string(), "0".to_string());

let op: Operator = Operator::via_map(Scheme::Redis, map)?;
Ok(())
}