Redis中keys()方法作用原理是什么?
大家讲道理
大家讲道理 2017-04-21 11:15:47
0
3
769

鄙人蠢,读不懂redis源码~
有一天用redis-py连上Redis备用服务器,想看一下某类型的key有多少个。

rds = redis.Redis(ip, host)
print len(rds.keys('xxx_*'))

最后有大概400w个,阻塞了很久才算出来结果。
令我疑惑的是,这个客户端进程CPU占用率一直在100%以上(为什么会超过100%我也不知道),反倒内存占用率不高。

理论上keys的运算结果应该是服务端计算出来的,客户端接收数据顶多就是内存消耗多点儿,为什么实际情况中客户端CPU占用率如此之高,客户端自己做了什么奇怪的计算?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(3)
PHPzhong

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!