text: 
  
  <!DOCTYPE html>
  <!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
  <!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
  <head>
    <meta charset="utf-8">
    
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    
    <title>INCRBYFLOAT key increment &mdash; Redis 命令参考</title>
    
  
    
    
    
    
  
    
    <script type="text/javascript" src="../_static/js/modernizr.min.js"></script>
    
      
        <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
          <script type="text/javascript" src="../_static/jquery.js"></script>
          <script type="text/javascript" src="../_static/underscore.js"></script>
          <script type="text/javascript" src="../_static/doctools.js"></script>
          <script type="text/javascript" src="../_static/language_data.js"></script>
      
      <script type="text/javascript" src="../_static/js/theme.js"></script>
  
      
  
    
    <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
      <link rel="index" title="Index" href="../genindex.html" />
      <link rel="search" title="Search" href="../search.html" />
      <link rel="next" title="DECR key" href="decr.html" />
      <link rel="prev" title="INCRBY key increment" href="incrby.html" /> 
  </head>
  
  <body class="wy-body-for-nav">
  
     
    <div class="wy-grid-for-nav">
  
      
      <nav data-toggle="wy-nav-shift" class="wy-nav-side">
        <div class="wy-side-scroll">
          <div class="wy-side-nav-search">
            
  
            
              <a href="../index.html" class="icon icon-home"> Redis 命令参考
            
  
            
            </a>
  
            
              
              
                <div class="version">
                  2019
                </div>
              
            
  
            
  <div role="search">
    <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
      <input type="text" name="q" placeholder="Search docs" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
  </div>
  
            
          </div>
  
          <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
            
              
              
                
              
              
                <ul class="current">
  <li class="toctree-l1 current"><a class="reference internal" href="index.html">字符串</a><ul class="current">
  <li class="toctree-l2"><a class="reference internal" href="set.html">SET</a></li>
  <li class="toctree-l2"><a class="reference internal" href="setnx.html">SETNX</a></li>
  <li class="toctree-l2"><a class="reference internal" href="setex.html">SETEX</a></li>
  <li class="toctree-l2"><a class="reference internal" href="psetex.html">PSETEX</a></li>
  <li class="toctree-l2"><a class="reference internal" href="get.html">GET</a></li>
  <li class="toctree-l2"><a class="reference internal" href="getset.html">GETSET</a></li>
  <li class="toctree-l2"><a class="reference internal" href="strlen.html">STRLEN</a></li>
  <li class="toctree-l2"><a class="reference internal" href="append.html">APPEND</a></li>
  <li class="toctree-l2"><a class="reference internal" href="setrange.html">SETRANGE</a></li>
  <li class="toctree-l2"><a class="reference internal" href="getrange.html">GETRANGE</a></li>
  <li class="toctree-l2"><a class="reference internal" href="incr.html">INCR</a></li>
  <li class="toctree-l2"><a class="reference internal" href="incrby.html">INCRBY</a></li>
  <li class="toctree-l2 current"><a class="current reference internal" href="#">INCRBYFLOAT</a><ul>
  <li class="toctree-l3"><a class="reference internal" href="#id1">返回值</a></li>
  <li class="toctree-l3"><a class="reference internal" href="#id2">代码示例</a></li>
  </ul>
  </li>
  <li class="toctree-l2"><a class="reference internal" href="decr.html">DECR</a></li>
  <li class="toctree-l2"><a class="reference internal" href="decrby.html">DECRBY</a></li>
  <li class="toctree-l2"><a class="reference internal" href="mset.html">MSET</a></li>
  <li class="toctree-l2"><a class="reference internal" href="msetnx.html">MSETNX</a></li>
  <li class="toctree-l2"><a class="reference internal" href="mget.html">MGET</a></li>
  </ul>
  </li>
  <li class="toctree-l1"><a class="reference internal" href="../hash/index.html">哈希表</a></li>
  <li class="toctree-l1"><a class="reference internal" href="../list/index.html">列表</a></li>
  <li class="toctree-l1"><a class="reference internal" href="../set/index.html">集合</a></li>
  <li class="toctree-l1"><a class="reference internal" href="../sorted_set/index.html">有序集合</a></li>
  <li class="toctree-l1"><a class="reference internal" href="../hyperloglog/index.html">HyperLogLog</a></li>
  <li class="toctree-l1"><a class="reference internal" href="../geo/index.html">地理位置</a></li>
  <li class="toctree-l1"><a class="reference internal" href="../bitmap/index.html">位图</a></li>
  <li class="toctree-l1"><a class="reference internal" href="../database/index.html">数据库</a></li>
  <li class="toctree-l1"><a class="reference internal" href="../expire/index.html">自动过期</a></li>
  <li class="toctree-l1"><a class="reference internal" href="../transaction/index.html">事务</a></li>
  <li class="toctree-l1"><a class="reference internal" href="../script/index.html">Lua 脚本</a></li>
  <li class="toctree-l1"><a class="reference internal" href="../persistence/index.html">持久化</a></li>
  <li class="toctree-l1"><a class="reference internal" href="../pubsub/index.html">发布与订阅</a></li>
  <li class="toctree-l1"><a class="reference internal" href="../replication/index.html">复制</a></li>
  <li class="toctree-l1"><a class="reference internal" href="../client_and_server/index.html">客户端与服务器</a></li>
  <li class="toctree-l1"><a class="reference internal" href="../configure/index.html">配置选项</a></li>
  <li class="toctree-l1"><a class="reference internal" href="../debug/index.html">调试</a></li>
  <li class="toctree-l1"><a class="reference internal" href="../internal/index.html">内部命令</a></li>
  <li class="toctree-l1"><a class="reference internal" href="../topic/index.html">功能文档</a></li>
  </ul>
  
              
            
          </div>
        </div>
      </nav>
  
      <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
  
        
        <nav class="wy-nav-top" aria-label="top navigation">
          
            <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
            <a href="../index.html">Redis 命令参考</a>
          
        </nav>
  
  
        <div class="wy-nav-content">
          
          <div class="rst-content">
          
            
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  <div role="navigation" aria-label="breadcrumbs navigation">
  
    <ul class="wy-breadcrumbs">
      
        <li><a href="../index.html">Docs</a> &raquo;</li>
          
            <li><a href="index.html">字符串</a> &raquo;</li>
          
        <li>INCRBYFLOAT key increment</li>
      
      
        <li class="wy-breadcrumbs-aside">
          
              
              <a href="../_sources/string/incrbyfloat.rst.txt" rel="nofollow"> View page source</a>
            
          
        </li>
      
    </ul>
  
    
    <hr/>
  </div>
            <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
             <div itemprop="articleBody">
              
    <div class="section" id="incrbyfloat-key-increment">
  <span id="incrbyfloat"></span><h1>INCRBYFLOAT key increment<a class="headerlink" href="#incrbyfloat-key-increment" title="Permalink to this headline">¶</a></h1>
  <blockquote>
  <div><div class="line-block">
  <div class="line">可用版本： &gt;= 2.6.0</div>
  <div class="line">时间复杂度： O(1)</div>
  </div>
  </div></blockquote>
  <p>为键 <code class="docutils literal notranslate"><span class="pre">key</span></code> 储存的值加上浮点数增量 <code class="docutils literal notranslate"><span class="pre">increment</span></code> 。</p>
  <p>如果键 <code class="docutils literal notranslate"><span class="pre">key</span></code> 不存在，
  那么 <code class="docutils literal notranslate"><span class="pre">INCRBYFLOAT</span></code> 会先将键 <code class="docutils literal notranslate"><span class="pre">key</span></code> 的值设为 <code class="docutils literal notranslate"><span class="pre">0</span></code> ，
  然后再执行加法操作。</p>
  <p>如果命令执行成功，
  那么键 <code class="docutils literal notranslate"><span class="pre">key</span></code> 的值会被更新为执行加法计算之后的新值，
  并且新值会以字符串的形式返回给调用者。</p>
  <p>无论是键 <code class="docutils literal notranslate"><span class="pre">key</span></code> 的值还是增量 <code class="docutils literal notranslate"><span class="pre">increment</span></code> ，
  都可以使用像 <code class="docutils literal notranslate"><span class="pre">2.0e7</span></code> 、 <code class="docutils literal notranslate"><span class="pre">3e5</span></code> 、 <code class="docutils literal notranslate"><span class="pre">90e-2</span></code> 那样的指数符号(exponential notation)来表示，
  但是，
  <strong>执行 INCRBYFLOAT 命令之后的值</strong>总是以同样的形式储存，
  也即是，
  它们总是由一个数字，
  一个（可选的）小数点和一个任意长度的小数部分组成（比如 <code class="docutils literal notranslate"><span class="pre">3.14</span></code> 、 <code class="docutils literal notranslate"><span class="pre">69.768</span></code> ，诸如此类)，
  小数部分尾随的 <code class="docutils literal notranslate"><span class="pre">0</span></code> 会被移除，
  如果可能的话，
  命令还会将浮点数转换为整数（比如 <code class="docutils literal notranslate"><span class="pre">3.0</span></code> 会被保存成 <code class="docutils literal notranslate"><span class="pre">3</span></code> ）。</p>
  <p>此外，
  无论加法计算所得的浮点数的实际精度有多长，
  <code class="docutils literal notranslate"><span class="pre">INCRBYFLOAT</span></code> 命令的计算结果最多只保留小数点的后十七位。</p>
  <p>当以下任意一个条件发生时，
  命令返回一个错误：</p>
  <ul class="simple">
  <li><p>键 <code class="docutils literal notranslate"><span class="pre">key</span></code> 的值不是字符串类型(因为 Redis 中的数字和浮点数都以字符串的形式保存，所以它们都属于字符串类型）；</p></li>
  <li><p>键 <code class="docutils literal notranslate"><span class="pre">key</span></code> 当前的值或者给定的增量 <code class="docutils literal notranslate"><span class="pre">increment</span></code> 不能被解释(parse)为双精度浮点数。</p></li>
  </ul>
  <div class="section" id="id1">
  <h2>返回值<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h2>
  <p>在加上增量 <code class="docutils literal notranslate"><span class="pre">increment</span></code> 之后，
  键 <code class="docutils literal notranslate"><span class="pre">key</span></code> 的值。</p>
  </div>
  <div class="section" id="id2">
  <h2>代码示例<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h2>
  <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">redis</span><span class="o">&gt;</span> <span class="n">GET</span> <span class="n">decimal</span>
  <span class="s2">&quot;3.0&quot;</span>
  
  <span class="n">redis</span><span class="o">&gt;</span> <span class="n">INCRBYFLOAT</span> <span class="n">decimal</span> <span class="mf">2.56</span>
  <span class="s2">&quot;5.56&quot;</span>
  
  <span class="n">redis</span><span class="o">&gt;</span> <span class="n">GET</span> <span class="n">decimal</span>
  <span class="s2">&quot;5.56&quot;</span>
  </pre></div>
  </div>
  </div>
  </div>
  
  
              <div class="section" id="discuss">
  
      <h2>
          讨论
          <a class="headerlink" href="#discuss" title="永久链接至标题">¶</a>
      </h2>
  
      <div id="disqus_thread"></div>
      <script type="text/javascript">
          /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
          var disqus_shortname = 'redis-command-cn'; // required: replace example with your forum shortname
  
          /* * * DON'T EDIT BELOW THIS LINE * * */
          (function() {
          var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
          dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
          (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
          })();
      </script>
      <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
      <a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
  </div>
  
  <!--
  <div id="sponser">
      <h2>赞助商</h2>
      <p>我们正在寻找赞助商，有意对这个网站进行赞助的朋友请联系 huangz1990@gmail.com 。</p>
  </div>
  -->
             </div>
             
            </div>
            <footer>
    
      <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
        
          <a href="decr.html" class="btn btn-neutral float-right" title="DECR key" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
        
        
          <a href="incrby.html" class="btn btn-neutral float-left" title="INCRBY key increment" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
        
      </div>
    
  
    <hr/>
  
    <div role="contentinfo">
      <p>
          &copy; Copyright 2019, Redis
  
      </p>
    </div>
    Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 
  
  </footer>
  
          </div>
        </div>
  
      </section>
  
    </div>
    
  
  
    <script type="text/javascript">
        jQuery(function () {
            SphinxRtdTheme.Navigation.enable(true);
        });
    </script>
  
    
    
      
     
  
      <script>
      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
      })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  
      ga('create', 'UA-53959484-7', 'auto');
      ga('send', 'pageview');
    </script>
  </body>
  </html>