Git Product home page Git Product logo

redis-cluster-async's Introduction

MIT licensed

A Rust crate implementing a Redis cluster client.

Documentation is available at here.

This library builds upon the redis-rs crate to enable working with a Redis cluster (instead of single Redis nodes).

Example

extern crate futures;
extern crate tokio;
use futures::prelude::*;
use redis_cluster_async::{Client, redis::cmd};

fn main() {
    let nodes = vec!["redis://127.0.0.1:6379/", "redis://127.0.0.1:6378/", "redis://127.0.0.1:6377/"];

    let mut runtime = tokio::runtime::Runtime::new().unwrap();

    let client = Client::open(nodes).unwrap();
    let (_, res): (_, String) = runtime.block_on(client.get_connection()
        .and_then(|connection| {
            cmd("SET").arg("test").arg("test_data").clone()
                .query_async(connection)
                .and_then(|(connection, ())| 
                    cmd("GET").arg("test")
                        .query_async(connection)
                )
        })
        )
        .unwrap();

    assert_eq!(res, "test_data");
}

Pipelining

extern crate futures;
extern crate tokio;

use futures::prelude::*;
use redis_cluster_async::{Client, redis::{PipelineCommands, pipe}};

fn main() {
    let nodes = vec!["redis://127.0.0.1:6379/", "redis://127.0.0.1:6378/", "redis://127.0.0.1:6377/"];

    let mut runtime = tokio::runtime::Runtime::new().unwrap();

    let client = Client::open(nodes).unwrap();
    let _: (_, ()) = runtime.block_on(
        client.get_connection().and_then(|connection| {
            let key = "test";

            pipe()
                .rpush(key, "123").ignore()
                .ltrim(key, -10, -1).ignore()
                .expire(key, 60).ignore()
                .query_async(connection)
        }))
        .unwrap();

}

Acknowledgements

This project is built upon the synchronous redis cluster implementation in https://github.com/atuk721/redis-cluster-rs .

redis-cluster-async's People

Contributors

atuk721 avatar emilhernvall avatar jaymell avatar jensenn avatar marwes avatar svix-daniel avatar

Watchers

 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.