1
1
from typing import List , Dict
2
2
3
3
import redis
4
- from redis . sentinel import Sentinel
4
+ import valkey
5
5
6
+ from .connection_types import RedisSentinel , BrokerConnectionClass
6
7
from .rq_classes import JobExecution , DjangoQueue , DjangoWorker
7
- from .settings import get_config
8
- from .settings import logger
8
+ from .settings import SCHEDULER_CONFIG
9
+ from .settings import logger , Broker
9
10
10
11
_CONNECTION_PARAMS = {
11
12
"URL" ,
@@ -31,12 +32,12 @@ def _get_redis_connection(config, use_strict_redis=False):
31
32
"""
32
33
Returns a redis connection from a connection config
33
34
"""
34
- if get_config ( " FAKEREDIS" ) :
35
+ if SCHEDULER_CONFIG . BROKER == Broker . FAKEREDIS :
35
36
import fakeredis
36
37
37
38
redis_cls = fakeredis .FakeRedis if use_strict_redis else fakeredis .FakeStrictRedis
38
39
else :
39
- redis_cls = redis . StrictRedis if use_strict_redis else redis . Redis
40
+ redis_cls = BrokerConnectionClass [( SCHEDULER_CONFIG . BROKER , use_strict_redis )]
40
41
logger .debug (f"Getting connection for { config } " )
41
42
if "URL" in config :
42
43
if config .get ("SSL" ) or config .get ("URL" ).startswith ("rediss://" ):
@@ -62,7 +63,7 @@ def _get_redis_connection(config, use_strict_redis=False):
62
63
}
63
64
connection_kwargs .update (config .get ("CONNECTION_KWARGS" , {}))
64
65
sentinel_kwargs = config .get ("SENTINEL_KWARGS" , {})
65
- sentinel = Sentinel (config ["SENTINELS" ], sentinel_kwargs = sentinel_kwargs , ** connection_kwargs )
66
+ sentinel = RedisSentinel (config ["SENTINELS" ], sentinel_kwargs = sentinel_kwargs , ** connection_kwargs )
66
67
return sentinel .master_for (
67
68
service_name = config ["MASTER_NAME" ],
68
69
redis_class = redis_cls ,
@@ -86,7 +87,7 @@ def get_connection(queue_settings, use_strict_redis=False):
86
87
87
88
88
89
def get_queue (
89
- name = "default" , default_timeout = None , is_async = None , autocommit = None , connection = None , ** kwargs
90
+ name = "default" , default_timeout = None , is_async = None , autocommit = None , connection = None , ** kwargs
90
91
) -> DjangoQueue :
91
92
"""Returns an DjangoQueue using parameters defined in `SCHEDULER_QUEUES`"""
92
93
from .settings import QUEUES
@@ -115,7 +116,7 @@ def get_all_workers():
115
116
try :
116
117
curr_workers = set (DjangoWorker .all (connection = connection ))
117
118
workers .update (curr_workers )
118
- except redis .ConnectionError as e :
119
+ except ( redis .ConnectionError , valkey . ConnectionError ) as e :
119
120
logger .error (f"Could not connect for queue { queue_name } : { e } " )
120
121
return workers
121
122
0 commit comments