昨晚咱們工程的redis告警,cpu佔用率100%,運營人員把咱們剛上線的工程給停了,後來排查是由於咱們工程中使用了redis的keys命令,致使cpu佔用率100%,還致使了其餘系統連不上,多麼痛的領悟。java
根據官網對keys命令的解釋發現,It may ruin performance when it is executed against large databases. This command is intended for debugging and special operations, such as changing your keyspace layout. Don't use KEYS in your regular application code.redis
原文請見 http://redis.io/commands/keysjson
redis官網文檔都說若是數據量大了,用keys命令會帶來毀滅性災難。app
解決方法:ui
把要查詢的這些redis的keys,以map的形式做爲value組成一條記錄放到redis中。若是這個集合中的有記錄新增或者刪除,用spa
cRedisTemplate.opsForHash().put("nationalGrid:task", taskno + ":" + mac, json);
或者debug
cRedisTemplate.opsForHash().delete("nationalGrid:task", tasknomac);
來刷新新增記錄的value值。code
參考文章:http://www.tuicool.com/articles/JrmYVzAorm