V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
013231
V2EX  ›  Redis

Redis python 驱动中一个不容易注意到的坑

  •  
  •   013231 · 2014-05-07 21:28:15 +08:00 · 4665 次点击
    这是一个创建于 3613 天前的主题,其中的信息可能已经有所发展或是发生改变。
    import redis
    r = redis.StrictRedis()
    r.set('x', None)
    r.hset('y', 'z', None)
    print r.get('x'), r.hget('y', 'z')
    # Output: None None

    你能看出这其中的坑吗?
    4 条回复    2014-05-08 08:42:39 +08:00
    superbear
        1
    superbear  
       2014-05-07 21:34:02 +08:00
    Z键赋值失败?
    qdvictory
        2
    qdvictory  
       2014-05-07 21:38:20 +08:00
    >>> str(None)
    'None'
    >>> print None,str(None)
    None None
    >>>
    skydiver
        3
    skydiver  
       2014-05-08 02:24:39 +08:00 via Android
    这也没错啊,你赋值成None读出来当然还是None
    ericls
        4
    ericls  
       2014-05-08 08:42:39 +08:00
    有问题,
    以后就不能直接用

    if r.get('x'):
    ...

    来判断了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2999 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 14:47 · PVG 22:47 · LAX 07:47 · JFK 10:47
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.