Skip to content

Commit

Permalink
Final version of supprot keepalive_options for redis result client + …
Browse files Browse the repository at this point in the history
…support setup 0 max_connection in it as well
  • Loading branch information
awmackowiak committed Jun 14, 2023
1 parent 063bd57 commit 9b540d3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions celery/backends/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def __init__(self, host=None, port=None, db=None, password=None,
socket_connect_timeout = _get('redis_socket_connect_timeout')
retry_on_timeout = _get('redis_retry_on_timeout')
socket_keepalive = _get('redis_socket_keepalive')
socket_keepalive_options = self._transport_options.get('socket_keepalive_options', None)
socket_keepalive_options = self._transport_options.get('socket_keepalive_options', {})
health_check_interval = _get('redis_backend_health_check_interval')

self.connparams = {
Expand Down Expand Up @@ -458,7 +458,7 @@ def apply_chord(self, header_result_args, body, **kwargs):
def _chord_zset(self):
return self._transport_options.get('result_chord_ordered', True)

@cached_property
@property
def _transport_options(self):
return self.app.conf.get('result_backend_transport_options', {})

Expand Down
Binary file modified statefilename
Binary file not shown.
40 changes: 20 additions & 20 deletions t/unit/backends/test_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from contextlib import contextmanager
from datetime import timedelta
from pickle import dumps, loads
from socket import TCP_KEEPCNT, TCP_KEEPINTVL
from platform import system
from unittest.mock import ANY, Mock, call, patch

import pytest
Expand Down Expand Up @@ -455,25 +455,6 @@ def test_socket_url(self):
assert 'socket_keepalive_options' not in x.connparams
assert x.connparams['db'] == 3

def test_socket_keepalive_options(self):
pytest.importorskip('redis')

self.app.conf.redis_socket_keepalive = True
self.app.conf.result_backend_transport_options = {
'socket_keepalive_options': {
0x10: 300,
TCP_KEEPCNT: 9,
TCP_KEEPINTVL: 45
}
}

x = self.Backend(
'socket:///tmp/redis.sock?virtual_host=/3', app=self.app,
)

assert x.connparams['socket_keepalive'] is True
assert x.connparams['socket_keepalive_options'] == {4: 300, 6: 9, 5: 45}

def test_backend_ssl(self):
pytest.importorskip('redis')

Expand Down Expand Up @@ -1116,6 +1097,25 @@ def test_on_chord_part_return__other_error__ordered(self):
callback.id, exc=ANY,
)

@pytest.mark.skipif(system() != 'Linux', reason="Test supported only for Linux setup")
def test_socket_keepalive_options(self):
pytest.importorskip('redis')
from socket import TCP_KEEPCNT, TCP_KEEPINTVL, TCP_KEEPIDLE

self.app.conf.redis_socket_keepalive = True
self.app.conf.result_backend_transport_options = {
'socket_keepalive_options': {
TCP_KEEPIDLE: 300,
TCP_KEEPCNT: 9,
TCP_KEEPINTVL: 45
}
}

x = self.Backend('socket:///tmp/redis.sock?virtual_host=/3', app=self.app)

assert x.connparams['socket_keepalive'] is True
assert x.connparams['socket_keepalive_options'] == {4: 300, 6: 9, 5: 45}


class test_RedisBackend_chords_complex(basetest_RedisBackend):
@pytest.fixture(scope="function", autouse=True)
Expand Down

0 comments on commit 9b540d3

Please sign in to comment.