diff options
author | Andy McCurdy <andy@andymccurdy.com> | 2019-07-22 17:14:28 -0700 |
---|---|---|
committer | Andy McCurdy <andy@andymccurdy.com> | 2019-07-23 14:48:30 -0700 |
commit | 0984b102264b2600a6534ad8fef6f4cab44b4ecc (patch) | |
tree | c1aad6c05ff0e021626ae94f76eb502a532af782 /tests/test_connection_pool.py | |
parent | 6e23760fefbdf27ec941a2c3ae1ec2657875ac31 (diff) | |
download | redis-py-0984b102264b2600a6534ad8fef6f4cab44b4ecc.tar.gz |
Ability to create a client that uses a single connection
This has multiple uses:
* Single connection clients will not be considered threadsafe. This means
certain settings could temporarily be adjusted. For example, a context
manager could temporarily modify the encoding behavior for a set
of commands.
* We can introduce more thorough health checks that only happen when a
connection is handed out from the connection pool.
* Workloads that issue many commands to Redis should be slightly faster.
Prior to this change, the client must retrieve a connection from the
pool for each command.
Diffstat (limited to 'tests/test_connection_pool.py')
-rw-r--r-- | tests/test_connection_pool.py | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/tests/test_connection_pool.py b/tests/test_connection_pool.py index 2aea1e4..0af615f 100644 --- a/tests/test_connection_pool.py +++ b/tests/test_connection_pool.py @@ -6,7 +6,7 @@ import re from threading import Thread from redis.connection import ssl_available, to_bool -from .conftest import skip_if_server_version_lt +from .conftest import skip_if_server_version_lt, _get_client class DummyConnection(object): @@ -448,9 +448,7 @@ class TestConnection(object): """ with pytest.raises(redis.BusyLoadingError): r.execute_command('DEBUG', 'ERROR', 'LOADING fake message') - pool = r.connection_pool - assert len(pool._available_connections) == 1 - assert not pool._available_connections[0]._sock + assert not r.connection._sock @skip_if_server_version_lt('2.8.8') def test_busy_loading_from_pipeline_immediate_command(self, r): @@ -521,3 +519,16 @@ class TestConnection(object): "AuthenticationError should be raised when sending the wrong password" with pytest.raises(redis.AuthenticationError): r.execute_command('DEBUG', 'ERROR', 'ERR invalid password') + + +class TestMultiConnectionClient(object): + @pytest.fixture() + def r(self, request): + return _get_client(redis.Redis, + request, + single_connection_client=False) + + def test_multi_connection_command(self, r): + assert not r.connection + assert r.set('a', '123') + assert r.get('a') == b'123' |