Python memcache flush_all行为

时间:2016-11-21 20:23:35

标签: python python-2.7 memcached

我想知道是否有人可以帮助解释为什么呼叫flush_all()似乎没有更新统计数据。如果我创建了一个客户端,请添加1个密钥,获取该密钥,然后flush_all()我希望后续get_stats()返回0 curr_items,但它不会#39;吨。在get() flush_all()curr_items设置回0之后执行import memcache # Create a client mc = memcache.Client(['127.0.0.1:11211'], debug=0) # Add a key mc.add('foo', 'bar') print mc.get('foo') # Get stats stats = mc.get_stats() # There will be 1 current item print "Initial get_stat(): {}".format(stats[0][1]['curr_items']) # Flush all mc.flush_all() # Get stats again stats2 = mc.get_stats() # There shouldn't be any items, but there is 1 print "Second get_stat(): {}".format(stats2[0][1]['curr_items']) # Get the one key we added before mc.get('foo') # Get stats a third time stats3 = mc.get_stats() # There shouldn't be any items and now there aren't print "Third get_stat(): {}".format(stats3[0][1]['curr_items']) 密钥之前。

这是我见证的一个例子:

bar
Initial get_stat(): 1
Second get_stat(): 1
Third get_stat(): 0

执行结果:

fib

1 个答案:

答案 0 :(得分:1)

flush操作实际上并没有从内存中删除任何内容,只是将所有内容标记为已过期。在您尝试访问过期商品之前,过期商品并未实际删除。