Skip to content

Commit

Permalink
Fix unlink in cluster pipeline (#2562)
Browse files Browse the repository at this point in the history
Implement unlink() like delete() to make it work when
used in a cluster pipeline.
  • Loading branch information
gmbnomis authored Jan 29, 2023
1 parent 42604b6 commit 9e6a9b5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
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

0 comments on commit 9e6a9b5

Please sign in to comment.