Skip to content

REPLICAOF command implementation #1622

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 18, 2021
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