Skip to content

Commit 8101da0

Browse files
committed
SINTER bugfix, does nothing when intersecting with empty set, while it should return an empty set instead, fixes #39.
1 parent 0711ea6 commit 8101da0

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

lib/backend.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1361,8 +1361,8 @@ exports.Backend.prototype = {
13611361
if (K instanceof ERROR) return K;
13621362

13631363
var j, m = out.length;
1364-
if (K) for (j = 0; j < m; j++)
1365-
if ((diff && K.value[out[j]]) || (!diff && !K.value[out[j]])) {
1364+
for (j = 0; j < m; j++)
1365+
if ((diff && (K && K.value[out[j]])) || (!diff && !(K && K.value[out[j]]))) {
13661366
out.splice(j, 1);
13671367
j--;
13681368
m--;

test.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ process.stdout.write('testing fakeredis ...\n\n');
110110
redis.SUNIONSTORE("output", [ "nonex1", "myset", "set2", "set3", "nonex2" ], test("SUNIONSTORE", null, 11));
111111
redis.SISMEMBER("output", "xxx", test("SISMEMBER union 3 sets", null, 1));
112112
redis.SINTER("myset", "output", test("SINTER", null, [ "ala", "bala", "niza" ]));
113+
redis.SINTER("myset", "outputs", test("SINTER nonex empty 1", null, []));
114+
redis.SINTER("outputs", "myset", test("SINTER nonex empty 2", null, []));
113115
redis.SADD("set3", "ala", 3, 4, "kukukuku");
114116
redis.SDIFFSTORE("output", "output", "set3", test("SDIFFSTORE", null, 5));
115117
redis.SMEMBERS("output", test("SMEMBERS", null, [ "1", "2", "5", "bala", "niza" ]));
@@ -1004,7 +1006,7 @@ function countTests() {
10041006
}
10051007

10061008
var NUM_TESTS = countTests();
1007-
if (NUM_TESTS !== 284)
1009+
if (NUM_TESTS !== 286)
10081010
throw new Error("Test count is off: " + NUM_TESTS);
10091011

10101012
process.on('exit', function () {

0 commit comments

Comments
 (0)