Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions redis/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions redis/features.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
try:
import hiredis # noqa
HIREDIS_AVAILABLE = True
except ImportError:
HIREDIS_AVAILABLE = False
8 changes: 8 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down