diff --git a/src/multi.c b/src/multi.c index 052b39751..a12a147fd 100644 --- a/src/multi.c +++ b/src/multi.c @@ -246,9 +246,12 @@ int execGetKeys(struct serverCommand *cmd, robj **argv, int argc, getKeysResult keys = getKeysPrepareResult(result, numkeys + 1); keys[numkeys].pos = key_index; keys[numkeys].flags = CMD_KEY_RO | CMD_KEY_ACCESS; - numkeys++; + /* Publish the count as we go. getKeysPrepareResult() copies only + * result->numkeys entries when it moves off the static buffer, so + * leaving it at 0 until the end discards the first MAX_KEYS_BUFFER + * entries and hands back uninitialised ones. */ + result->numkeys = ++numkeys; } - result->numkeys = numkeys; return numkeys; } diff --git a/tests/unit/multi.tcl b/tests/unit/multi.tcl index 4048501fa..54ee12104 100644 --- a/tests/unit/multi.tcl +++ b/tests/unit/multi.tcl @@ -48,6 +48,21 @@ start_server {tags {"multi"}} { list $committed $ifeq_failed $ifne_failed $nx_failed $xx_failed [r get destination{t}] } {OK {} {} {} {} committed} + test {EXEC conditions past the static key buffer report the real keys} { + # getKeysPrepareResult() grows out of keysbuf at MAX_KEYS_BUFFER (256), + # and copies result->numkeys entries when it does. + set conds {} + for {set i 0} {$i < 300} {incr i} { + lappend conds IFEQ key:$i val:$i + } + set keys [r command getkeys EXEC {*}$conds] + assert_equal 300 [llength $keys] + assert_equal key:0 [lindex $keys 0] + assert_equal key:255 [lindex $keys 255] + assert_equal key:299 [lindex $keys 299] + r ping + } {PONG} + test {EXEC IFNE matches a missing key} { r del condition{t} destination{t} r multi