summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgmbnomis <gmbnomis@users.noreply.github.com>2023-01-29 14:46:42 +0100
committerGitHub <noreply@github.com>2023-01-29 15:46:42 +0200
commit9e6a9b52e5aab021d239ca56e27f06bca871cbf0 (patch)
tree6f950974fce09e3f4aa6d823af335ac2d43c542e
parent42604b68c906a156fd64a001a83e0e84a0fa63fa (diff)
downloadredis-py-9e6a9b52e5aab021d239ca56e27f06bca871cbf0.tar.gz
Fix unlink in cluster pipeline (#2562)
Implement unlink() like delete() to make it work when used in a cluster pipeline.
-rw-r--r--CHANGES1
-rw-r--r--redis/cluster.py11
-rw-r--r--tests/test_cluster.py19
3 files changed, 31 insertions, 0 deletions
diff --git a/CHANGES b/CHANGES
index d89079b..9d82341 100644
--- a/CHANGES
+++ b/CHANGES
@@ -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)
diff --git a/redis/cluster.py b/redis/cluster.py
index 5f730a8..d6dc02d 100644
--- a/redis/cluster.py
+++ b/redis/cluster.py
@@ -2136,6 +2136,17 @@ class ClusterPipeline(RedisCluster):
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]:
"""
diff --git a/tests/test_cluster.py b/tests/test_cluster.py
index da6a8e4..1bf57a3 100644
--- a/tests/test_cluster.py
+++ b/tests/test_cluster.py
@@ -2703,6 +2703,25 @@ class TestClusterPipeline:
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