]> git.saurik.com Git - redis.git/blame - doc/ExpireCommand.html
timestamp in log lines
[redis.git] / doc / ExpireCommand.html
CommitLineData
57172ffb 1
2<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
3<html>
4 <head>
5 <link type="text/css" rel="stylesheet" href="style.css" />
6 </head>
7 <body>
8 <div id="page">
9
10 <div id='header'>
11 <a href="index.html">
12 <img style="border:none" alt="Redis Documentation" src="redis.png">
13 </a>
14 </div>
15
16 <div id="pagecontent">
17 <div class="index">
18<!-- This is a (PRE) block. Make sure it's left aligned or your toc title will be off. -->
19<b>ExpireCommand: Contents</b><br>&nbsp;&nbsp;<a href="#Expire _key_ _seconds_">Expire _key_ _seconds_</a><br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#How the expire is removed from a key">How the expire is removed from a key</a><br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#Restrictions with write operations against volatile keys">Restrictions with write operations against volatile keys</a><br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#Setting the timeout again on already volatile keys">Setting the timeout again on already volatile keys</a><br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#Return value">Return value</a><br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#See also">See also</a>
20 </div>
21
22 <h1 class="wikiname">ExpireCommand</h1>
23
24 <div class="summary">
25
26 </div>
27
28 <div class="narrow">
29 <h1><a name="Expire _key_ _seconds_">Expire _key_ _seconds_</a></h1>
30<i>Time complexity: O(1)</i><blockquote>Set a timeout on the specified key. After the timeout the key will beautomatically delete by the server. A key with an associated timeout issaid to be <i>volatile</i> in Redis terminology.</blockquote>
31<blockquote>Voltile keys are stored on disk like the other keys, the timeout is persistenttoo like all the other aspects of the dataset. Saving a dataset containingthe dataset and stopping the server does not stop the flow of time as Redisregisters on disk when the key will no longer be available as Unix time, andnot the remaining seconds.</blockquote>
32<h2><a name="How the expire is removed from a key">How the expire is removed from a key</a></h2><blockquote>When the key is set to a new value using the SET command, the INCR commandor any other command that modify the value stored at key the timeout isremoved from the key and the key becomes non volatile.</blockquote>
33<h2><a name="Restrictions with write operations against volatile keys">Restrictions with write operations against volatile keys</a></h2><blockquote>Write operations like LPUSH, LSET and every other command that has theeffect of modifying the value stored at a volatile key have a special semantic:basically a volatile key is destroyed when it is target of a write operation.See for example the following usage pattern:</blockquote>
34<pre class="codeblock python" name="code">
35% ./redis-cli lpush mylist foobar /Users/antirez/hack/redis
36OK
37% ./redis-cli lpush mylist hello /Users/antirez/hack/redis
38OK
39% ./redis-cli expire mylist 10000 /Users/antirez/hack/redis
401
41% ./redis-cli lpush mylist newelement
42OK
43% ./redis-cli lrange mylist 0 -1 /Users/antirez/hack/redis
441. newelement
45</pre><blockquote>What happened here is that lpush against the key with a timeout set deletedthe key before to perform the operation. There is so a simple rule, writeoperations against volatile keys will destroy the key before to perform theoperation. Why Redis uses this behavior? In order to retain an importantproperty: a server that receives a given number of commands in the samesequence will end with the same dataset in memory. Without the delete-on-writesemantic what happens is that the state of the server depends on the timeof the commands to. This is not a desirable property in a distributed databasethat supports replication.</blockquote>
46<h2><a name="Setting the timeout again on already volatile keys">Setting the timeout again on already volatile keys</a></h2><blockquote>Trying to call EXPIRE against a key that already has an associated timeoutwill not change the timeout of the key, but will just return 0. If insteadthe key does not have a timeout associated the timeout will be set and EXPIREwill return 1.</blockquote>
47<h2><a name="Return value">Return value</a></h2><a href="ReplyTypes.html">Integer reply</a>, specifically:<br/><br/><pre class="codeblock python python" name="code">
481: the timeout was set.
490: the timeout was not set since the key already has an associated timeout, or the key does not exist.
50</pre><h2><a name="See also">See also</a></h2>
efc296a1 51<ul><li> <a href="TypeCommand.html">TYPE</a></li></ul>
57172ffb 52 </div>
53
54 </div>
55 </div>
56 </body>
57</html>
58