鄙人蠢,读不懂redis源码~
有一天用redis-py连上Redis备用服务器,想看一下某类型的key有多少个。
rds = redis.Redis(ip, host)
print len(rds.keys('xxx_*'))
最后有大概400w个,阻塞了很久才算出来结果。
令我疑惑的是,这个客户端进程CPU占用率一直在100%以上(为什么会超过100%我也不知道),反倒内存占用率不高。
理论上keys的运算结果应该是服务端计算出来的,客户端接收数据顶多就是内存消耗多点儿,为什么实际情况中客户端CPU占用率如此之高,客户端自己做了什么奇怪的计算?
Traversing matches is definitely slow. The author has said that try not to use the keys command
The reason for the high CPU is mainly decoding the transmission format and converting it into a python object
Are you using top to watch? More than 100% is probably because of the multi-core CPU
It is best not to use key. You can use redis-rdb-tools, a small tool of redis. Someone seems to have mentioned how to use it here