| Crates.io | rhai-redis |
| lib.rs | rhai-redis |
| version | 0.2.0 |
| created_at | 2025-09-19 02:44:26.822181+00 |
| updated_at | 2025-09-19 17:12:57.527743+00 |
| description | Redis scripting support for Rhai |
| homepage | |
| repository | https://github.com/joshrotenberg/rhai-redis |
| max_upload_size | |
| id | 1845703 |
| size | 118,129 |
Redis scripting support for Rhai - an embedded scripting language for Rust.
rhai-redis provides a clean, intuitive interface for using Redis commands within Rhai scripts. It wraps the redis-rs crate and exposes Redis operations through an object-oriented API.
redis.set(), redis.get() syntax[dependencies]
rhai-redis = "0.1"
use rhai_redis::{RedisEngine, RedisClient};
use redis::Client;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Connect to Redis
let client = Client::open("redis://localhost:6379")?;
let conn = client.get_connection()?;
// Create engine and set Redis client
let mut engine = RedisEngine::new();
engine.set_redis_client(RedisClient::new(conn));
// Run a script
engine.run(r#"
redis.set("key", "value");
let value = redis.get("key");
print("Got: " + value);
"#)?;
Ok(())
}
redis.set("key", "value")
redis.get("key")
redis.del("key")
redis.exists("key")
redis.incr("counter")
redis.decr("counter")
redis.lpush("list", "item")
redis.rpush("list", "item")
redis.lpop("list")
redis.rpop("list")
redis.lrange("list", 0, -1)
redis.hset("hash", "field", "value")
redis.hget("hash", "field")
redis.hgetall("hash")
redis.hdel("hash", "field")
redis.sadd("set", "member")
redis.srem("set", "member")
redis.smembers("set")
redis.sismember("set", "member")
redis.multi()
redis.set("key1", "value1")
redis.set("key2", "value2")
let results = redis.exec()
print("output")
sleep(1000) // milliseconds
let ts = timestamp()
let r = rand() // 0.0 to 1.0
let n = rand_int(1, 100)
engine.run_with_variables(
r#"
print("User ID: " + user_id);
redis.hset("user:" + user_id, "last_seen", timestamp().to_string());
"#,
vec![("user_id".to_string(), "12345".to_string())]
)?;
let mut engine = RedisEngine::new();
// Access the underlying Rhai engine for customization
engine.engine()
.set_max_operations(100_000)
.set_max_expr_depths(50, 50);
default: Includes synchronous support and utility functionsasync: Enable async/await support with Tokioutils: Include utility functions (rand, sleep, etc.)Scripts run in a sandboxed environment with:
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.