Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 2 additions & 1 deletion build/components/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
'go': '//',
'c#': '//',
'redisvl': '#',
'php': '//'
'php': '//',
'rust': '//'
}


Expand Down
6 changes: 4 additions & 2 deletions build/local_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
'.go': 'go',
'.cs': 'c#',
'.java': 'java',
'.php': 'php'
'.php': 'php',
'.rs': 'rust'
}

# Language to client name mapping (from config.toml clientsExamples)
Expand All @@ -36,7 +37,8 @@
'c#': 'C#',
'java': 'Java-Sync', # Default to sync, could be overridden
'php': 'PHP',
'redisvl': 'RedisVL'
'redisvl': 'RedisVL',
'rust': 'Rust'
}


Expand Down
3 changes: 2 additions & 1 deletion config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ tagManagerId = "GTM-TKZ6J9R"
gitHubRepo = "https://github.com/redis/docs"

# Display and sort order for client examples
clientsExamples = ["Python", "Node.js", "Java-Sync", "Java-Async", "Java-Reactive", "Go", "C#", "RedisVL", "PHP"]
clientsExamples = ["Python", "Node.js", "Java-Sync", "Java-Async", "Java-Reactive", "Go", "C#", "RedisVL", "PHP", "Rust"]
searchService = "/convai/api/search-service"
ratingsService = "/docusight/api/rate"

Expand All @@ -67,6 +67,7 @@ rdi_current_version = "1.14.1"
"C#"={quickstartSlug="dotnet"}
"RedisVL"={quickstartSlug="redis-vl"}
"PHP"={quickstartSlug="php"}
"Rust"={quickstartSlug="redis-rs"}

# Markup
[markup]
Expand Down
4 changes: 2 additions & 2 deletions content/develop/clients/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ weight: 30

Use the Redis client libraries to connect to Redis servers from
your own code. We document the following client libraries
for seven main languages:
for eight main languages:

| Language | Client name | Docs | Supported |
| :-- | :-- | :-- | :-- |
Expand All @@ -32,6 +32,7 @@ for seven main languages:
| [Go](https://go.dev/) | [`go-redis`](https://github.com/redis/go-redis) | [`go-redis` guide]({{< relref "/develop/clients/go" >}}) | Yes |
| [PHP](https://www.php.net/)| [`Predis`](https://github.com/predis/predis) | [`Predis` guide]({{< relref "/develop/clients/php" >}}) | No |
| [C](https://en.wikipedia.org/wiki/C_(programming_language)) | [`hiredis`](https://github.com/redis/hiredis) | [`hiredis` guide]({{< relref "/develop/clients/hiredis" >}}) | Yes |
| [Rust](https://www.rust-lang.org/) | [`redis-rs`](https://github.com/redis-rs/redis-rs) | [`redis-rs` guide]({{< relref "/develop/clients/rust" >}}) | No |

We also provide several higher-level
[object mapping (OM)]({{< relref "/develop/clients/om-clients" >}})
Expand All @@ -51,7 +52,6 @@ Redis does not document directly:
| [Dart](https://dart.dev/) | redis_dart_link | https://github.com/toolsetlink/redis_dart_link | https://github.com/toolsetlink/redis_dart_link |
| [PHP](https://www.php.net/) | PhpRedis extension | https://github.com/phpredis/phpredis | https://github.com/phpredis/phpredis/blob/develop/README.md |
| [Ruby](https://www.ruby-lang.org/en/) | redis-rb | https://github.com/redis/redis-rb | https://rubydoc.info/gems/redis |
| [Rust](https://www.rust-lang.org/) | redis-rs | https://github.com/redis-rs/redis-rs | https://docs.rs/redis/latest/redis/ |


## Requirements
Expand Down
63 changes: 63 additions & 0 deletions content/develop/clients/rust/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
categories:
- docs
- develop
- stack
- oss
- rs
- rc
- oss
- kubernetes
- clients
description: Connect your Rust application to a Redis database
linkTitle: redis-rs (Rust)
title: redis-rs guide (Rust)
weight: 9
---

[`redis-rs`](https://github.com/redis-rs/redis-rs) is the [Rust](https://www.rust-lang.org/) client for Redis.
The sections below explain how to install `redis-rs` and connect your application to a Redis database.

{{< note >}}Although we provide basic documentation for `redis-rs`, it is a third-party
client library and is not developed or supported directly by Redis.
{{< /note >}}

`redis-rs` requires a running Redis server. See [here]({{< relref "/operate/oss_and_stack/install/" >}}) for Redis Open Source installation instructions.

## Install

Add the `redis` crate as a dependency in your `Cargo.toml` file:

```toml
[dependencies]
redis = "0.32.5"
```

## Connect

Start by importing the `Commands` trait from the `redis` crate:

{{< clients-example set="landing" step="import" lang_filter="Rust" >}}
{{< /clients-example >}}

The following example shows the simplest way to connect to a Redis server:

{{< clients-example set="landing" step="connect" lang_filter="Rust" >}}
{{< /clients-example >}}

After connecting, you can test the connection by storing and retrieving
a simple [string]({{< relref "/develop/data-types/strings" >}}):

{{< clients-example set="landing" step="set_get_string" lang_filter="Rust" >}}
{{< /clients-example >}}

You can also easily store and retrieve a [hash]({{< relref "/develop/data-types/hashes" >}}):

{{< clients-example set="landing" step="set_get_hash" lang_filter="Rust" >}}
{{< /clients-example >}}

## More information

See the [`redis-rs`](https://docs.rs/redis/latest/redis/) documentation
and the [GitHub repository](https://github.com/redis-rs/redis-rs) for more
information and examples.
15 changes: 15 additions & 0 deletions data/components/redis-rs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"id": "redis_rs",
"type": "client",
"name": "redis-rs",
"language": "Rust",
"label": "Rust",
"repository": {
"git_uri": "https://github.com/redis-rs/redis-rs"
},
"examples": {
"git_uri": "https://github.com/redis-rs/redis-rs",
"path": "redis/examples",
"pattern": "*.rs"
}
}
99 changes: 99 additions & 0 deletions local_examples/client-specific/rust/landing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// EXAMPLE: landing
// STEP_START import
use redis::Commands;
// STEP_END

fn main() {
// STEP_START connect
let mut r = match redis::Client::open("redis://127.0.0.1") {
Ok(client) => {
match client.get_connection() {
Ok(conn) => conn,
Err(e) => {
println!("Failed to connect to Redis: {}", e);
return;
}
}
},
Err(e) => {
println!("Failed to create Redis client: {}", e);
return;
}
};
// STEP_END

// STEP_START set_get_string
if let Ok(res) = r.set("foo", "bar") {
let res: String = res;
println!("{}", res); // >>> OK
} else {
println!("Error setting foo");
}

match r.get("foo") {
Ok(res) => {
let res: String = res;
println!("{}", res); // >>> bar
},
Err(e) => {
println!("Error getting foo: {}", e);
return;
}
};
// STEP_END

// STEP_START set_get_hash
let hash_fields = [
("model", "Deimos"),
("brand", "Ergonom"),
("type", "Enduro bikes"),
("price", "4972"),
];

if let Ok(res) = r.hset_multiple("bike:1", &hash_fields) {
let res: String = res;
println!("{}", res); // >>> OK
} else {
println!("Error setting bike:1");
}

match r.hget("bike:1", "model") {
Ok(res) => {
let res: String = res;
println!("{}", res); // >>> Deimos
},
Err(e) => {
println!("Error getting bike:1: {}", e);
return;
}
}

match r.hget("bike:1", "price") {
Ok(res) => {
let res: String = res;
println!("{}", res); // >>> 4972
},
Err(e) => {
println!("Error getting bike:1: {}", e);
return;
}
}

match r.hgetall("bike:1") {
Ok(res) => {
let res: Vec<(String, String)> = res;
for (key, value) in res {
println!("{}: {}", key, value);
}
// >>> model: Deimos
// >>> brand: Ergonom
// >>> type: Enduro bikes
// >>> price: 4972
},
Err(e) => {
println!("Error getting bike:1: {}", e);
return;
}
}
// STEP_END
}