SetbitCommand.html 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
  2. <html>
  3. <head>
  4. <link type="text/css" rel="stylesheet" href="style.css" />
  5. </head>
  6. <body>
  7. <div id="page">
  8. <div id='header'>
  9. <a href="index.html">
  10. <img style="border:none" alt="Redis Documentation" src="redis.png">
  11. </a>
  12. </div>
  13. <div id="pagecontent">
  14. <div class="index">
  15. <!-- This is a (PRE) block. Make sure it's left aligned or your toc title will be off. -->
  16. <b>SetbitCommand: Contents</b><br>&nbsp;&nbsp;<a href="#SETBIT _key_ _offset_ _value_ (Redis &gt;">SETBIT _key_ _offset_ _value_ (Redis &gt;</a><br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#Return value">Return value</a>
  17. </div>
  18. <h1 class="wikiname">SetbitCommand</h1>
  19. <div class="summary">
  20. </div>
  21. <div class="narrow">
  22. <h1><a name="SETBIT _key_ _offset_ _value_ (Redis &gt;">SETBIT _key_ _offset_ _value_ (Redis &gt;</a></h1> 2.1.8) =
  23. <i>Time complexity: O(1)</i><blockquote>Sets or clears the bit at <i>offset</i> in the string value stored at <i>key</i>.</blockquote>
  24. The bit is either set or cleared depending on <i>value</i>, which can be either 0 or 1. When <i>key</i> does not exist, a new string value is created. The string is grown to make sure it can hold a bit at <i>offset</i>. The <i>offset</i> argument is required to be greater than or equal to 0, and is limited to 2<sup>32-1 (which limits bitmaps to 512MB).
  25. When the string at <i>key</i> is grown, added bits are set to 0.<br/><br/><b>Warning</b>: When setting the last possible bit (<i>offset</i> equal to 2</sup>32-1) and the string value stored at <i>key</i> does not yet hold a string value, or holds a small string value, Redis needs to allocate all intermediate memory which can block the server for some time.
  26. On a 2010 Macbook Pro, setting bit number 2<sup>32-1 (512MB allocation) takes ~300ms,
  27. setting bit number 2</sup>30-1 (128MB allocation) takes ~80ms,
  28. setting bit number 2<sup>28-1 (32MB allocation) takes ~30ms and
  29. setting bit number 2</sup>26-1 (8MB allocation) takes ~8ms.
  30. Note that once this first allocation is done, subsequent calls to SETBIT for the same <i>key</i> will not have the allocation overhead.<h2><a name="Return value">Return value</a></h2><a href="ReplyTypes.html">Integer reply</a>, specifically: the original bit value stored at <i>offset</i>.
  31. </div>
  32. </div>
  33. </div>
  34. </body>
  35. </html>