Skip to content

Commit 576d33c

Browse files
authored
REPLICAOF command implementation (#1622)
1 parent 726eede commit 576d33c

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

redis/commands.py

+10
Original file line numberDiff line numberDiff line change
@@ -2845,6 +2845,16 @@ def pubsub_numsub(self, *args):
28452845
def cluster(self, cluster_arg, *args):
28462846
return self.execute_command('CLUSTER %s' % cluster_arg.upper(), *args)
28472847

2848+
def replicaof(self, *args):
2849+
"""
2850+
Update the replication settings of a redis replica, on the fly.
2851+
Examples of valid arguments include:
2852+
NO ONE (set no replication)
2853+
host port (set to the host and port of a redis server)
2854+
see: https://redis.io/commands/replicaof
2855+
"""
2856+
return self.execute_command('REPLICAOF', *args)
2857+
28482858
def eval(self, script, numkeys, *keys_and_args):
28492859
"""
28502860
Execute the Lua ``script``, specifying the ``numkeys`` the script

redis/features.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
try:
2+
import hiredis # noqa
3+
HIREDIS_AVAILABLE = True
4+
except ImportError:
5+
HIREDIS_AVAILABLE = False

tests/test_commands.py

+8
Original file line numberDiff line numberDiff line change
@@ -3613,6 +3613,14 @@ def test_restore(self, r):
36133613
assert r.restore(key, 0, dumpdata, frequency=5)
36143614
assert r.get(key) == b'blee!'
36153615

3616+
@skip_if_server_version_lt('5.0.0')
3617+
def test_replicaof(self, r):
3618+
3619+
with pytest.raises(redis.ResponseError):
3620+
assert r.replicaof("NO ONE")
3621+
3622+
assert r.replicaof("NO", "ONE")
3623+
36163624

36173625
class TestBinarySave:
36183626

0 commit comments

Comments
 (0)