在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):redis-rs/redis-rs开源软件地址(OpenSource Url):https://github.com/redis-rs/redis-rs开源编程语言(OpenSource Language):Rust 99.3%开源软件介绍(OpenSource Introduction):redis-rsRedis-rs is a high level redis library for Rust. It provides convenient access to all Redis functionality through a very flexible but low-level API. It uses a customizable type conversion trait so that any operation can return results in just the type you are expecting. This makes for a very pleasant development experience. The crate is called [dependencies]
redis = "0.21.5" Documentation on the library can be found at docs.rs/redis. Note: redis-rs requires at least Rust 1.51. Basic OperationTo open a connection you need to create a client and then to fetch a connection from it. In the future there will be a connection pool for those, currently each connection is separate and not pooled. Many commands are implemented through the extern crate redis;
use redis::Commands;
fn fetch_an_integer() -> redis::RedisResult<isize> {
// connect to redis
let client = redis::Client::open("redis://127.0.0.1/")?;
let mut con = client.get_connection()?;
// throw away the result, just make sure it does not fail
let _ : () = con.set("my_key", 42)?;
// read back the key and return it. Because the return value
// from the function is a result for integer this will automatically
// convert into one.
con.get("my_key")
} Async supportTo enable asynchronous clients a feature for the underlying feature need to be activated.
TLS SupportTo enable TLS support, you need to use the relevant feature entry in your Cargo.toml.
then you should be able to connect to a redis instance using the let client = redis::Client::open("rediss://127.0.0.1/")?; Cluster SupportCluster mode can be used by specifying "cluster" as a features entry in your Cargo.toml.
Then you can simply use the use redis::cluster::ClusterClient;
use redis::Commands;
fn fetch_an_integer() -> String {
// connect to redis
let nodes = vec!["redis://127.0.0.1/"];
let client = ClusterClient::open(nodes).unwrap();
let mut connection = client.get_connection().unwrap();
let _: () = connection.set("test", "test_data").unwrap();
let rv: String = connection.get("test").unwrap();
return rv;
} DevelopmentIf you want to develop on the library there are a few commands provided by the makefile: To build:
To test:
To run benchmarks:
To build the docs (require nightly compiler, see rust-lang/rust#43781):
We encourage you to run
To run fuzz tests with afl, first install cargo-afl (
If the fuzzer finds a crash, in order to reproduce it, run:
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论