Skip to content

Commit

Permalink
addressing comments
Browse files Browse the repository at this point in the history
Signed-off-by: Sarthak Aggarwal <[email protected]>
  • Loading branch information
sarthakaggarwal97 committed Nov 20, 2024
1 parent f5ec47c commit 3dc3407
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
13 changes: 4 additions & 9 deletions src/t_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,26 +102,21 @@ void setGenericCommand(client *c,
if (getGenericCommand(c) == C_ERR) return;
}

const robj *value = lookupKeyWrite(c->db, key);
found = value != NULL;
robj *existing_value = lookupKeyWrite(c->db, key);
found = existing_value != NULL;

/* Handle the IFEQ conditional check */
if (flags & OBJ_SET_IFEQ && found) {

if (value->type != OBJ_STRING) {
if (!(flags & OBJ_SET_GET)) {
addReplyError(c, "value(s) must be present or string");
}
if (!(flags & OBJ_SET_GET) && checkType(c, existing_value, OBJ_STRING)) {
return;
}

if (compareStringObjects(value, comparison) != 0) {
if (compareStringObjects(existing_value, comparison) != 0) {
if (!(flags & OBJ_SET_GET)) {
addReply(c, abort_reply ? abort_reply : shared.null[c->resp]);
}
return;
}

} else if (flags & OBJ_SET_IFEQ && !found) {
if (!(flags & OBJ_SET_GET)) {
addReply(c, abort_reply ? abort_reply : shared.null[c->resp]);
Expand Down
10 changes: 9 additions & 1 deletion tests/unit/type/string.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -598,9 +598,10 @@ if {[string match {*jemalloc*} [s mem_allocator]]} {
r del foo

r sadd foo "some_set_value"
assert_error {ERR value(s) must be present or string} {r set foo "new_value" ifeq "some_set_value"}
assert_error {WRONGTYPE Operation against a key holding the wrong kind of value} {r set foo "new_value" ifeq "some_set_value"}
}


test "SET with IFEQ conditional - with get" {
r del foo

Expand All @@ -612,6 +613,13 @@ if {[string match {*jemalloc*} [s mem_allocator]]} {
assert_equal "new_value" [r get foo]
}

test "SET with IFEQ conditional - non string current value with get" {
r del foo

r sadd foo "some_set_value"

assert_error {WRONGTYPE Operation against a key holding the wrong kind of value} {r set foo "new_value" ifeq "initial_value" get}
}

test "SET with IFEQ conditional - with xx" {
r del foo
Expand Down

0 comments on commit 3dc3407

Please sign in to comment.