From 6bd78b51a45922293f93edcc2a1ca829054b148f Mon Sep 17 00:00:00 2001 From: Madelyn Olson <34459052+madolson@users.noreply.github.com> Date: Tue, 1 Dec 2020 11:46:45 -0800 Subject: [PATCH] Getset fix (#8118) * Fixed SET GET executing on wrong type Co-authored-by: Madelyn Olson --- src/t_string.c | 2 +- tests/unit/type/string.tcl | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/t_string.c b/src/t_string.c index e8b37663d..3ecc473bd 100644 --- a/src/t_string.c +++ b/src/t_string.c @@ -90,7 +90,7 @@ void setGenericCommand(client *c, int flags, robj *key, robj *val, robj *expire, } if (flags & OBJ_SET_GET) { - getGenericCommand(c); + if (getGenericCommand(c) == C_ERR) return; } genericSetKey(c,c->db,key,val,flags & OBJ_SET_KEEPTTL,1); diff --git a/tests/unit/type/string.tcl b/tests/unit/type/string.tcl index 5058acec4..16e961623 100644 --- a/tests/unit/type/string.tcl +++ b/tests/unit/type/string.tcl @@ -415,6 +415,14 @@ start_server {tags {"string"}} { list $err1 $err2 } {*syntax err* *syntax err*} + test {Extended SET GET with incorrect type should result in wrong type error} { + r del foo + r rpush foo waffle + catch {r set foo bar GET} err1 + assert_equal "waffle" [r rpop foo] + set err1 + } {*WRONGTYPE*} + test {Extended SET EX option} { r del foo r set foo bar ex 10