diff --git a/redis/commands.py b/redis/commands.py index 29877dbef9..8b70aee6ac 100644 --- a/redis/commands.py +++ b/redis/commands.py @@ -268,12 +268,15 @@ def bgrewriteaof(self): "Tell the Redis server to rewrite the AOF file from data in memory." return self.execute_command('BGREWRITEAOF') - def bgsave(self): + def bgsave(self, schedule=True): """ Tell the Redis server to save its data to disk. Unlike save(), this method is asynchronous and returns immediately. """ - return self.execute_command('BGSAVE') + pieces = [] + if schedule: + pieces.append("SCHEDULE") + return self.execute_command('BGSAVE', *pieces) def client_kill(self, address): "Disconnects the client at ``address`` (ip:port)" diff --git a/tests/test_commands.py b/tests/test_commands.py index 0c9ca1eb57..9c17199447 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -547,6 +547,11 @@ def test_time(self, r): assert isinstance(t[0], int) assert isinstance(t[1], int) + def test_bgsave(self, r): + assert r.bgsave() + time.sleep(0.3) + assert r.bgsave(True) + # BASIC KEY COMMANDS def test_append(self, r): assert r.append('a', 'a1') == 2