REDIS Durability ? how to auto expire data?

skidrow406 picture skidrow406 · Jun 30, 2014 · Viewed 18.1k times · Source

I use REDIS to store data (string) . ex: key "s1" store value "hello world". key "s2" store value "bye bye". I want s1 auto expire (free memory) after 5 minutes but s2 never expire. I use C#, .net 4.0 >> how to code ?. thanks

Answer

wow0609 picture wow0609 · Jun 30, 2014

Documentation regarding EXPIRE allows you to set an EXPIRE value per key, in seconds.

EXPIRE s1 300

will expire the key s1 in 5 minutes.

See the documentation here: REDIS EXPIRE

If you are looking for C# code, I think it would depend on what library you are using to access REDIS. There are some other SO questions that may help, but also discuss the problem where expire did not work: Redis Expire does not work