MCPcopy Create free account
hub / github.com/openai/openai-agents-python / prepare_redis_for_example

Function prepare_redis_for_example

examples/run_examples.py:344–369  ·  view source on GitHub ↗
(
    relpath: str,
    env: dict[str, str],
)

Source from the content-addressed store, hash-verified

342
343
344def 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
372def parse_args() -> argparse.Namespace:

Callers 1

run_singleFunction · 0.85

Calls 4

redis_url_is_localFunction · 0.85
redis_ping_urlFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected