Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for unlink in cluster pipeline #2562

Merged
merged 1 commit into from
Jan 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* Support `.unlink()` in ClusterPipeline
* Simplify synchronous SocketBuffer state management
* Fix string cleanse in Redis Graph
* Make PythonParser resumable in case of error (#2510)
Expand Down
11 changes: 11 additions & 0 deletions redis/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -2136,6 +2136,17 @@ def delete(self, *names):

return self.execute_command("DEL", names[0])

def unlink(self, *names):
"""
"Unlink a key specified by ``names``"
"""
if len(names) != 1:
raise RedisClusterException(
"unlinking multiple keys is not implemented in pipeline command"
)

return self.execute_command("UNLINK", names[0])


def block_pipeline_command(name: str) -> Callable[..., Any]:
"""
Expand Down
19 changes: 19 additions & 0 deletions tests/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -2703,6 +2703,25 @@ def test_multi_delete_unsupported(self, r):
with pytest.raises(RedisClusterException):
pipe.delete("a", "b")

def test_unlink_single(self, r):
"""
Test a single unlink operation
"""
r["a"] = 1
with r.pipeline(transaction=False) as pipe:
pipe.unlink("a")
assert pipe.execute() == [1]

def test_multi_unlink_unsupported(self, r):
"""
Test that multi unlink operation is unsupported
"""
with r.pipeline(transaction=False) as pipe:
r["a"] = 1
r["b"] = 2
with pytest.raises(RedisClusterException):
pipe.unlink("a", "b")

def test_brpoplpush_disabled(self, r):
"""
Test that brpoplpush is disabled for ClusterPipeline
Expand Down