Crates.io | redis_events |
lib.rs | redis_events |
version | 0.1.0 |
source | src |
created_at | 2024-09-26 23:11:40.674672 |
updated_at | 2024-09-26 23:11:40.674672 |
description | Redis Events is a Rust library that provides a simple and efficient way to watch for changes in Redis hash fields. It allows you to register callbacks for specific hash:field combinations and automatically triggers these callbacks when the values change. Uses polling under the hood allowing you to set polling rate based on your needs. |
homepage | |
repository | https://github.com/heety313/redis_events |
max_upload_size | |
id | 1388077 |
size | 17,007 |
Redis Events is a Rust library that provides a simple and efficient way to watch for changes in Redis hash fields. It allows you to register callbacks for specific hash:field combinations and automatically triggers these callbacks when the values change. Uses polling under the hood allowing you to set polling rate based on your needs.
Before using this library, make sure you have:
redis://127.0.0.1/
)Add this to your Cargo.toml
:
[dependencies]
redis_events = "0.1.0"
Run cargo run --example example
to see an example of the library in action. Make sure you have a Redis server running on redis://127.0.0.1/
or set the REDIS_URL
environment variable to your Redis server URL. Also add the hash and key you want to watch to the redis server before running the example.
use redis_events::RedisEvents;
fn sample_callback(hash: &str, field: &str, value: String) {
println!("Got a new value for {}:{} = {}", hash, field, value);
}
fn main() {
let events = RedisEvents::new(None);
events.register("user", "name", |hash, field, value| {
sample_callback(hash, field, value);
});
events.start();
std::thread::sleep(std::time::Duration::from_secs(1));
}