013231
V2EX  ›  Redis

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

  •  
  •   013231 · May 7, 2014 · 5721 views
    This topic created in 4565 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
    superbear
    May 7, 2014
    1
    Z键赋值失败?
    qdvictory
    qdvictory
    May 7, 2014
    2
    >>> str(None)
    'None'
    >>> print None,str(None)
    None None
    >>>
    skydiver
    skydiver
    May 8, 2014 via Android
    3
    这也没错啊,你赋值成None读出来当然还是None
    ericls
    ericls
    May 8, 2014
    4
    有问题,
    以后就不能直接用

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

    来判断了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2278 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 12:16 · PVG 20:16 · LAX 04:16 · JFK 07:16
    ♥ Do have faith in what you're doing.