0

I am doing a maintenance on several Python applications, which use connections to Redis services. Due to an infrastructure need, I am reducing the number of variables we will have in the environment settings as much as possible for all applicaitons. Today, the application uses several parameters, for example:

REDIS_PRIMARY_HOST= "localhost"
REDIS_PRIMARY_PORT= "6379"
REDIS_PRIMARY_PASSWORD= "password"
REDIS_PRIMARY_TTL_SECONDS = "1"
REDIS_DATABASE = "0"

We want to make a change and only use a connection string and another variable, such as:

REDIS_PRIMARY_CONNECTION_STRING = "redis://:password@localhost:6379?db=<database_number>&decode_responses=True&health_check_interval=2"
REDIS_DATABASE_NUMBER = "0"

However, via Connection String, I couldn't find in the documentation a way to set the TTL (Time To Live) as default to a value. Either I do this directly in the code, or I will have to extract the key parameter and define it at run time. Is there any way to set the Redis Time To Live by default, in the connection string?

1
  • This question is similar to: Can I set global TTL in redis?. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. Commented Oct 4, 2024 at 18:06

1 Answer 1

1

Redis doesn't support a global TTL. You will need to set it individually for each key.

Sign up to request clarification or add additional context in comments.

1 Comment

I see. Well, I've already developed the code to do what I need to do (extract and remove the value from the connection string), but I was hoping there was a way to do without this manipulation in the string. Thanks for your reply.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.