All Projects → sagiegurari → simple_redis

sagiegurari / simple_redis

Licence: Apache-2.0 license
Simple and resilient redis client for rust.

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to simple redis

Iodine
iodine - HTTP / WebSockets Server for Ruby with Pub/Sub support
Stars: ✭ 720 (+3328.57%)
Mutual labels:  pubsub, redis-client
Facil.io
Your high performance web application C framework
Stars: ✭ 1,393 (+6533.33%)
Mutual labels:  pubsub, redis-client
Cachingframework.redis
Distributed caching based on StackExchange.Redis and Redis. Includes support for tagging and is cluster-compatible.
Stars: ✭ 209 (+895.24%)
Mutual labels:  pubsub, redis-client
unicode-linebreak
󠁼💔 Implementation of the Unicode Line Breaking Algorithm in Rust
Stars: ✭ 14 (-33.33%)
Mutual labels:  rust-library
node-redis-connection-pool
A node.js connection manager for Redis
Stars: ✭ 52 (+147.62%)
Mutual labels:  redis-client
kane
Google Pub/Sub client for Elixir
Stars: ✭ 92 (+338.1%)
Mutual labels:  pubsub
Pubbie
A high performance pubsub client/server implementation for .NET Core
Stars: ✭ 122 (+480.95%)
Mutual labels:  pubsub
ipfs-chat
Real-time P2P messenger using go-ipfs pubsub. TUI. End-to-end encrypted texting & file-sharing. NAT traversal.
Stars: ✭ 84 (+300%)
Mutual labels:  pubsub
metamorphosis
Easy and flexible Kafka Library for Laravel and PHP 7
Stars: ✭ 39 (+85.71%)
Mutual labels:  pubsub
requests-rs
Rust HTTP client library styled after awesome Python requests
Stars: ✭ 37 (+76.19%)
Mutual labels:  rust-library
CloudStructures
Redis Client based on StackExchange.Redis.
Stars: ✭ 124 (+490.48%)
Mutual labels:  redis-client
pg-ipc
IPC over PostgreSQL LISTEN/NOTIFY/UNLISTEN exposed as an EventEmitter
Stars: ✭ 27 (+28.57%)
Mutual labels:  pubsub
font8x8-rs
8x8 monochrome bitmap fonts for rendering. Implemented in Rust.
Stars: ✭ 15 (-28.57%)
Mutual labels:  rust-library
thread-priority
A simple thread schedule and priority library for rust
Stars: ✭ 48 (+128.57%)
Mutual labels:  rust-library
talek
a Private Publish Subscribe System
Stars: ✭ 39 (+85.71%)
Mutual labels:  pubsub
healthchecks-rs
Simple Rust library to interact with healthchecks.io
Stars: ✭ 16 (-23.81%)
Mutual labels:  rust-library
java-redis-client
OpenTracing Instrumentation for Redis Client
Stars: ✭ 31 (+47.62%)
Mutual labels:  redis-client
console-chat
Chat on your terminal with other users through a gRPC service
Stars: ✭ 21 (+0%)
Mutual labels:  pubsub
emulator-tools
Google Cloud BigTable and PubSub emulator tools to make development a breeze
Stars: ✭ 16 (-23.81%)
Mutual labels:  pubsub
iris3
An upgraded and improved version of the Iris automatic GCP-labeling project
Stars: ✭ 38 (+80.95%)
Mutual labels:  pubsub

simple_redis

crates.io CI codecov
license Libraries.io for GitHub Documentation downloads
Built with cargo-make

Simple and resilient redis client for rust.

Overview

This library provides a very basic, simple API for the most common redis operations.
While not as comprehensive or flexible as redis-rs, it does provide a simpler api for most common use cases and operations as well as automatic and resilient internal connection and subscription (pubsub) handling.
In addition, the entire API is accessible via simple client interface and there is no need to manage multiple entities such as connection or pubsub in parallel.

Connection Resiliency

Connection resiliency is managed by verifying the internally managed connection before every operation against the redis server.
In case of any connection issue, a new connection will be allocated to ensure the operation is invoked on a valid connection only.
However, this comes at a small performance cost of PING operation to the redis server.

//! In redis-rs, connections are no longer usable in case the connection is broken and if operations are invoked on the client directly, it will basically open a new connection for every operation which is very costly.

Subscription Resiliency

Subscription resiliency is ensured by recreating the internal pubsub and issuing new subscription requests automatically in case of any error while fetching a message from the subscribed channels.

redis-rs doesn't provide any such automatic resiliency and re-subscription capabilities.

Usage

Initialization and Simple Operations

fn main() {
    match simple_redis::create("redis://127.0.0.1:6379/") {
        Ok(mut client) => {
            println!("Created Redis Client");

            match client.set("my_key", "my_value") {
                Err(error) => println!("Unable to set value in Redis: {}", error),
                _ => println!("Value set in Redis"),
            };

            match client.get_string("my_key") {
                Ok(value) => println!("Read value from Redis: {}", value),
                Err(error) => println!("Unable to get value from Redis: {}", error),
            };

            match client.set("my_numeric_key", 255.5) {
                Err(error) => println!("Unable to set value in Redis: {}", error),
                _ => println!("Value set in Redis"),
            };

            match client.get::<f32>("my_numeric_key") {
                Ok(value) => println!("Read value from Redis: {}", value),
                Err(error) => println!("Unable to get value from Redis: {}", error),
            };

            match client.hgetall("my_map") {
                Ok(map) => match map.get("my_field") {
                    Some(value) => println!("Got field value from map: {}", value),
                    None => println!("Map field is empty"),
                },
                Err(error) => println!("Unable to read map from Redis: {}", error),
            };

            // run some command that is not built in the library
            match client.run_command::<String>("ECHO", vec!["testing"]) {
                Ok(value) => assert_eq!(value, "testing"),
                _ => panic!("test error"),
            };

            // publish messages
            let result = client.publish("news_channel", "test message");
            assert!(result.is_ok());
        }
        Err(error) => println!("Unable to create Redis client: {}", error),
    }
}

Subscription Flow

use simple_redis::{Interrupts, Message};

fn main() {
    match simple_redis::create("redis://127.0.0.1:6379/") {
        Ok(mut client) => {
            println!("Created Redis Client");

            let mut result = client.subscribe("important_notifications");
            assert!(result.is_ok());
            result = client.psubscribe("*_notifications");
            assert!(result.is_ok());

            // fetch messages from all subscriptions
            let mut polling_counter: usize = 0;
            client
                .fetch_messages(
                    &mut |message: Message| -> bool {
                        let payload: String = message.get_payload().unwrap();
                        println!("Got message: {}", payload);

                        // continue fetching
                        false
                    },
                    // interrupts enable you to break the fetching blocking call
                    &mut || -> Interrupts {
                        let mut interrupts = Interrupts::new();
                        interrupts.next_polling_time = Some(150);

                        polling_counter = polling_counter + 1;
                        if polling_counter > 3 {
                            interrupts.stop = true;
                        }

                        interrupts
                    },
                )
                .unwrap();
        }
        Err(error) => println!("Unable to create Redis client: {}", error),
    }
}

Closing Connection

fn main() {
    match simple_redis::create("redis://127.0.0.1:6379/") {
        Ok(mut client) => {
            println!("Created Redis Client");

            match client.set("my_key", "my_value") {
                Err(error) => println!("Unable to set value in Redis: {}", error),
                _ => println!("Value set in Redis"),
            };

            match client.quit() {
                Err(error) => println!("Error: {}", error),
                _ => println!("Connection Closed."),
            }
        }
        Err(error) => println!("Unable to create Redis client: {}", error),
    }
}

Installation

In order to use this library, just add it as a dependency:

[dependencies]
simple_redis = "^0.6.1"

API Documentation

See full docs at: API Docs

Contributing

See contributing guide

Release History

See Changelog

License

Developed by Sagie Gur-Ari and licensed under the Apache 2 open source license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].