Home  >  Q&A  >  body text

为什么redis中incr一个“0” 会报错?

问下 弄过redis的人 为什么incr命令会报错。。“0”可以转换为 0 呀。

redis 版本是windows 3.2.100 稳定版

过去多啦不再A梦过去多啦不再A梦2754 days ago901

reply all(3)I'll reply

  • 为情所困

    为情所困2017-04-27 09:04:55

    It’s normal here too

    127.0.0.1:6379> set test "0"
    OK
    127.0.0.1:6379> INCR test
    (integer) 1
    127.0.0.1:6379> INCR test
    (integer) 2
    127.0.0.1:6379> INCR test
    (integer) 3
    127.0.0.1:6379> get test
    "3"
    127.0.0.1:6379> type test
    string
    

    The version is redis-3.2.4

    reply
    0
  • ringa_lee

    ringa_lee2017-04-27 09:04:55

    incr

    # 情况3:key不是数字值
    
    redis> SET book "long long ago..."
    OK
    
    redis> INCRBY book 200
    (error) ERR value is not an integer or out of range

    I don’t know what your version is. My version is redis_version:2.4.10. The test is fine. Online test link

    reply
    0
  • ringa_lee

    ringa_lee2017-04-27 09:04:55

    ServiceStack.Redis client indeed omits "" for string type values. If you add an extra "", it will be self-defeating! Also, thank you
    @苏生Buhuo @mylxsw

    reply
    0
  • Cancelreply