redis keys命令之领悟

昨晚咱们工程的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

相关文章
相关标签/搜索