From f81ab32f6f6bedd9d42924b7472dbde8f8d260b6 Mon Sep 17 00:00:00 2001 From: Aprabhat19 Date: Fri, 3 Jan 2025 14:15:06 +0530 Subject: [PATCH] add a test case to test the script --- crates/redis_interface/src/commands.rs | 36 ++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/crates/redis_interface/src/commands.rs b/crates/redis_interface/src/commands.rs index 65103522aa51..9fa1f6b1e817 100644 --- a/crates/redis_interface/src/commands.rs +++ b/crates/redis_interface/src/commands.rs @@ -991,6 +991,42 @@ mod tests { .await .expect("Spawn block failure"); + assert!(is_success); + } + #[tokio::test] + async fn test_getting_keys_using_scripts() { + let is_success = tokio::task::spawn_blocking(move || { + futures::executor::block_on(async { + // Arrange + let pool = RedisConnectionPool::new(&RedisSettings::default()) + .await + .expect("failed to create redis connection pool"); + let lua_script = r#" + local results = {} + for i = 1, #KEYS do + results[i] = redis.call("GET", KEYS[i]) + end + return results + "#; + let mut keys_and_values = HashMap::new(); + for i in 0..10 { + keys_and_values.insert(format!("key{}", i), i); + } + + let key = keys_and_values.keys().cloned().collect::>(); + + // Act + let result = pool + .incr_keys_using_script::<_, String>(lua_script, key, 0) + .await; + + // Assert Setup + result.is_ok() + }) + }) + .await + .expect("Spawn block failure"); + assert!(is_success); } }