(
relpath: str,
env: dict[str, str],
)
| 342 | |
| 343 | |
| 344 | def prepare_redis_for_example( |
| 345 | relpath: str, |
| 346 | env: dict[str, str], |
| 347 | ) -> tuple[TemporaryRedisServer | None, list[str]]: |
| 348 | if relpath != REDIS_SESSION_EXAMPLE: |
| 349 | return None, [] |
| 350 | |
| 351 | configured_url = env.get("REDIS_URL") |
| 352 | redis_url = configured_url or DEFAULT_REDIS_URL |
| 353 | if redis_url_is_local(redis_url) and redis_ping_url(redis_url): |
| 354 | env["REDIS_URL"] = redis_url |
| 355 | return None, [f"Using existing Redis server at {redis_url}."] |
| 356 | |
| 357 | if configured_url: |
| 358 | env["REDIS_URL"] = redis_url |
| 359 | return None, [f"REDIS_URL is set but not reachable before example start: {redis_url}."] |
| 360 | |
| 361 | server = start_temporary_redis_server() |
| 362 | if server is None: |
| 363 | env["REDIS_URL"] = redis_url |
| 364 | return None, [ |
| 365 | "redis-server was not found or did not start; running the example without managed Redis." |
| 366 | ] |
| 367 | |
| 368 | env["REDIS_URL"] = server.url |
| 369 | return server, [f"Started temporary Redis server at {server.url}."] |
| 370 | |
| 371 | |
| 372 | def parse_args() -> argparse.Namespace: |
no test coverage detected