Redis Persistence #JU6

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.? },
    );

Hey @leBolideur!

This relates to expiry - the key is being fetched twice, once before expiry and once after.

In the first set of logs you posted, before the failure it says:

Fetching key “grape” at 06:58:54.376 (should be expired)

That’s why the expected value is a null bulk string. There was a previous test in that same log that said:

Fetching key “grape” at 06:58:54.229 (should not be expired)

That GET would’ve expected a value to be returned back.

Also note that the failure here is from stage 7 (expiry), a stage you previously passed - it looks like recent code changes might’ve broken functionality in previous stages?

Going to close this out for now, please let us know if you still need help!

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.

Note: I’ve updated the title of this post to include the stage ID (#JU6). You can learn about the stages rename here: Upcoming change: Stages overhaul.