1
votes

I'm setting up new redis server in my personal project.

If I do not set any timeout value using EXPIRE command the ttl is -1

I just want to know does -1 means permenent or default expire timeout.

If setting a key value sets ttl -1 then what is the purpose of PERSIST command

2

2 Answers

2
votes

I just want to know does -1 means permenent or default expire timeout.

Yes, if no timeout is set, the default TTL is -1, and the key won't be expired. However, it might be evicted when you run out of memory, check the maxmemory-policy configuration in redis.conf.

If setting a key value sets ttl -1 then what is the purpose of PERSIST command

You CANNOT manually set a key's TTL as -1 with EXPIRE command. If you do that, i.e. expire key -1, Redis will delete the key.

As you mentioned in your answer, PERSIST is used to remove the expiration setting, and make the key persistent.

0
votes

Yes.After little bit of research I found, key will expire only after given with EXPIRE command Persist used to remove expire value if already given expire value for a key