-
Notifications
You must be signed in to change notification settings - Fork 12
Reduce Redis EXPIRE calls using CustomRedisSessionStoreCustom redis session store #1221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
fedeazzato
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm struggling to see how the tradeoff between the increase in TTL invocations results in performance gains due to the reduction of EXIPRE invocations, but I trust your findings.
| var ttl = await _db.KeyTimeToLiveAsync(redisKey); | ||
|
|
||
| if (ShouldRefreshKey(ttl)) | ||
| { | ||
| _ = _db.KeyExpireAsync(redisKey, _idleTimeout); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it really more performant to check for the TTL (invoking a Redis operation) before expiring the key? Isn't the Redis endpoint hit anyway?
Shouldn't the invocation to KeyExpireAsync be awaited?
| var ttl = _db.KeyTimeToLive(redisKey); | ||
|
|
||
| if (ShouldRefreshKey(ttl)) | ||
| { | ||
| _db.KeyExpire(redisKey, _idleTimeout); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. How checking for TTL before invoking expire results in performance gains, if both must reach a Redis?
Replaces the default RedisCache behavior (https://github.com/dotnet/aspnetcore/blob/main/src/Caching/StackExchangeRedis/src/RedisCache.cs) , which refreshes the session TTL on every access to the web session, with a custom implementation that renews it only when near expiry (below 20% of the idle timeout).
This reduces redundant EXPIRE calls and Redis roundtrips while maintaining consistent session expiration behavior.
Issue:206131