(self, host=None, port=None, db=None, password=None,
max_connections=None, url=None,
connection_pool=None, **kwargs)
| 196 | _MAX_STR_VALUE_SIZE = 536870912 |
| 197 | |
| 198 | def __init__(self, host=None, port=None, db=None, password=None, |
| 199 | max_connections=None, url=None, |
| 200 | connection_pool=None, **kwargs): |
| 201 | super().__init__(expires_type=int, **kwargs) |
| 202 | _get = self.app.conf.get |
| 203 | if self.redis is None: |
| 204 | raise ImproperlyConfigured(E_REDIS_MISSING.strip()) |
| 205 | |
| 206 | if host and '://' in host: |
| 207 | url, host = host, None |
| 208 | |
| 209 | self.max_connections = ( |
| 210 | max_connections or |
| 211 | _get('redis_max_connections') or |
| 212 | self.max_connections) |
| 213 | self._ConnectionPool = connection_pool |
| 214 | |
| 215 | socket_timeout = _get('redis_socket_timeout') |
| 216 | socket_connect_timeout = _get('redis_socket_connect_timeout') |
| 217 | retry_on_timeout = _get('redis_retry_on_timeout') |
| 218 | socket_keepalive = _get('redis_socket_keepalive') |
| 219 | health_check_interval = _get('redis_backend_health_check_interval') |
| 220 | credential_provider = _get('redis_backend_credential_provider') |
| 221 | |
| 222 | self.connparams = { |
| 223 | 'host': _get('redis_host') or 'localhost', |
| 224 | 'port': _get('redis_port') or 6379, |
| 225 | 'db': _get('redis_db') or 0, |
| 226 | 'password': _get('redis_password'), |
| 227 | 'max_connections': self.max_connections, |
| 228 | 'socket_timeout': socket_timeout and float(socket_timeout), |
| 229 | 'retry_on_timeout': retry_on_timeout or False, |
| 230 | 'socket_connect_timeout': |
| 231 | socket_connect_timeout and float(socket_connect_timeout), |
| 232 | 'client_name': _get('redis_client_name'), |
| 233 | } |
| 234 | |
| 235 | username = _get('redis_username') |
| 236 | if username: |
| 237 | # We're extra careful to avoid including this configuration value |
| 238 | # if it wasn't specified since older versions of py-redis |
| 239 | # don't support specifying a username. |
| 240 | # Only Redis>6.0 supports username/password authentication. |
| 241 | |
| 242 | # TODO: Include this in connparams' definition once we drop |
| 243 | # support for py-redis<3.4.0. |
| 244 | self.connparams['username'] = username |
| 245 | |
| 246 | if credential_provider: |
| 247 | # if credential provider passed as string or query param |
| 248 | if isinstance(credential_provider, str): |
| 249 | credential_provider_cls = symbol_by_name(credential_provider) |
| 250 | credential_provider = credential_provider_cls() |
| 251 | |
| 252 | if not isinstance(credential_provider, CredentialProvider): |
| 253 | raise ValueError( |
| 254 | "Credential provider is not an instance of a redis.CredentialProvider or a subclass" |
| 255 | ) |
no test coverage detected