Skip to content

AsyncRedisSaver always error:redis.exceptions.ConnectionError: Error 22 while writing to socket. #109

@aceliuchanghong

Description

@aceliuchanghong

always error:redis.exceptions.ConnectionError: Error 22 while writing to socket.

no matter what default_ttl is, frastrated

from langgraph.checkpoint.redis.aio import AsyncRedisSaver

host = os.getenv("REDIS_HOST", "localhost")
port = int(os.getenv("REDIS_PORT", 6379))
password = os.getenv("REDIS_PASSWORD", None)
db_index = int(os.getenv("REDIS_DB", 0))
ttl_config = {
    "default_ttl": 60 * 60,
    "refresh_on_read": True,
}
params = "socket_timeout=3600&socket_connect_timeout=3600"
if password:
    conn_str = f"redis://{password}@{host}:{port}/{db_index}?{params}"
else:
    conn_str = f"redis://{host}:{port}/{db_index}?{params}"
_agent = None

async def get_agent():
    global _agent
    if _agent is None:
        async with AsyncRedisSaver.from_conn_string(
            conn_str, ttl=ttl_config
        ) as checkpointer:
            await checkpointer.setup()
            # 构建图
            workflow = StateGraph(MatchmakingState)

            # 节点
            workflow.add_node("initiate_match", initiate_match)
            workflow.add_node("get_human_response", get_human_response)
            workflow.add_node("process_human_input", process_human_input)
            workflow.add_node("router_node", router_node)
            workflow.add_node("invoke_subgraph", invoke_subgraph)
            workflow.add_node("end_match", end_match)

            # 边
            workflow.add_edge(START, "initiate_match")
            workflow.add_edge("initiate_match", "get_human_response")
            workflow.add_edge("get_human_response", "process_human_input")
            workflow.add_edge("process_human_input", "router_node")
            workflow.add_conditional_edges(
                "router_node",
                should_continue,
                {"continue": "invoke_subgraph", "end_match": "end_match"},
            )
            workflow.add_conditional_edges(
                "invoke_subgraph",
                should_continue,
                {"continue": "get_human_response", "end_match": "end_match"},
            )
            workflow.add_edge("end_match", END)

            # 编译并绑定 checkpointer
            _agent = workflow.compile(
                checkpointer=checkpointer, interrupt_before=["get_human_response"]
            )
    return _agent

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions