Call Us! 1-800-383-5193
Call Us! 1-800-383-5193

Need Help?

Our experts will login to your server within 30 minutes to fix urgent issues.

We will keep your servers stable, secure and fast at all times for one fixed price.

Redis get expire time – How we find it easily?

Are you trying to get the expire time in Redis? We’ll help you with it.

Usually, the timeout on Redis keys plays an important role in website navigation sessions. And, website owners often need tweaks in timeout values too.

That’s why at Bobcares, we often receive requests regarding key expiration as part of our Server Management Services.

Today, let’s discuss this topic in detail and see how our Support Engineers set Redis timeouts easily.


More about Redis key expiration

As we all know, Redis is a server that stores data. Also, it works as a data storage space that can store, retrieve and manage data.

But, it functions primarily as a key-value store. And, it is possible to set timeout values on these keys.

In Redis terminology, the key with an associated timeout is called volatile. But, a timeout expiration automatically deletes the key. Additionally, when we use commands that delete or overwrite the contents of the key, it will clear the timeout.


Need to know the expire time in Redis?

Usually, this key expiration is useful in the case of the Navigation session on a website.

Suppose, we want to view the latest N pages visited by our users. And, these set of page views is known as Navigation session of the user.

We can do this easily in Redis by using the EXPIRE command.

Suppose, we set the timeout of the key as 60. So, if the user becomes idle for more than 60 seconds, the key will get deleted. And, it will record the subsequent page views that have less than 60 seconds of difference.

Now, let’s discuss the ways to get the expire time of the key.


How can we get the expire time in Redis?

Recently, one of our customers approached us with a requirement. He had already set a timeout of 60 on his key.

And, he wanted to know the remaining time to live of that key. This helps to identify the time to fetch the content again. Our Support Engineers used the TTL command to know the remaining time in seconds.

So, Redis TTL helps the Redis client to check how many seconds are left for the key to expire.

TTL key_name

For instance, if we set the timeout on the key “key1” as 60, we can get the remaining time to live as follows.

redis get expire time

Similarly, the PTTL command returns the remaining time in milliseconds. Also, both TTL and PTTL shows a value of -1, if the key does not have an expiry timeout.

And, if the key does not exist, it will show -2.

Also, we can use the expireat command to expire the key at a specific point in time.

expireat key_name time

As we have already said, using commands that overwrite the contents of the key will clear out the timeout on that key.

So, we use the persist command to manually clear a key’s timeout.

persist key_name

And, after its successful completion, this command will return (integer)1.

redis get expire time


[Need more assistance with Redis timeout configuration? – We’re available 24/7 to help you.]



In short, we can get the expire time in Redis using the TTL command. In today’s article, we have discussed how our Support Engineers do it easily.


Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.



Submit a Comment

Your email address will not be published. Required fields are marked *

Privacy Preference Center


Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]


Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid


Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie


These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.