Skip to content

How to add TTL for RedisStore #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
YolandaAlvarez opened this issue Apr 23, 2025 · 0 comments
Closed

How to add TTL for RedisStore #27

YolandaAlvarez opened this issue Apr 23, 2025 · 0 comments

Comments

@YolandaAlvarez
Copy link

Hello, I have a project and I am using the same configuration for Cross-thread memory shown in https://redis.io/blog/langgraph-redis-build-smarter-ai-agents-with-memory-persistence/ .
The part where they initialize the checkpointer and store is this:

#Initialize Redis persistence and store
REDIS_URI = "redis://localhost:6379"
with RedisSaver.from_conn_string(REDIS_URI) as checkpointer:
    checkpointer.setup()
     
    with RedisStore.from_conn_string(REDIS_URI) as store:
        store.setup()
         
        # Compile graph with both checkpointer and store
        graph = builder.compile(checkpointer=checkpointer, store=store)

I want to know how to implement TTL in RedisStore.

In langgraph-redis/langgraph/store/redis/init.py in the definition of from_conn_string I can see the parameter ttl: Optional[dict[str, Any]] = None) .
I suppose I need to use that, do you have an example?
How can I set the TTL to 24hrs for the graph checkpoints I'm storing in RedisStore?

bsbodden added a commit that referenced this issue Apr 30, 2025
  Implements Time-To-Live (TTL) functionality for Redis-based checkpoint storage in LangGraph. This allows
  automatic expiration of checkpoint data after a configurable time period, helping to manage Redis memory usage.

  Key features:
  - Add TTL configuration option to RedisSaver and AsyncRedisSaver constructors
  - Implement TTL refresh-on-read functionality to extend expiration when checkpoints are accessed
  - Apply TTL consistently to all related keys (checkpoints, blobs, writes)
  - Add comprehensive test suite for TTL functionality
  - Update type hints to use explicit format (Dict, List, Tuple) for better clarity
bsbodden added a commit that referenced this issue May 1, 2025
  Implements Time-To-Live (TTL) functionality for Redis-based checkpoint storage in LangGraph. This allows
  automatic expiration of checkpoint data after a configurable time period, helping to manage Redis memory usage.

  Key features:
  - Add TTL configuration option to RedisSaver and AsyncRedisSaver constructors
  - Implement TTL refresh-on-read functionality to extend expiration when checkpoints are accessed
  - Apply TTL consistently to all related keys (checkpoints, blobs, writes)
  - Add comprehensive test suite for TTL functionality
  - Update type hints to use explicit format (Dict, List, Tuple) for better clarity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants