summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChayim <chayim@users.noreply.github.com>2021-10-18 12:08:54 +0300
committerGitHub <noreply@github.com>2021-10-18 12:08:54 +0300
commit576d33c148de867fd48077a55d51135d14e45ec0 (patch)
tree022318ebcc92b8e20988758194b02c1bad574396
parent726eedeae75e51c18bdb2ba697ff390a1efb2b78 (diff)
downloadredis-py-576d33c148de867fd48077a55d51135d14e45ec0.tar.gz
REPLICAOF command implementation (#1622)
-rw-r--r--redis/commands.py10
-rw-r--r--redis/features.py5
-rw-r--r--tests/test_commands.py8
3 files changed, 23 insertions, 0 deletions
diff --git a/redis/commands.py b/redis/commands.py
index 69aae20..c2d9ff7 100644
--- a/redis/commands.py
+++ b/redis/commands.py
@@ -2845,6 +2845,16 @@ class Commands:
def cluster(self, cluster_arg, *args):
return self.execute_command('CLUSTER %s' % cluster_arg.upper(), *args)
+ def replicaof(self, *args):
+ """
+ Update the replication settings of a redis replica, on the fly.
+ Examples of valid arguments include:
+ NO ONE (set no replication)
+ host port (set to the host and port of a redis server)
+ see: https://redis.io/commands/replicaof
+ """
+ return self.execute_command('REPLICAOF', *args)
+
def eval(self, script, numkeys, *keys_and_args):
"""
Execute the Lua ``script``, specifying the ``numkeys`` the script
diff --git a/redis/features.py b/redis/features.py
new file mode 100644
index 0000000..a96bac7
--- /dev/null
+++ b/redis/features.py
@@ -0,0 +1,5 @@
+try:
+ import hiredis # noqa
+ HIREDIS_AVAILABLE = True
+except ImportError:
+ HIREDIS_AVAILABLE = False
diff --git a/tests/test_commands.py b/tests/test_commands.py
index 802d8e4..2136d37 100644
--- a/tests/test_commands.py
+++ b/tests/test_commands.py
@@ -3613,6 +3613,14 @@ class TestRedisCommands:
assert r.restore(key, 0, dumpdata, frequency=5)
assert r.get(key) == b'blee!'
+ @skip_if_server_version_lt('5.0.0')
+ def test_replicaof(self, r):
+
+ with pytest.raises(redis.ResponseError):
+ assert r.replicaof("NO ONE")
+
+ assert r.replicaof("NO", "ONE")
+
class TestBinarySave: