diff --git a/redis/commands/core.py b/redis/commands/core.py index 5df93455c4..06773e3f35 100644 --- a/redis/commands/core.py +++ b/redis/commands/core.py @@ -1917,6 +1917,25 @@ def brpoplpush(self, src, dst, timeout=0): timeout = 0 return self.execute_command("BRPOPLPUSH", src, dst, timeout) + def lmpop( + self, + num_keys: int, + *args: List[str], + direction: str = None, + count: Optional[int] = 1, + ) -> List: + """ + Pop ``count`` values (default 1) first non-empty list key from the list + of args provided key names. + + For more information check https://redis.io/commands/lmpop + """ + args = [num_keys] + list(args) + [direction] + if count != 1: + args.extend(["COUNT", count]) + + return self.execute_command("LMPOP", *args) + def lindex(self, name, index): """ Return the item from list ``name`` at position ``index`` diff --git a/tests/test_commands.py b/tests/test_commands.py index a7135c03a8..ed69c40693 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -1480,6 +1480,17 @@ def test_brpoplpush_empty_string(self, r): r.rpush("a", "") assert r.brpoplpush("a", "b") == b"" + @pytest.mark.onlynoncluster + # @skip_if_server_version_lt("7.0.0") turn on after redis 7 release + def test_lmpop(self, unstable_r): + unstable_r.rpush("foo", "1", "2", "3", "4", "5") + result = [b"foo", [b"1", b"2"]] + assert unstable_r.lmpop("2", "bar", "foo", direction="LEFT", count=2) == result + with pytest.raises(redis.ResponseError): + unstable_r.lmpop("2", "bar", "foo", direction="up", count=2) + unstable_r.rpush("bar", "a", "b", "c", "d") + assert unstable_r.lmpop("2", "bar", "foo", direction="LEFT") == [b"bar", [b"a"]] + def test_lindex(self, r): r.rpush("a", "1", "2", "3") assert r.lindex("a", "0") == b"1"