GithubHelp home page GithubHelp logo

isabella232 / redis-rs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from redislabs/redis-rs

0.0 0.0 0.0 2.21 MB

Redis library for rust

Home Page: https://docs.rs/redis

License: Other

Makefile 0.44% Rust 99.28% Shell 0.29%

redis-rs's Introduction

redis-rs

Build Status crates.io

Redis-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 redis and you can depend on it via cargo:

[dependencies]
redis = "0.20.0"

Documentation on the library can be found at docs.rs/redis.

Note: redis-rs requires at least Rust 1.39.

Basic Operation

To 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 Commands trait but manual command creation is also possible.

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 support

To enable asynchronous clients a feature for the underlying feature need to be activated.

# if you use tokio
redis = { version = "0.17.0", features = ["tokio-comp"] }

# if you use async-std
redis = { version = "0.17.0", features = ["async-std-comp"] }

TLS Support

To enable TLS support, you need to use the relevant feature entry in your Cargo.toml.

redis = { version = "0.19.0", features = ["tls"] }

# if you use tokio
redis = { version = "0.19.0", features = ["tokio-native-tls-comp"] }

# if you use async-std
redis = { version = "0.19.0", features = ["async-std-tls-comp"] }

then you should be able to connect to a redis instance using the rediss:// URL scheme:

let client = redis::Client::open("rediss://127.0.0.1/")?;

Cluster Support

Cluster mode can be used by specifying "cluster" as a features entry in your Cargo.toml.

redis = { version = "0.17.0", features = [ "cluster"] }

Then you can simply use the ClusterClient which accepts a list of available nodes.

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;
}

Development

If you want to develop on the library there are a few commands provided by the makefile:

To build:

$ make

To test:

$ make test

To run benchmarks:

$ make bench

To build the docs (require nightly compiler, see rust-lang/rust#43781):

$ make docs

We encourage you to run clippy prior to seeking a merge for your work. The lints can be quite strict. Running this on your own workstation can save you time, since Travis CI will fail any build that doesn't satisfy clippy:

$ cargo clippy --all-features --all --tests --examples -- -D clippy::all -D warnings

To run fuzz tests with afl, first install cargo-afl (cargo install -f afl), then run:

$ make fuzz

If the fuzzer finds a crash, in order to reproduce it, run:

$ cd afl/<target>/
$ cargo run --bin reproduce -- out/crashes/<crashfile>

redis-rs's People

Contributors

astro avatar ayosec avatar badboy avatar davidbm avatar dbrgn avatar doyshinda avatar dsander avatar emschwartz avatar engylemure avatar evdokimovs avatar gavrie avatar gferon avatar hadashia avatar harrydevnull avatar hiratara avatar jan-auer avatar jwilm avatar marcoieni avatar marwes avatar mattcollier avatar michael-grunder avatar mitsuhiko avatar npajkovsky avatar przygienda avatar swilcox3 avatar terkwood avatar theglenn88 avatar tsnoam avatar weihanglo avatar yoav-steinberg avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.