diff --git a/src/Response.cpp b/src/Response.cpp index 8b699b9..f8e68b5 100644 --- a/src/Response.cpp +++ b/src/Response.cpp @@ -114,6 +114,8 @@ void Response::adjustForLeader(Request* req) if (leader == req) { mHead.fset(nullptr, "*%d\r\n", req->followers()); } + } else if (mType == Reply::Error) { + break; } else { mType = Reply::Array; if (leader == req) { diff --git a/test/mget_wrong_type.py b/test/mget_wrong_type.py new file mode 100644 index 0000000..8518d70 --- /dev/null +++ b/test/mget_wrong_type.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python +# +# Verify MGET returns WRONGTYPE for non-string keys +# + +import argparse +import sys +import redis + + +def run_test(host, port): + c = redis.StrictRedis(host=host, port=port) + c.delete("mget_wrong_type") + c.lpush("mget_wrong_type", "v1") + + res = c.execute_command("MGET", "mget_wrong_type") + if not isinstance(res, (list, tuple)) or len(res) != 1 or res[0] is not None: + print("FAIL: MGET wrong type should return nil:", res) + return False + + return True + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(conflict_handler='resolve', description="MGET wrong type test") + parser.add_argument("-h", "--host", default="127.0.0.1") + parser.add_argument("-p", "--port", type=int, default=7617) + args = parser.parse_args() + + if run_test(args.host, args.port): + print("PASS: MGET wrong type") + sys.exit(0) + print("FAIL: MGET wrong type") + sys.exit(1) diff --git a/test/run.sh b/test/run.sh index 1b198c3..6fa80dc 100755 --- a/test/run.sh +++ b/test/run.sh @@ -65,6 +65,7 @@ PUBSUB_RESET_EXIT=0 NULL_RESPONSE_EXIT=0 PUBSUB_LONG_EXIT=0 TRANSACTION_FORBID_EXIT=0 +MGET_WRONG_TYPE_EXIT=0 uv run python3 test/basic.py || BASIC_EXIT=$? uv run python3 test/pubsub_minimal.py -p 7617 || PUBSUB_REDIS_EXIT=$? @@ -72,10 +73,11 @@ uv run python3 test/pubsub_minimal.py -p 6379 || PUBSUB_MINIMAL_EXIT=$? uv run python3 test/pubsub.py || PUBSUB_EXIT=$? uv run python3 test/pubsub_subscription_order.py -p 7617 || PUBSUB_ORDER_EXIT=$? uv run python3 test/pubsub_parser_reset.py -p 7617 || PUBSUB_RESET_EXIT=$? +uv run python3 test/mget_wrong_type.py -p 7617 || MGET_WRONG_TYPE_EXIT=$? uv run python3 test/transaction_forbid.py -p 7617 || TRANSACTION_FORBID_EXIT=$? uv run python3 test/pubsub_long_name.py -p 7617 || PUBSUB_LONG_EXIT=$? uv run python3 test/null_response_handling.py -p 7617 || NULL_RESPONSE_EXIT=$? uv run python3 test/pubsub_message_response.py -p 7617 || PUBSUB_MESSAGE_EXIT=$? -TEST_EXIT=$((BASIC_EXIT + PUBSUB_REDIS_EXIT + PUBSUB_MINIMAL_EXIT + PUBSUB_EXIT + PUBSUB_MESSAGE_EXIT + PUBSUB_ORDER_EXIT + PUBSUB_RESET_EXIT + NULL_RESPONSE_EXIT + PUBSUB_LONG_EXIT + TRANSACTION_FORBID_EXIT)) +TEST_EXIT=$((BASIC_EXIT + PUBSUB_REDIS_EXIT + PUBSUB_MINIMAL_EXIT + PUBSUB_EXIT + PUBSUB_MESSAGE_EXIT + PUBSUB_ORDER_EXIT + PUBSUB_RESET_EXIT + NULL_RESPONSE_EXIT + PUBSUB_LONG_EXIT + TRANSACTION_FORBID_EXIT + MGET_WRONG_TYPE_EXIT)) exit $TEST_EXIT