REDIS Durability ? how to auto expire data?

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

Answers


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


If you plan to use Redis just as a cache where every key will have an expire set, you may consider using the following configuration instead (assuming a max memory limit of 2 megabytes as an example):

maxmemory 2mb
maxmemory-policy allkeys-lru

In this configuration there is no need for the application to set a time to live for keys using the EXPIRE command (or equivalent) since all the keys will be evicted using an approximated LRU algorithm as long as we hit the 2 megabyte memory limit.

Basically in this configuration Redis acts in a similar way to memcached. We have more extensive documentation about using Redis as an LRU cache.


By default redis don't expire keys, it sets expire time to -1, "s2" time is unilimited unless you set it.

Normally Redis keys are created without an associated time to live. The key will simply live forever, unless it is removed by the user in an explicit way, for instance using the DEL command. The EXPIRE family of commands is able to associate an expire to a given key, at the cost of some additional memory used by the key. When a key has an expire set, Redis will make sure to remove the key when the specified amount of time elapsed.

http://redis.io/commands/expire (again)


For my case with REDIS Azure, I was looking to just assure that I didn't have to keep scaling my service for useless data. I found that the maxmemory LRU/FIFO seems to serve this purpose:

http://redis.io/topics/lru-cache

In REDIS Azure, one can set the Maxmemory Policy to any of the permitted LRU schemes in the management portal.


Need Your Help

TextView drawable posts (Android)

android textview drawable shape messages

I need to know how to create a drawable comic style for a TextView. I do not need a simple border radius, but a form like this:

EC2 instance image on VirtualBOX?

amazon-ec2 amazon-web-services vmware virtual-machine virtualbox

Is there any way of getting the saved EC2 instance image and running it on virtualbox on my personal computer?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.