Skip to content

Commit

Permalink
Fix crash when using global_keyprefix with a sentinel connection (#1838)
Browse files Browse the repository at this point in the history
* Fix partial closure error when instantiating redis pool for a global_keyprefix sentinel connection

* add tests for redis sentinel connection with global_keyprefix setting

* StrictRedis is deprecated, use Redis class

* add some resource cleanup

* add some resource cleanup
  • Loading branch information
adam-homeboost committed Jan 9, 2024
1 parent 2783b12 commit 159e9df
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion kombu/transport/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1429,7 +1429,7 @@ def _sentinel_managed_pool(self, asynchronous=False):

return sentinel_inst.master_for(
master_name,
self.Client,
redis.Redis,
).connection_pool

def _get_pool(self, asynchronous=False):
Expand Down
38 changes: 38 additions & 0 deletions t/unit/transport/test_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1734,6 +1734,44 @@ def test_sentinel_with_ssl(self):
assert (params['connection_class'] is
SentinelManagedSSLConnection)

def test_can_create_connection_with_global_keyprefix(self):
from redis.exceptions import ConnectionError

try:
connection = Connection(
'sentinel://localhost:65534/',
transport_options={
'global_keyprefix': 'some_prefix',
'master_name': 'not_important',
},
)
with pytest.raises(ConnectionError):
connection.channel()
finally:
connection.close()

def test_can_create_correct_mixin_with_global_keyprefix(self):
from kombu.transport.redis import GlobalKeyPrefixMixin

with patch('redis.sentinel.Sentinel'):
connection = Connection(
'sentinel://localhost:65534/',
transport_options={
'global_keyprefix': 'some_prefix',
'master_name': 'not_important',
},
)

assert isinstance(
connection.channel().client,
GlobalKeyPrefixMixin
)
assert (
connection.channel().client.global_keyprefix
== 'some_prefix'
)
connection.close()


class test_GlobalKeyPrefixMixin:

Expand Down

0 comments on commit 159e9df

Please sign in to comment.