diff --git a/fakeredis.py b/fakeredis.py index 5954232..138e23b 100644 --- a/fakeredis.py +++ b/fakeredis.py @@ -1362,7 +1362,7 @@ def sismember(self, name, value): def smembers(self, name): "Return all members of the set ``name``" - return self._get_set(name) + return self._get_set(name).copy() @_remove_empty def smove(self, src, dst, value): diff --git a/test_fakeredis.py b/test_fakeredis.py index 8b1ae48..71fc30b 100644 --- a/test_fakeredis.py +++ b/test_fakeredis.py @@ -1488,11 +1488,22 @@ def test_sismember_wrong_type(self): def test_smembers(self): self.assertEqual(self.redis.smembers('foo'), set()) + def test_smembers_copy(self): + self.redis.sadd('foo', 'member1') + set = self.redis.smembers('foo') + self.redis.sadd('foo', 'member2') + self.assertNotEqual(set, self.redis.smembers('foo')) + def test_smembers_wrong_type(self): self.redis.zadd('foo', 1, 'member') with self.assertRaises(redis.ResponseError): self.redis.smembers('foo') + def test_smembers_runtime_error(self): + self.redis.sadd('foo', 'member1', 'member2') + for member in self.redis.smembers('foo'): + self.redis.srem('foo', member) + def test_smove(self): self.redis.sadd('foo', 'member1') self.redis.sadd('foo', 'member2')