I’m stuck on Persistence stage 3/6
I’ve tried to return the value and the tester expects a null string
Here are my logs:
[stage-7] Running tests for Stage #7: Expiry
remote: [stage-7] $ ./spawn_redis_server.sh
remote: [stage-7] $ redis-cli SET grape apple px 100
remote: [stage-7] Sent bytes: "*5\r\n$3\r\nSET\r\n$5\r\ngrape\r\n$5\r\napple\r\n$2\r\npx\r\n$3\r\n100\r\n"
remote: [stage-7] Received bytes: "+OK\r\n"
remote: [stage-7] Received RESP value: "OK"
remote: [stage-7] Received "OK"
remote: [stage-7] Received OK at 06:58:54.229
remote: [stage-7] Fetching key "grape" at 06:58:54.229 (should not be expired)
remote: [stage-7] $ redis-cli GET grape
remote: [stage-7] Sent bytes: "*2\r\n$3\r\nGET\r\n$5\r\ngrape\r\n"
remote: [stage-7] Received bytes: "$5\r\napple\r\n"
remote: [stage-7] Received RESP value: "apple"
remote: [stage-7] Received "apple"
remote: [stage-7] Sleeping for 101ms
remote: [stage-7] Fetching key "grape" at 06:58:54.376 (should be expired)
remote: [stage-7] $ redis-cli GET grape
remote: [stage-7] Sent bytes: "*2\r\n$3\r\nGET\r\n$5\r\ngrape\r\n"
remote: [stage-7] Received bytes: "$5\r\napple\r\n"
remote: [stage-7] Received RESP value: "apple"
remote: [stage-7] Expected null bulk string ("$-1\r\n"), got BULK_STRING
remote: [stage-7] Test failed
And if I return a null bulk string I get
[stage-7] Running tests for Stage #7: Expiry
remote: [stage-7] $ ./spawn_redis_server.sh
remote: [stage-7] $ redis-cli SET orange strawberry px 100
remote: [stage-7] Sent bytes: "*5\r\n$3\r\nSET\r\n$6\r\norange\r\n$10\r\nstrawberry\r\n$2\r\npx\r\n$3\r\n100\r\n"
remote: [stage-7] Received bytes: "+OK\r\n"
remote: [stage-7] Received RESP value: "OK"
remote: [stage-7] Received "OK"
remote: [stage-7] Received OK at 06:57:42.720
remote: [stage-7] Fetching key "orange" at 06:57:42.721 (should not be expired)
remote: [stage-7] $ redis-cli GET orange
remote: [stage-7] Sent bytes: "*2\r\n$3\r\nGET\r\n$6\r\norange\r\n"
remote: [stage-7] Received bytes: "$-1\r\n"
remote: [stage-7] Received RESP value: NIL
remote: [stage-7] Expected simple string or bulk string, got NIL
remote: [stage-7] Test failed
And here’s a snippet of my code:
const key = elems[1].bulk_string.value;
var value: ?[]const u8 = undefined;
if (rdb_map.* != null) {
value = rdb_map.*.?.get(key);
} else {
// _ = map;
// _ = try client.stream.write("$-1\r\n");
// return;
value = map.*.get(key).?.value;
}
if (value == null) {
_ = try client.stream.write("$-1\r\n");
return;
}
_ = try client.stream.writer().print(
"${d}\r\n{s}\r\n",
.{ value.?.len, value.? },
);