diff options
author | Theo Despoudis <thdespou@hotmail.com> | 2019-01-07 14:21:55 +0000 |
---|---|---|
committer | Andy McCurdy <andy@andymccurdy.com> | 2019-07-09 16:26:27 -0700 |
commit | 9ed2132af28652e964b6a4a20d387580d1081003 (patch) | |
tree | f823f628584feae679eb480fdc7d8ad7636bfbce | |
parent | 0be4d2920684345eb52115c7142c39d65356e7d4 (diff) | |
download | redis-py-9ed2132af28652e964b6a4a20d387580d1081003.tar.gz |
Add READONLY and READWRITE commands
-rw-r--r-- | CHANGES | 1 | ||||
-rwxr-xr-x | redis/client.py | 12 | ||||
-rw-r--r-- | tests/test_commands.py | 13 |
3 files changed, 24 insertions, 2 deletions
@@ -16,6 +16,7 @@ AuthenticationError is now a subclass of ConnectionError, which will cause the connection to be disconnected and cleaned up appropriately. #923 + * Add READONLY and READWRITE commands. Thanks @theodesp. #1114 * 3.2.1 * Fix SentinelConnectionPool to work in multiprocess/forked environments. * 3.2.0 diff --git a/redis/client.py b/redis/client.py index b87fcf6..aa1ca7e 100755 --- a/redis/client.py +++ b/redis/client.py @@ -499,8 +499,8 @@ class Redis(object): string_keys_to_dict('SORT', sort_return_tuples), string_keys_to_dict('ZSCORE ZINCRBY GEODIST', float_or_none), string_keys_to_dict( - 'FLUSHALL FLUSHDB LSET LTRIM MSET PFMERGE RENAME ' - 'SAVE SELECT SHUTDOWN SLAVEOF SWAPDB WATCH UNWATCH', + 'FLUSHALL FLUSHDB LSET LTRIM MSET PFMERGE READONLY READWRITE ' + 'RENAME SAVE SELECT SHUTDOWN SLAVEOF SWAPDB WATCH UNWATCH ', bool_ok ), string_keys_to_dict('BLPOP BRPOP', lambda r: r and tuple(r) or None), @@ -928,6 +928,14 @@ class Redis(object): raise DataError("CLIENT PAUSE timeout must be an integer") return self.execute_command('CLIENT PAUSE', str(timeout)) + def readwrite(self): + "Disables read queries for a connection to a Redis Cluster slave node" + return self.execute_command('READWRITE') + + def readonly(self): + "Enables read queries for a connection to a Redis Cluster replica node" + return self.execute_command('READONLY') + def config_get(self, pattern="*"): "Return a dictionary of configuration based on the ``pattern``" return self.execute_command('CONFIG GET', pattern) diff --git a/tests/test_commands.py b/tests/test_commands.py index 0815427..64cabdf 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -1643,6 +1643,19 @@ class TestRedisCommands(object): assert isinstance(mock_cluster_resp_slaves.cluster( 'slaves', 'nodeid'), dict) + @skip_if_server_version_lt('3.0.0') + def test_readwrite(self, r): + assert r.readwrite() + + @skip_if_server_version_lt('3.0.0') + def test_readonly_invalid_cluster_state(self, r): + with pytest.raises(exceptions.RedisError): + r.readonly() + + @skip_if_server_version_lt('3.0.0') + def test_readonly(self, mock_cluster_resp_ok): + assert mock_cluster_resp_ok.readonly() is True + # GEO COMMANDS @skip_if_server_version_lt('3.2.0') def test_geoadd(self, r): |