I’m stuck on stage 7 expiry.
I have implemented the expiry logic, as per the instructions in java, even though i am sending the null bulk string, it is failing. Can you guys please help me where i am missing.
Here are my logs:
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 10:29:33.576
remote: [stage-7] Fetching key "apple" at 10:29:33.576 (should not be expired)
remote: [stage-7] $ redis-cli GET apple
remote: [stage-7] Sent bytes: "*2\r\n$3\r\nGET\r\n$5\r\napple\r\n"
remote: [stage-7] Received bytes: "$6\r\nbanana\r\n"
remote: [stage-7] Received RESP value: "banana"
remote: [stage-7] Received "banana"
remote: [stage-7] Sleeping for 101ms
remote: [stage-7] Fetching key "apple" at 10:29:33.690 (should be expired)
remote: [stage-7] $ redis-cli GET apple
remote: [stage-7] Sent bytes: "*2\r\n$3\r\nGET\r\n$5\r\napple\r\n"
remote: [stage-7] Received bytes: "$5\r\n$-1\r\n\r\n"
remote: [stage-7] Received RESP value: "$-1\r\n"
remote: [stage-7] Expected null bulk string ("$-1\r\n"), got BULK_STRING
remote: [stage-7] Test failed
remote: [stage-7] Terminating program
remote: [stage-7] Program terminated successfully
And here’s a snippet of my code:
public class Get implements Command {
@Override
public void execute(BufferedReader inputStream, OutputStream outputStream) throws IOException {
int length = Integer.parseInt(inputStream.readLine().substring(1));
String key = inputStream.readLine();
String result = InMemoryCache.getValue(key);
result = (result == null) ? RedisParser.nullBulkStringResponse() : result;
outputStream.write(
RedisParser.stringFormatting(result).getBytes(StandardCharsets.UTF_8)
);
}
}