Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify the expiry time of a Redis object in .NET Core?

I find there are "absexp","sldexp" and "data" fields in a Redis hash key.

I can use _radius.setString/getString to set and get the value of field data. But how can I modify the field "absexp" in the ASP.NET core project?

like image 471
Hongyang Du Avatar asked Feb 24 '17 03:02

Hongyang Du


1 Answers

Are you trying to change the cache expiration?

Use code like this to create an DistributedCacheEntryOptions object and assign when you set the value to cache so:

var options = new DistributedCacheEntryOptions(); // create options object
options.SetSlidingExpiration(TimeSpan.FromMinutes(1)); // 1 minute sliding expiration
_cache.SetString(cacheKey, value, options); // set key value pair with options
// your value will now expire after one minute

Absolute expiration can be set with a similar method on the option object if you don't want sliding expiration.

Hope this helps.

like image 152
BYUDigger Avatar answered Sep 21 '22 18:09

BYUDigger