diff --git a/redis/commands.py b/redis/commands.py index 69aae207f0..c2d9ff7bb1 100644 --- a/redis/commands.py +++ b/redis/commands.py @@ -2845,6 +2845,16 @@ def pubsub_numsub(self, *args): 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 0000000000..a96bac7c77 --- /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 802d8e448c..2136d37caf 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -3613,6 +3613,14 @@ def test_restore(self, r): 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: