Repository: redis-rs/redis-rs (2025-07-13T11:19:16Z)

Issue:
No way to explicitly call `HMGET`
Hi, it seems that there's no way to explicitly call `HMGET`, instead we rely on using `hget` with multiple params. This makes it hard to write generic code, where if we request less than 2 fields inside the `hget`, we'll get a single value instead of key-value pairs, which we might be unable to parse.


Discussion:
feel free to add the function :)



Patch:
diff --git a/redis/src/commands/mod.rs b/redis/src/commands/mod.rs
index 988452171..9e60932eb 100644
--- a/redis/src/commands/mod.rs
+++ b/redis/src/commands/mod.rs
@@ -494,6 +494,12 @@ implement_commands! {
         cmd(if field.num_of_args() <= 1 { "HGET" } else { "HMGET" }).arg(key).arg(field)
     }
 
+    /// Gets multiple fields from a hash.
+    /// [Redis Docs](https://redis.io/commands/HMGET)
+    fn hmget<K: ToRedisArgs, F: ToRedisArgs>(key: K, fields: F) -> (Vec<String>) {
+        cmd("HMGET").arg(key).arg(fields)
+    }
+
     /// Get the value of one or more fields of a given hash key, and optionally set their expiration
     /// [Redis Docs](https://redis.io/commands/HGETEX)
     fn hget_ex<K: ToRedisArgs, F: ToRedisArgs>(key: K, fields: F, expire_at: Expiry) -> (Vec<String>) {


Test patch:
diff --git a/redis/tests/test_basic.rs b/redis/tests/test_basic.rs
index 674846c7b..129ace10a 100644
--- a/redis/tests/test_basic.rs
+++ b/redis/tests/test_basic.rs
@@ -2083,6 +2083,10 @@ mod basic {
             redis::Commands::hget(&mut con, "my_hash", &["f2", "f4"]),
             Ok((2, 8))
         );
+        assert_eq!(
+            redis::Commands::hmget(&mut con, "my_hash", &["f2", "f4"]),
+            Ok((2, 8))
+        );
         assert_eq!(con.hincr("my_hash", "f1", 1), Ok(2.0));
         assert_eq!(con.hincr("my_hash", "f2", 1.5), Ok(3.5));
         assert_eq!(con.hexists("my_hash", "f2"), Ok(true));