013231
V2EX  ›  Redis

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

  •  
  •   013231 · May 7, 2014 · 5528 views
    This topic created in 4453 days ago, the information mentioned may be changed or developed.
    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 replies    2014-05-08 08:42:39 +08:00
    superbear
        1
    superbear  
       May 7, 2014
    Z键赋值失败?
    qdvictory
        2
    qdvictory  
       May 7, 2014
    >>> str(None)
    'None'
    >>> print None,str(None)
    None None
    >>>
    skydiver
        3
    skydiver  
       May 8, 2014 via Android
    这也没错啊,你赋值成None读出来当然还是None
    ericls
        4
    ericls  
       May 8, 2014
    有问题,
    以后就不能直接用

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

    来判断了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5731 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 85ms · UTC 06:32 · PVG 14:32 · LAX 23:32 · JFK 02:32
    ♥ Do have faith in what you're doing.