我想知道是否有人可以帮助解释为什么呼叫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
答案 0 :(得分:1)
flush
操作实际上并没有从内存中删除任何内容,只是将所有内容标记为已过期。在您尝试访问过期商品之前,过期商品并未实际删除。