diff --git a/REDIS_COMMANDS.md b/REDIS_COMMANDS.md index 12f85cc0..fdec0a01 100644 --- a/REDIS_COMMANDS.md +++ b/REDIS_COMMANDS.md @@ -135,6 +135,7 @@ list of [unimplemented commands](#unimplemented-commands). * sinter * sinterstore * sismember + * smismember * smembers * smove * spop @@ -399,7 +400,6 @@ All of the redis commands are implemented in fakeredis with these exceptions: ### set * sintercard - * smismember ### stream * xack diff --git a/fakeredis/_server.py b/fakeredis/_server.py index ec029b54..510266a1 100644 --- a/fakeredis/_server.py +++ b/fakeredis/_server.py @@ -1973,6 +1973,10 @@ def sinterstore(self, dst, *keys): def sismember(self, key, member): return int(member in key.value) + @command((Key(set), bytes), (bytes,)) + def smismember(self, key, *members): + return [self.sismember(key, member) for member in members] + @command((Key(set),)) def smembers(self, key): return list(key.value) diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 00000000..f0a84671 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,8 @@ +[pytest] +markers = + slow: marks tests as slow (deselect with '-m "not slow"') + fake: run tests only with fake redis + real: run tests with a locally running real Redis server + redis4_and_above: run tests for redis-py 4.1.2 and above + redis3_and_above: run tests for redis-py 3.x and above + redis_below_v3: run tests for redis-py 2.x and below diff --git a/test/test_fakeredis.py b/test/test_fakeredis.py index 795981a7..8db735d9 100644 --- a/test/test_fakeredis.py +++ b/test/test_fakeredis.py @@ -2006,6 +2006,28 @@ def test_sismember_wrong_type(r): with pytest.raises(redis.ResponseError): r.sismember('foo', 'member') +@redis4_and_above +def test_smismember(r): + assert r.smismember('foo', ['member1', 'member2', 'member3']) == [0, 0, 0] + r.sadd('foo', 'member1', 'member2', 'member3') + assert r.smismember('foo', ['member1', 'member2', 'member3']) == [1, 1, 1] + assert r.smismember('foo', ['member1', 'member2', 'member3', 'member4']) == [1, 1, 1, 0] + assert r.smismember('foo', ['member4', 'member2', 'member3']) == [0, 1, 1] + # should also work if provided values as arguments + assert r.smismember('foo', 'member4', 'member2', 'member3') == [0, 1, 1] + +@redis4_and_above +def test_smismember_wrong_type(r): + # verify that command fails when the key itself is not a SET + zadd(r, 'foo', {'member': 1}) + with pytest.raises(redis.ResponseError): + r.smismember('foo', 'member') + + # verify that command fails if the input parameter is of wrong type + r.sadd('foo2', 'member1', 'member2', 'member3') + with pytest.raises(redis.DataError, match='Invalid input of type'): + r.smismember('foo2', [["member1", "member2"]]) + def test_smembers(r): assert r.smembers('foo') == set()