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_commands.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_commands.py')
-rw-r--r-- | tests/test_commands.py | 79 |
1 files changed, 49 insertions, 30 deletions
diff --git a/tests/test_commands.py b/tests/test_commands.py index a41e1a2..931fe9c 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -102,20 +102,20 @@ class TestRedisCommands(object): @skip_if_server_version_lt('2.6.9') def test_client_kill(self, r, r2): r.client_setname('redis-py-c1') - r2[0].client_setname('redis-py-c2') - r2[1].client_setname('redis-py-c3') - test_clients = [client for client in r.client_list() - if client.get('name') - in ['redis-py-c1', 'redis-py-c2', 'redis-py-c3']] - assert len(test_clients) == 3 + r2.client_setname('redis-py-c2') + clients = [client for client in r.client_list() + if client.get('name') in ['redis-py-c1', 'redis-py-c2']] + assert len(clients) == 2 - resp = r.client_kill(test_clients[1].get('addr')) - assert isinstance(resp, bool) and resp is True + clients_by_name = dict([(client.get('name'), client) + for client in clients]) - test_clients = [client for client in r.client_list() - if client.get('name') - in ['redis-py-c1', 'redis-py-c2', 'redis-py-c3']] - assert len(test_clients) == 2 + assert r.client_kill(clients_by_name['redis-py-c2'].get('addr')) is True + + clients = [client for client in r.client_list() + if client.get('name') in ['redis-py-c1', 'redis-py-c2']] + assert len(clients) == 1 + assert clients[0].get('name') == 'redis-py-c1' @skip_if_server_version_lt('2.8.12') def test_client_kill_filter_invalid_params(self, r): @@ -132,25 +132,44 @@ class TestRedisCommands(object): r.client_kill_filter(_type="caster") @skip_if_server_version_lt('2.8.12') - def test_client_kill_filter(self, r, r2): + def test_client_kill_filter_by_id(self, r, r2): + r.client_setname('redis-py-c1') + r2.client_setname('redis-py-c2') + clients = [client for client in r.client_list() + if client.get('name') in ['redis-py-c1', 'redis-py-c2']] + assert len(clients) == 2 + + clients_by_name = dict([(client.get('name'), client) + for client in clients]) + + client_2_id = clients_by_name['redis-py-c2'].get('id') + resp = r.client_kill_filter(_id=client_2_id) + assert resp == 1 + + clients = [client for client in r.client_list() + if client.get('name') in ['redis-py-c1', 'redis-py-c2']] + assert len(clients) == 1 + assert clients[0].get('name') == 'redis-py-c1' + + @skip_if_server_version_lt('2.8.12') + def test_client_kill_filter_by_addr(self, r, r2): r.client_setname('redis-py-c1') - r2[0].client_setname('redis-py-c2') - r2[1].client_setname('redis-py-c3') - test_clients = [client for client in r.client_list() - if client.get('name') - in ['redis-py-c1', 'redis-py-c2', 'redis-py-c3']] - assert len(test_clients) == 3 - - resp = r.client_kill_filter(_id=test_clients[1].get('id')) - assert isinstance(resp, int) and resp == 1 - - resp = r.client_kill_filter(addr=test_clients[2].get('addr')) - assert isinstance(resp, int) and resp == 1 - - test_clients = [client for client in r.client_list() - if client.get('name') - in ['redis-py-c1', 'redis-py-c2', 'redis-py-c3']] - assert len(test_clients) == 1 + r2.client_setname('redis-py-c2') + clients = [client for client in r.client_list() + if client.get('name') in ['redis-py-c1', 'redis-py-c2']] + assert len(clients) == 2 + + clients_by_name = dict([(client.get('name'), client) + for client in clients]) + + client_2_addr = clients_by_name['redis-py-c2'].get('addr') + resp = r.client_kill_filter(addr=client_2_addr) + assert resp == 1 + + clients = [client for client in r.client_list() + if client.get('name') in ['redis-py-c1', 'redis-py-c2']] + assert len(clients) == 1 + assert clients[0].get('name') == 'redis-py-c1' @skip_if_server_version_lt('2.6.9') def test_client_list_after_client_setname(self, r): |