from praisonai.train.agents.storage import TrainingStoragefrom praisonaiagents.storage import RedisBackendwith TrainingStorage( session_id="train-123", backend=RedisBackend(url="redis://localhost:6379", prefix="train:", ttl=86400),) as storage: storage.save_iteration(...)# Redis connection closed automatically at the end of the with block
TrainingStorage is a context manager. Using with (or calling .close() explicitly)
releases the underlying Redis connection at the end of the block — best practice for
long-running processes. On backends without an open resource (e.g. FileBackend)
.close() is a safe no-op.
# Training with Redis backendpraisonai train agents --input "Hello" --storage-backend redis://localhost:6379# Session list with Redis backendpraisonai session list --storage-backend redis://localhost:6379
RedisStateStore.scan_prefix(prefix) iterates the keyspace with a non-blocking SCAN cursor (batches of 500) instead of the O(N) blocking KEYS command. Prefer it over keys(pattern) when listing many keys on a production Redis instance, so a single read never freezes other clients on the single-threaded server.
from praisonai.persistence import create_state_storestore = create_state_store("redis", url="redis://localhost:6379")recent = store.scan_prefix("session:")