Redis - TTL update on every access Vs requery after expiry

50 views
Skip to first unread message

Birender Rawat

unread,
Feb 14, 2018, 4:05:32 AM2/14/18
to Redis DB

I am storing detail of a user for one day. Which one of below is better approach assuming this user is viewed 2k times in day .

  1. TTL set one time

    Set TTL of 24hours. On every access to the user we will fetch data from Redis and won't update TTL. after 24 hours, when the key was expired update the TTL.

  2. TTL set on every request.

    Set TTL of 4hours. On every access to the user we will fetch data from Redis and update TTL to +4 hours from now. unused keys will automatically expire.

Question: I feel the first approach is better as on 2nd approach we don't need to update TTL 10k times(views) and need to fire query only one time. Please suggest which is better approach?

Salvatore Sanfilippo

unread,
Feb 14, 2018, 4:46:03 AM2/14/18
to redi...@googlegroups.com
This is in alternative to using maxmemory and an eviction policy of Redis? In that case, what you are doing is basically rewriting an eviction algorithm specific for your application use case, so 1 or 2 are to be preferred in accordance to the following questions:

1) Once a user is created, is it likely to be accessed only in a time <= 24 h?
2) When an user is accessed, it is likely that it will be accessed again in the next 4h?

Depending on what of the above is the most true in your specific application, will drive what policy to adopt.
If you are using a latest 4.0.x release, an alternative is to use the LFU policy and let Redis decide, so you just "SET", this will work likely in a better way assuming that the model of access is not so rigid and simple to anticipate. Moreover note that the above models you have (both 1 and 2) are unbound in memory as the number of users that are accessed concurrently raises.

Cheers,
Salvatore





--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+unsubscribe@googlegroups.com.
To post to this group, send email to redi...@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.



--
Salvatore 'antirez' Sanfilippo
open source developer - Redis Labs https://redislabs.com

"If a system is to have conceptual integrity, someone must control the concepts."
       — Fred Brooks, "The Mythical Man-Month", 1975.

Birender Rawat

unread,
Feb 14, 2018, 11:38:31 PM2/14/18
to Redis DB
Lets say i have 1000 user.
out of 1000 95% user will be accessed next day. also we will get increment of 5% new user.
Then above will repeat.

which means a user can be accessed for months or even for few hours (random).

My question was is it a good strategy to change ttl on evey request ?


On Wednesday, February 14, 2018 at 3:16:03 PM UTC+5:30, Salvatore Sanfilippo wrote:
This is in alternative to using maxmemory and an eviction policy of Redis? In that case, what you are doing is basically rewriting an eviction algorithm specific for your application use case, so 1 or 2 are to be preferred in accordance to the following questions:

1) Once a user is created, is it likely to be accessed only in a time <= 24 h?
2) When an user is accessed, it is likely that it will be accessed again in the next 4h?

Depending on what of the above is the most true in your specific application, will drive what policy to adopt.
If you are using a latest 4.0.x release, an alternative is to use the LFU policy and let Redis decide, so you just "SET", this will work likely in a better way assuming that the model of access is not so rigid and simple to anticipate. Moreover note that the above models you have (both 1 and 2) are unbound in memory as the number of users that are accessed concurrently raises.

Cheers,
Salvatore




On Wed, Feb 14, 2018 at 10:02 AM, Birender Rawat <birende...@gmail.com> wrote:

I am storing detail of a user for one day. Which one of below is better approach assuming this user is viewed 2k times in day .

  1. TTL set one time

    Set TTL of 24hours. On every access to the user we will fetch data from Redis and won't update TTL. after 24 hours, when the key was expired update the TTL.

  2. TTL set on every request.

    Set TTL of 4hours. On every access to the user we will fetch data from Redis and update TTL to +4 hours from now. unused keys will automatically expire.

Question: I feel the first approach is better as on 2nd approach we don't need to update TTL 10k times(views) and need to fire query only one time. Please suggest which is better approach?

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.

To post to this group, send email to redi...@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages