Skip to content

Commit 9e6a9b5

Browse files
authored
Fix unlink in cluster pipeline (#2562)
Implement unlink() like delete() to make it work when used in a cluster pipeline.
1 parent 42604b6 commit 9e6a9b5

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

CHANGES

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
* Support `.unlink()` in ClusterPipeline
12
* Simplify synchronous SocketBuffer state management
23
* Fix string cleanse in Redis Graph
34
* Make PythonParser resumable in case of error (#2510)

redis/cluster.py

+11
Original file line numberDiff line numberDiff line change
@@ -2136,6 +2136,17 @@ def delete(self, *names):
21362136

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

2139+
def unlink(self, *names):
2140+
"""
2141+
"Unlink a key specified by ``names``"
2142+
"""
2143+
if len(names) != 1:
2144+
raise RedisClusterException(
2145+
"unlinking multiple keys is not implemented in pipeline command"
2146+
)
2147+
2148+
return self.execute_command("UNLINK", names[0])
2149+
21392150

21402151
def block_pipeline_command(name: str) -> Callable[..., Any]:
21412152
"""

tests/test_cluster.py

+19
Original file line numberDiff line numberDiff line change
@@ -2703,6 +2703,25 @@ def test_multi_delete_unsupported(self, r):
27032703
with pytest.raises(RedisClusterException):
27042704
pipe.delete("a", "b")
27052705

2706+
def test_unlink_single(self, r):
2707+
"""
2708+
Test a single unlink operation
2709+
"""
2710+
r["a"] = 1
2711+
with r.pipeline(transaction=False) as pipe:
2712+
pipe.unlink("a")
2713+
assert pipe.execute() == [1]
2714+
2715+
def test_multi_unlink_unsupported(self, r):
2716+
"""
2717+
Test that multi unlink operation is unsupported
2718+
"""
2719+
with r.pipeline(transaction=False) as pipe:
2720+
r["a"] = 1
2721+
r["b"] = 2
2722+
with pytest.raises(RedisClusterException):
2723+
pipe.unlink("a", "b")
2724+
27062725
def test_brpoplpush_disabled(self, r):
27072726
"""
27082727
Test that brpoplpush is disabled for ClusterPipeline

0 commit comments

Comments
 (0)