0

I am using StackExchange.Redis client to access Azure Redis Cache. I am creating a hashset as below:

Database.HashSet("HashSetKey", "EntryKey", "EntryValue");
Database.KeyExpire("HashSetKey", TimeSpan.MaxValue); 

Even though I am specifying expiry as TimeSpan.MaxValue the hashset is deleted after few minutes of not being used.

What am i missing ?

souser
  • 33
  • 1
  • 8

1 Answers1

1

There is no point is setting TimeSpan.MaxValue to a key expiration. You should not set it at all, because it should never be removed. And that's what the StackExchange redis client does - when you put TimeSpan.MaxValue it actually doesn't set an expiration at all, it calls the PERSIST command
In the StackExchange redis client look for the class RedisDatabase.cs and the method is

Message GetExpiryMessage(RedisKey key, CommandFlags flags, TimeSpan? expiry, out ServerEndPoint server)

https://github.com/StackExchange/StackExchange.Redis
You can also call the method Database.KeyTimeToLive and it will return 0 for your key.
And why it is being evicted might be because your Azure cache setup, it might be set with maxmemory and evictions policies: http://redis.io/topics/lru-cache

Liviu Costea
  • 3,624
  • 14
  • 17