Browse Source

Fixed bug in SETEX command (#29)

SETEX was parsing the arguments incorrectly, copying the VALUE from the
second argument instead of the third.
César D. Rodas 3 years ago
parent
commit
f2964cbd43
1 changed files with 12 additions and 1 deletions
  1. 12 1
      src/cmd/string.rs

+ 12 - 1
src/cmd/string.rs

@@ -307,7 +307,7 @@ pub async fn setex(conn: &Connection, args: &[Bytes]) -> Result<Value, Error> {
 
     Ok(conn
         .db()
-        .set(&args[1], Value::Blob(args[2].to_owned()), Some(ttl)))
+        .set(&args[1], Value::Blob(args[3].to_owned()), Some(ttl)))
 }
 
 /// Set key to hold string value if key does not exist. In that case, it is
@@ -655,6 +655,17 @@ mod test {
     }
 
     #[tokio::test]
+    async fn setex() {
+        let c = create_connection();
+        assert_eq!(
+            Ok(Value::Ok),
+            run_command(&c, &["setex", "foo", "10", "bar"]).await
+        );
+        assert_eq!(Ok("bar".into()), run_command(&c, &["get", "foo"]).await);
+        assert_eq!(Ok(9.into()), run_command(&c, &["ttl", "foo"]).await);
+    }
+
+    #[tokio::test]
     async fn wrong_type() {
         let c = create_connection();
         let _ = run_command(&c, &["hset", "xxx", "key", "foo"]).await;