2 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01//EN">
5 <link type=
"text/css" rel=
"stylesheet" href=
"style.css" />
12 <img style=
"border:none" alt=
"Redis Documentation" src=
"redis.png">
16 <div id=
"pagecontent">
18 <!-- This is a (PRE) block. Make sure it's left aligned or your toc title will be off. -->
19 <b>GetsetCommand: Contents
</b><br> <a href=
"#GETSET _key_ _value_">GETSET _key_ _value_
</a><br> <a href=
"#Return value">Return value
</a><br> <a href=
"#Design patterns">Design patterns
</a>
22 <h1 class=
"wikiname">GetsetCommand
</h1>
29 #sidebar
<a href=
"StringCommandsSidebar.html">StringCommandsSidebar
</a><h1><a name=
"GETSET _key_ _value_">GETSET _key_ _value_
</a></h1>
30 <i>Time complexity: O(
1)
</i><blockquote>GETSET is an atomic
<i>set this value and return the old value
</i> command.Set
<i>key
</i> to the string
<i>value
</i> and return the old value stored at
<i>key
</i>.The string can't be longer than
1073741824 bytes (
1 GB).
</blockquote>
31 <h2><a name=
"Return value">Return value
</a></h2><a href=
"ReplyTypes.html">Bulk reply
</a><h2><a name=
"Design patterns">Design patterns
</a></h2><blockquote>GETSET can be used together with INCR for counting with atomic reset whena given condition arises. For example a process may call INCR against thekey
<i>mycounter
</i> every time some event occurred, but from time totime we need to get the value of the counter and reset it to zero atomicallyusing
<code name=
"code" class=
"python">GETSET mycounter
0</code>.
</blockquote>