i guess for expiration the information is somewhere anyway, would it be possible to add a command to check when a key was last set ?

Comment From: georgepsarakis

I am guessing you can achieve this with the TTL/PTTL commands.

Comment From: vutral

well if so i would like an explaination how you think i can achieve that using ttl/pttl

MirOS Project Armored Secure Operating System http://www.mirbsd.org/

2013/8/26 George Psarakis notifications@github.com

I am guessing you can achieve this with the TTLhttp://redis.io/commands/ttl /PTTL http://redis.io/commands/pttl commands.

— Reply to this email directly or view it on GitHubhttps://github.com/antirez/redis/issues/1258#issuecomment-23244566 .

Comment From: georgepsarakis

I should have specified in my comment that this can be done if you are setting expiration times on your keys. With EXPIRE or SETEX:

SET a_key "hello"
EXPIRE a_key 300

Some time later if you wish to see when this key was set

TTL a_key

This will return the time-to-live (KEY_TTL). Since you know the expiration interval and the time-to-live you can easily find out when this key was set you need to get the current timestamp in your code (let's call it CURRENT_TIMESTAMP):

CURRENT_TIMESTAMP - ( 300 - KEY_TTL )

If you do not set an expiration time, I am not really sure that this information (the time that the key was set) is even stored, because SET and EXPIRE are 2 different commands. All keys are permanent by default.

Comment From: vutral

well thats not exactly what i was looking for ^^ as my intention is to check freshness without expiring the data it only partly solves my problem

MirOS Project Armored Secure Operating System http://www.mirbsd.org/

2013/8/27 George Psarakis notifications@github.com

I should have specified in my comment that this can be done if you are setting expiration times on your keys. With EXPIREhttp://redis.io/commands/expireor SETEX http://redis.io/commands/setex:

SET a_key "hello" EXPIRE a_key 300

Some time later if you wish to see when this key was set

TTL a_key

This will return the time-to-live (KEY_TTL). Since you know the expiration interval and the time-to-live you can easily find out when this key was set you need to get the current timestamp in your code (let's call it CURRENT_TIMESTAMP):

CURRENT_TIMESTAMP - ( 300 - KEY_TTL )

If you do not set an expiration time, I am not really sure that this information (the time that the key was set) is even stored, because SET and EXPIRE are 2 different commands. All keys are permanent by default.

— Reply to this email directly or view it on GitHubhttps://github.com/antirez/redis/issues/1258#issuecomment-23313957 .

Comment From: georgepsarakis

As a workaround, you can give an expiration with a timestamp and set it at a distant point in the future. Thus you will be able to implement this solution with TTL. Not sure if it helps you though.

Comment From: SummerHill

when i Dispose redis client that make me don't visits other method ? what should i do?

Comment From: bitthegeek

@SummerHill maybe you should post that question on a new thread

Comment From: fahadjabbar8

I was having the same issue and unfortunately using IDistributed cache c# library . Now i am using date against a separate key in the cached data itself and working okay for me.

Comment From: StarWindMoonCloud

I have the same question, @vutral have you found the solution?

Comment From: PratikStar

I don't understand. If Redis does not store the information on the key's creation time. How does the eviction algorithm work? like LRU

Comment From: vvaradarajan

@PratikStar: Redis has an OBJECT IDLETIME which can be used for LRU. Recall LRU is least recently 'used' and not to be confused with 'oldest'