Skip to content

Commit ca05ee2

Browse files
committed
fix(get): return null bulk string for missing keys and enforce type
check - Return RESP null bulk string when key is absent - Return WRONGTYPE when stored value is not a BulkString - Avoid relying on toString() for BulkString values
1 parent 39cf2f9 commit ca05ee2

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/main/java/redis/command/core/GetCommand.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ public CommandResponse execute(Client client, RArray command) {
2929
String key = args.get(0).toString();
3030
RValue value = storage.get(key);
3131

32-
if (!(value instanceof BulkString)) {
32+
if (value == null) {
33+
return new CommandResponse(new BulkString(null));
34+
}
35+
36+
if (!(value instanceof BulkString bulk)) {
3337
return new CommandResponse(SimpleErrors.WRONG_TYPE_OPERATION);
3438
}
3539

36-
return new CommandResponse(
37-
new BulkString(value == null ? null : value.toString())
38-
);
40+
return new CommandResponse(new BulkString(bulk.getValue()));
3941
}
4042

4143
@Override

0 commit comments

Comments
 (0)