{"id":17002040,"url":"https://github.com/sagiegurari/simple_redis","last_synced_at":"2025-08-09T09:24:08.732Z","repository":{"id":48595676,"uuid":"93156669","full_name":"sagiegurari/simple_redis","owner":"sagiegurari","description":"Simple and resilient redis client for rust.","archived":false,"fork":false,"pushed_at":"2024-07-29T13:34:22.000Z","size":4015,"stargazers_count":25,"open_issues_count":0,"forks_count":8,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-01-21T07:05:31.436Z","etag":null,"topics":["database","pubsub","redis","redis-client","rust","rust-library"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sagiegurari.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-02T10:50:48.000Z","updated_at":"2024-07-31T09:56:52.000Z","dependencies_parsed_at":"2024-07-29T17:10:41.257Z","dependency_job_id":"4b8a59bf-f231-4eef-b913-b43bc11ec048","html_url":"https://github.com/sagiegurari/simple_redis","commit_stats":{"total_commits":176,"total_committers":3,"mean_commits":"58.666666666666664","dds":"0.051136363636363646","last_synced_commit":"4c7fe7f5207b10ac231d83760fd07cf4ef803f6f"},"previous_names":[],"tags_count":55,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagiegurari%2Fsimple_redis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagiegurari%2Fsimple_redis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagiegurari%2Fsimple_redis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagiegurari%2Fsimple_redis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sagiegurari","download_url":"https://codeload.github.com/sagiegurari/simple_redis/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":236102619,"owners_count":19095206,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","pubsub","redis","redis-client","rust","rust-library"],"created_at":"2024-10-14T04:26:55.958Z","updated_at":"2025-01-28T23:07:36.129Z","avatar_url":"https://github.com/sagiegurari.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# simple_redis\n\n[![crates.io](https://img.shields.io/crates/v/simple_redis.svg)](https://crates.io/crates/simple_redis) [![CI](https://github.com/sagiegurari/simple_redis/workflows/CI/badge.svg?branch=master)](https://github.com/sagiegurari/simple_redis/actions) [![codecov](https://codecov.io/gh/sagiegurari/simple_redis/branch/master/graph/badge.svg)](https://codecov.io/gh/sagiegurari/simple_redis)\u003cbr\u003e\n[![license](https://img.shields.io/crates/l/simple_redis.svg)](https://github.com/sagiegurari/simple_redis/blob/master/LICENSE) [![Libraries.io for GitHub](https://img.shields.io/librariesio/github/sagiegurari/simple_redis.svg)](https://libraries.io/cargo/simple_redis) [![Documentation](https://docs.rs/simple_redis/badge.svg)](https://docs.rs/crate/simple_redis/) [![downloads](https://img.shields.io/crates/d/simple_redis.svg)](https://crates.io/crates/simple_redis)\u003cbr\u003e\n[![Built with cargo-make](https://sagiegurari.github.io/cargo-make/assets/badges/cargo-make.svg)](https://sagiegurari.github.io/cargo-make)\n\n\u003e Simple and resilient [redis](https://redis.io/) client for [rust](https://www.rust-lang.org/).\n\n* [Overview](#overview)\n    * [Connection Resiliency](#overview-connection)\n    * [Subscription Resiliency](#overview-subscription)\n* [Usage](#usage)\n* [Installation](#installation)\n* [API Documentation](https://sagiegurari.github.io/simple_redis/)\n* [Contributing](.github/CONTRIBUTING.md)\n* [Release History](CHANGELOG.md)\n* [License](#license)\n\n\u003ca name=\"overview\"\u003e\u003c/a\u003e\n## Overview\nThis library provides a very basic, simple API for the most common redis operations.\u003cbr\u003e\nWhile not as comprehensive or flexible as [redis-rs](https://crates.io/crates/redis),\nit does provide a simpler api for most common use cases and operations as well as automatic and resilient internal connection\nand subscription (pubsub) handling.\u003cbr\u003e\nIn 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.\u003cbr\u003e\n\n\u003ca name=\"overview-connection\"\u003e\u003c/a\u003e\n### Connection Resiliency\nConnection resiliency is managed by verifying the internally managed connection before every operation against the redis server.\u003cbr\u003e\nIn case of any connection issue, a new connection will be allocated to ensure the operation is invoked on a valid\nconnection only.\u003cbr\u003e\nHowever, this comes at a small performance cost of PING operation to the redis server.\u003cbr\u003e\n\u003cbr\u003e\n//!\n*In [redis-rs](https://crates.io/crates/redis), connections are no longer usable in case the connection is broken and if operations are invoked\non the client directly, it will basically open a new connection for every operation which is very costly.*\n\n\u003ca name=\"overview-subscription\"\u003e\u003c/a\u003e\n### Subscription Resiliency\nSubscription resiliency is ensured by recreating the internal pubsub and issuing new subscription requests\nautomatically in case of any error while fetching a message from the subscribed channels.\u003cbr\u003e\n\u003cbr\u003e\n*[redis-rs](https://crates.io/crates/redis) doesn't provide any such automatic resiliency and re-subscription capabilities.*\n\n\n\u003ca name=\"usage\"\u003e\u003c/a\u003e\n## Usage\n\n### Initialization and Simple Operations\n\n\u003c!--{ \"examples/init_and_simple_operations.rs\" | lines: 3 | code: rust }--\u003e\n```rust\nfn main() {\n    match simple_redis::create(\"redis://127.0.0.1:6379/\") {\n        Ok(mut client) =\u003e {\n            println!(\"Created Redis Client\");\n\n            match client.set(\"my_key\", \"my_value\") {\n                Err(error) =\u003e println!(\"Unable to set value in Redis: {}\", error),\n                _ =\u003e println!(\"Value set in Redis\"),\n            };\n\n            match client.get_string(\"my_key\") {\n                Ok(value) =\u003e println!(\"Read value from Redis: {}\", value),\n                Err(error) =\u003e println!(\"Unable to get value from Redis: {}\", error),\n            };\n\n            match client.set(\"my_numeric_key\", 255.5) {\n                Err(error) =\u003e println!(\"Unable to set value in Redis: {}\", error),\n                _ =\u003e println!(\"Value set in Redis\"),\n            };\n\n            match client.get::\u003cf32\u003e(\"my_numeric_key\") {\n                Ok(value) =\u003e println!(\"Read value from Redis: {}\", value),\n                Err(error) =\u003e println!(\"Unable to get value from Redis: {}\", error),\n            };\n\n            match client.hgetall(\"my_map\") {\n                Ok(map) =\u003e match map.get(\"my_field\") {\n                    Some(value) =\u003e println!(\"Got field value from map: {}\", value),\n                    None =\u003e println!(\"Map field is empty\"),\n                },\n                Err(error) =\u003e println!(\"Unable to read map from Redis: {}\", error),\n            };\n\n            // run some command that is not built in the library\n            match client.run_command::\u003cString\u003e(\"ECHO\", vec![\"testing\"]) {\n                Ok(value) =\u003e assert_eq!(value, \"testing\"),\n                _ =\u003e panic!(\"test error\"),\n            };\n\n            // publish messages\n            let result = client.publish(\"news_channel\", \"test message\");\n            assert!(result.is_ok());\n        }\n        Err(error) =\u003e println!(\"Unable to create Redis client: {}\", error),\n    }\n}\n```\n\u003c!--{ end }--\u003e\n\n### Subscription Flow\n\n\u003c!--{ \"examples/subscription_flow.rs\" | lines: 2 | code: rust }--\u003e\n```rust\nuse simple_redis::{Interrupts, Message};\n\nfn main() {\n    match simple_redis::create(\"redis://127.0.0.1:6379/\") {\n        Ok(mut client) =\u003e {\n            println!(\"Created Redis Client\");\n\n            let mut result = client.subscribe(\"important_notifications\");\n            assert!(result.is_ok());\n            result = client.psubscribe(\"*_notifications\");\n            assert!(result.is_ok());\n\n            // fetch messages from all subscriptions\n            let mut polling_counter: usize = 0;\n            client\n                .fetch_messages(\n                    \u0026mut |message: Message| -\u003e bool {\n                        let payload: String = message.get_payload().unwrap();\n                        println!(\"Got message: {}\", payload);\n\n                        // continue fetching\n                        false\n                    },\n                    // interrupts enable you to break the fetching blocking call\n                    \u0026mut || -\u003e Interrupts {\n                        let mut interrupts = Interrupts::new();\n                        interrupts.next_polling_time = Some(150);\n\n                        polling_counter = polling_counter + 1;\n                        if polling_counter \u003e 3 {\n                            interrupts.stop = true;\n                        }\n\n                        interrupts\n                    },\n                )\n                .unwrap();\n        }\n        Err(error) =\u003e println!(\"Unable to create Redis client: {}\", error),\n    }\n}\n```\n\u003c!--{ end }--\u003e\n\n### Closing Connection\n\n\u003c!--{ \"examples/open_close_connection.rs\" | lines: 3 | code: rust }--\u003e\n```rust\nfn main() {\n    match simple_redis::create(\"redis://127.0.0.1:6379/\") {\n        Ok(mut client) =\u003e {\n            println!(\"Created Redis Client\");\n\n            match client.set(\"my_key\", \"my_value\") {\n                Err(error) =\u003e println!(\"Unable to set value in Redis: {}\", error),\n                _ =\u003e println!(\"Value set in Redis\"),\n            };\n\n            match client.quit() {\n                Err(error) =\u003e println!(\"Error: {}\", error),\n                _ =\u003e println!(\"Connection Closed.\"),\n            }\n        }\n        Err(error) =\u003e println!(\"Unable to create Redis client: {}\", error),\n    }\n}\n```\n\u003c!--{ end }--\u003e\n\n\u003ca name=\"installation\"\u003e\u003c/a\u003e\n## Installation\nIn order to use this library, just add it as a dependency:\n\n```ini\n[dependencies]\nsimple_redis = \"^0.6.4\"\n```\n\n## API Documentation\nSee full docs at: [API Docs](https://sagiegurari.github.io/simple_redis/)\n\n## Contributing\nSee [contributing guide](.github/CONTRIBUTING.md)\n\n\u003ca name=\"history\"\u003e\u003c/a\u003e\n## Release History\n\nSee [Changelog](CHANGELOG.md)\n\n\u003ca name=\"license\"\u003e\u003c/a\u003e\n## License\nDeveloped by Sagie Gur-Ari and licensed under the Apache 2 open source license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsagiegurari%2Fsimple_redis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsagiegurari%2Fsimple_redis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsagiegurari%2Fsimple_redis/lists"}