redis_openai_agents.AtomicOperations#

class AtomicOperations(client)[source]#

Lua script-based atomic operations for Redis.

Uses SCRIPT LOAD + EVALSHA pattern for efficient script execution. Scripts are loaded lazily on first use and cached by SHA.

Example

>>> from redis.asyncio import Redis
>>> client = Redis.from_url("redis://localhost:6379")
>>> ops = AtomicOperations(client)
>>> await ops.atomic_message_append(
...     session_key="session:abc",
...     message={"role": "user", "content": "Hello"},
... )

Initialize AtomicOperations with a Redis client.

Parameters:

client (Redis) – Redis client (async)

__init__(client)[source]#

Initialize AtomicOperations with a Redis client.

Parameters:

client (Redis) – Redis client (async)

Return type:

None

Methods

__init__(client)

Initialize AtomicOperations with a Redis client.

atomic_handoff(session_key, from_agent, ...)

Atomically perform an agent handoff with distributed locking.

atomic_message_append(session_key, message)

Atomically append a message to a session.

atomic_response_record(session_key, ...[, ...])

Atomically record a response with cache, session, and metrics update.

release_handoff_lock(session_key)

Release the handoff lock for a session.